1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-31 05:54:36 +03:00

Align random test function parameters in test_bitmapset

53a981ed5 adjusted test_random_offset_operations() so that the minimum
value parameter came before the maximum value parameter.  Here we adjust
test_random_operations() so that it accepts absolute numbers for the
minimum and maximum values.  Previously the maximum value to put in the
random Bitmapset was the minimum value plus the range.  Also align the
parameter order with test_random_offset_operations() to make these
functions consistent with each other.

Backpatch to v19 as test_random_operations() is new there.

Author: David Rowley <dgrowleyml@gmail.com>
Reviewed-by: Greg Burd <greg@burd.me>
Discussion: https://postgr.es/m/66d041b4-32f4-4097-bb2c-0e7147337a5e@app.fastmail.com
Backpatch-through: 19
This commit is contained in:
David Rowley
2026-08-25 10:42:41 +12:00
parent 1e9b06a8e0
commit d5d86704f4
3 changed files with 24 additions and 18 deletions

View File

@@ -1643,7 +1643,7 @@ SELECT test_bms_nonempty_difference('(b 1 2)', '(b 50 100)') AS result;
(1 row)
-- random operations
SELECT test_random_operations(NULL, 10000, 81920, 0) > 0 AS result;
SELECT test_random_operations(NULL, 10000, 0, 81920) > 0 AS result;
result
--------
t

View File

@@ -421,7 +421,7 @@ SELECT test_bms_nonempty_difference('(b 100)', '(b 5)') AS result;
SELECT test_bms_nonempty_difference('(b 1 2)', '(b 50 100)') AS result;
-- random operations
SELECT test_random_operations(NULL, 10000, 81920, 0) > 0 AS result;
SELECT test_random_operations(NULL, 10000, 0, 81920) > 0 AS result;
-- perform some random tests on bms_offset_members()
SELECT test_random_offset_operations(NULL, 1000, 0, 1024) AS result;

View File

@@ -598,10 +598,11 @@ test_bitmap_match(PG_FUNCTION_ARGS)
* equivalent C functions, this stresses Bitmapsets in a random fashion for
* various operations.
*
* "min_value" is the minimal value used for the members, that will stand
* up to a range of "max_range". "num_ops" defines the number of time each
* operation is done. "seed" is a random seed used to calculate the member
* values. When "seed" is NULL, a random seed will be chosen automatically.
* Arguments:
* arg1: optional random seed. NULL autoselects the seed.
* arg2: defines the number of times each operation is done.
* arg3: the minimum bitmapset member number to use in the random set.
* arg4: the maximum bitmapset member number to use in the random set.
*
* The return value is the number of times all operations have been executed.
*/
@@ -615,9 +616,10 @@ test_random_operations(PG_FUNCTION_ARGS)
pg_prng_state state;
uint64 seed = GetCurrentTimestamp();
int num_ops;
int max_range;
int min_value;
int max_value;
int member;
uint32 range;
int *members;
int num_members = 0;
int total_ops = 0;
@@ -625,18 +627,22 @@ test_random_operations(PG_FUNCTION_ARGS)
if (!PG_ARGISNULL(0))
seed = PG_GETARG_INT64(0);
num_ops = PG_GETARG_INT32(1);
max_range = PG_GETARG_INT32(2);
min_value = PG_GETARG_INT32(3);
if (PG_ARGISNULL(1) || num_ops <= 0)
if (PG_ARGISNULL(1) || PG_GETARG_INT32(1) <= 0)
elog(ERROR, "invalid number of operations");
if (PG_ARGISNULL(2) || max_range <= 0)
elog(ERROR, "invalid maximum range");
if (PG_ARGISNULL(3) || min_value < 0)
if (PG_ARGISNULL(2) || PG_GETARG_INT32(2) < 0)
elog(ERROR, "invalid minimum value");
if (PG_ARGISNULL(3) || PG_GETARG_INT32(3) < 0)
elog(ERROR, "invalid maximum value");
num_ops = PG_GETARG_INT32(1);
min_value = PG_GETARG_INT32(2);
max_value = PG_GETARG_INT32(3);
if (max_value < min_value)
elog(ERROR, "maximum value must be greater than or equal to minimum value");
pg_prng_seed(&state, seed);
range = (uint32) max_value - (uint32) min_value + 1;
/*
* There can be up to "num_ops" members added. This is very unlikely,
@@ -650,7 +656,7 @@ test_random_operations(PG_FUNCTION_ARGS)
{
CHECK_FOR_INTERRUPTS();
member = pg_prng_uint32(&state) % max_range + min_value;
member = min_value + (pg_prng_uint32(&state) % range);
if (!bms_is_member(member, bms1))
members[num_members++] = member;
@@ -662,7 +668,7 @@ test_random_operations(PG_FUNCTION_ARGS)
{
CHECK_FOR_INTERRUPTS();
member = pg_prng_uint32(&state) % max_range + min_value;
member = min_value + (pg_prng_uint32(&state) % range);
if (!bms_is_member(member, bms2))
members[num_members++] = member;
@@ -737,7 +743,7 @@ test_random_operations(PG_FUNCTION_ARGS)
switch (pg_prng_uint32(&state) % 3)
{
case 0: /* add */
member = pg_prng_uint32(&state) % max_range + min_value;
member = min_value + (pg_prng_uint32(&state) % range);
if (!bms_is_member(member, bms))
members[num_members++] = member;
bms = bms_add_member(bms, member);