56 "all ones",
"1111111111",
60 "alternating bits",
"0101010101",
64 "clusters of ten",
"1111111111",
68 "clusters of hundred",
69 "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111",
77 "sparse",
"100000000000000000000000000000001",
81 "single values, distance > 2^32",
"1",
82 UINT64CONST(10000000000), 1000000
85 "clusters, distance > 2^32",
"10101010",
86 UINT64CONST(10000000000), 10000000
89 "clusters, distance > 2^60",
"10101010",
90 UINT64CONST(2000000000000000000),
145 uint64 *pattern_values;
146 uint64 pattern_num_values;
150 fprintf(stderr,
"-----\ntesting intset with pattern \"%s\"\n", spec->
test_name);
154 pattern_values =
palloc(patternlen *
sizeof(uint64));
155 pattern_num_values = 0;
156 for (
int i = 0;
i < patternlen;
i++)
159 pattern_values[pattern_num_values++] =
i;
185 while (n < spec->num_values)
189 for (
int i = 0;
i < pattern_num_values && n < spec->
num_values;
i++)
191 x = last_int + pattern_values[
i];
203 spec->
num_values, (
int) (endtime - starttime) / 1000);
224 mem_usage, (
double) mem_usage / spec->
num_values);
239 for (n = 0; n < 100000; n++)
261 if (
idx >= patternlen)
278 n, (
int) (endtime - starttime) / 1000);
288 while (n < spec->num_values)
290 for (
int i = 0;
i < pattern_num_values && n < spec->
num_values;
i++)
292 uint64 expected = last_int + pattern_values[
i];
307 n, (
int) (endtime - starttime) / 1000);
309 if (n < spec->num_values)
336 if (num_entries != 1)
344 elog(
ERROR,
"intset_is_member failed for 0");
346 elog(
ERROR,
"intset_is_member failed for 1");
348 elog(
ERROR,
"intset_is_member failed for PG_UINT64_MAX");
350 elog(
ERROR,
"intset_is_member failed for the tested value");
382 uint64 *iter_expected;
384 uint64 num_entries = 0;
388 value, filler_min, filler_max);
392 iter_expected =
palloc(
sizeof(uint64) * (filler_max - filler_min + 1));
393 if (
value < filler_min)
396 iter_expected[n++] =
value;
399 for (
x = filler_min;
x < filler_max;
x++)
402 iter_expected[n++] =
x;
405 if (
value >= filler_max)
408 iter_expected[n++] =
value;
413 if (num_entries != n)
421 value, filler_min, filler_max);
423 value, filler_min, filler_max);
425 value, filler_min, filler_max);
427 value, filler_min, filler_max);
429 value, filler_min, filler_max);
431 value, filler_min, filler_max);
433 value, filler_min, filler_max);
435 value, filler_min, filler_max);
437 value, filler_min, filler_max);
439 value, filler_min, filler_max);
441 value, filler_min, filler_max);
443 value, filler_min, filler_max);
445 value, filler_min, filler_max);
448 for (uint64
i = 0;
i < n;
i++)
451 if (!found ||
x != iter_expected[
i])
459 if (mem_usage < 5000 || mem_usage > 500000000)
471 uint64
value, uint64 filler_min, uint64 filler_max)
476 expected = (
x ==
value || (filler_min <=
x &&
x < filler_max));
480 if (actual != expected)
493 elog(
NOTICE,
"testing intset with empty set");
499 elog(
ERROR,
"intset_is_member on empty set returned true");
501 elog(
ERROR,
"intset_is_member on empty set returned true");
503 elog(
ERROR,
"intset_is_member on empty set returned true");
528 elog(
NOTICE,
"testing intset with distances > 2^60 between values");
534 val += UINT64CONST(1152921504606846976) - 1;
537 val += UINT64CONST(1152921504606846976) - 1;
540 val += UINT64CONST(1152921504606846976);
543 val += UINT64CONST(1152921504606846976);
546 val += UINT64CONST(1152921504606846976);
549 val += UINT64CONST(1152921504606846976) + 1;
552 val += UINT64CONST(1152921504606846976) + 1;
555 val += UINT64CONST(1152921504606846976) + 1;
558 val += UINT64CONST(1152921504606846976) + 2;
561 val += UINT64CONST(1152921504606846976) + 2;
564 val += UINT64CONST(1152921504606846976);
572 while (num_values < 1000)
580 for (
int i = 0;
i < num_values;
i++)
586 for (
int i = 0;
i < num_values;
i++)
594 expected = (
values[
i - 1] ==
y - 1);
596 if (result != expected)
604 expected = (
i != num_values - 1) ? (
values[
i + 1] ==
y + 1) :
false;
606 if (result != expected)
614 for (
int i = 0;
i < num_values;
i++)
Datum intset(PG_FUNCTION_ARGS)
Datum idx(PG_FUNCTION_ARGS)
TimestampTz GetCurrentTimestamp(void)
static Datum values[MAXATTR]
uint64 intset_memory_usage(IntegerSet *intset)
uint64 intset_num_entries(IntegerSet *intset)
bool intset_is_member(IntegerSet *intset, uint64 x)
IntegerSet * intset_create(void)
void intset_begin_iterate(IntegerSet *intset)
bool intset_iterate_next(IntegerSet *intset, uint64 *next)
void intset_add_member(IntegerSet *intset, uint64 x)
MemoryContext CurrentMemoryContext
void MemoryContextStats(MemoryContext context)
void MemoryContextDelete(MemoryContext context)
void MemoryContextSetIdentifier(MemoryContext context, const char *id)
#define AllocSetContextCreate
#define ALLOCSET_SMALL_SIZES
uint64 pg_prng_uint64_range(pg_prng_state *state, uint64 rmin, uint64 rmax)
uint32 pg_prng_uint32(pg_prng_state *state)
pg_prng_state pg_global_prng_state
RT_SCOPE RT_RADIX_TREE *MemoryContext old_ctx
MemoryContextSwitchTo(old_ctx)
static void test_pattern(const test_spec *spec)
static const bool intset_test_stats
Datum test_integerset(PG_FUNCTION_ARGS)
static void test_single_value(uint64 value)
PG_FUNCTION_INFO_V1(test_integerset)
static void test_empty(void)
static const test_spec test_specs[]
static void test_single_value_and_filler(uint64 value, uint64 filler_min, uint64 filler_max)
static void check_with_filler(IntegerSet *intset, uint64 x, uint64 value, uint64 filler_min, uint64 filler_max)
static void test_huge_distances(void)