Update nbits_set in brin_bloom_union
authorTomas Vondra <[email protected]>
Sun, 14 Apr 2024 15:58:59 +0000 (17:58 +0200)
committerTomas Vondra <[email protected]>
Sun, 14 Apr 2024 16:18:07 +0000 (18:18 +0200)
Properly update the number of bits set in the bitmap after merging the
filters in brin_bloom_union.

This is mostly harmless, as the counter is used only in the output
function, which means pageinspect may show incorrect information about
the BRIN summary. The counter does not affect correctness.

Discovered while adding a regression test comparing indexes built with
and without parallelism. The parallel index builds exercise the union
procedure when merging results from workers, which is otherwise very
hard to do in a test. Which is why this went unnoticed until now.

Backpatch through 14, where the BRIN bloom opclasses were introduced.

Backpatch-through: 14
Discussion: https://postgr.es/m/1df00a66-db5a-4e66-809a-99b386a06d86%40enterprisedb.com

src/backend/access/brin/brin_bloom.c

index 72aabbcf50d8839038844ac23a9720b0a0c2b3f1..cc274256b31c94b64a8e3e1582116d57fd5c646a 100644 (file)
@@ -661,6 +661,9 @@ brin_bloom_union(PG_FUNCTION_ARGS)
    for (i = 0; i < nbytes; i++)
        filter_a->data[i] |= filter_b->data[i];
 
+   /* update the number of bits set in the filter */
+   filter_a->nbits_set = pg_popcount((const char *) filter_a->data, nbytes);
+
    PG_RETURN_VOID();
 }