pgsql: Fix incorrect nmembers calculation in test_bitmapset

From: David Rowley <drowley(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix incorrect nmembers calculation in test_bitmapset
Date: 2026-08-24 10:44:40
Message-ID: E1wySAR-00000001tL5-13Su@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix incorrect nmembers calculation in test_bitmapset

This calculation was failing to correctly account for the min_value when
calculating how many random members to add to the Bitmapset. What the
code was meant to do was add a random number of members between the
minimum and maximum values. The code failed to account for the minimum
value being non-zero, which could result in too many members being added
to the set, which could reduce the effectiveness of the test. In reality,
the only caller to this function did pass 0 as the min_value, so there is
no live bug being fixed here.

Fix this so that the Bitmapset is more sparsely populated with members
between the minimum and maximum values. In passing, swap the order of the
min_value and max_value parameters. Having the minimum value appear
before the maximum value makes more sense. Also align the names of both
parameters, and adjust the 'offset' calculation to widen the offset range
by 1 so that the possible range for that random value is -max_value to
max_value.

Author: David Rowley <dgrowleyml(at)gmail(dot)com>
Reviewed-by: Greg Burd <greg(at)burd(dot)me>
Discussion: https://postgr.es/m/CAApHDvpfZqdMRmR-6W9UXb+Tanex5wK6PsL=XzYCV4P3pD36Ng@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/53a981ed5bbaa8344da88dfa3550e6cfb6ecf3c9

Modified Files
--------------
.../test_bitmapset/expected/test_bitmapset.out | 2 +-
.../modules/test_bitmapset/sql/test_bitmapset.sql | 2 +-
src/test/modules/test_bitmapset/test_bitmapset.c | 53 ++++++++++++++--------
3 files changed, 37 insertions(+), 20 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2026-08-24 12:31:28 pgsql: Fix untranslatable message that was pasted together at run time
Previous Message Daniel Gustafsson 2026-08-24 08:11:18 pgsql: Use ArchiveHandle.lookaheadSize instead of a hardcoded 512