136 #define BloomEqualStrategyNumber 1
145 #define BLOOM_MAX_PROCNUMS 1
146 #define PROCNUM_HASH 11
152 #define PROCNUM_BASE 11
172 #define BLOOM_MIN_NDISTINCT_PER_RANGE 16
179 #define BLOOM_DEFAULT_NDISTINCT_PER_RANGE -0.1
195 #define BLOOM_MIN_FALSE_POSITIVE_RATE 0.0001
196 #define BLOOM_MAX_FALSE_POSITIVE_RATE 0.25
197 #define BLOOM_DEFAULT_FALSE_POSITIVE_RATE 0.01
199 #define BloomGetNDistinctPerRange(opts) \
200 ((opts) && (((BloomOptions *) (opts))->nDistinctPerRange != 0) ? \
201 (((BloomOptions *) (opts))->nDistinctPerRange) : \
202 BLOOM_DEFAULT_NDISTINCT_PER_RANGE)
204 #define BloomGetFalsePositiveRate(opts) \
205 ((opts) && (((BloomOptions *) (opts))->falsePositiveRate != 0.0) ? \
206 (((BloomOptions *) (opts))->falsePositiveRate) : \
207 BLOOM_DEFAULT_FALSE_POSITIVE_RATE)
214 #define BloomMaxFilterSize \
215 MAXALIGN_DOWN(BLCKSZ - \
216 (MAXALIGN(SizeOfPageHeaderData + \
217 sizeof(ItemIdData)) + \
218 MAXALIGN(sizeof(BrinSpecialSpace)) + \
225 #define BLOOM_SEED_1 0x71d924af
226 #define BLOOM_SEED_2 0xba48b314
275 int *nbytesp,
int *nbitsp,
int *nhashesp)
282 nbits = ceil(-(ndistinct * log(false_positive_rate)) / pow(log(2.0), 2));
285 nbytes = ((nbits + 7) / 8);
292 k = log(2.0) * nbits / ndistinct;
293 k = (k - floor(k) >= 0.5) ? ceil(k) : floor(k);
328 &nbytes, &nbits, &nhashes);
348 elog(
ERROR,
"the bloom filter is too large (%d > %zu)", nbytes,
361 filter->
nbits = nbits;
393 if (!(filter->
data[
byte] & (0x01 <<
bit)))
395 filter->
data[byte] |= (0x01 <<
bit);
430 if (!(filter->
data[
byte] & (0x01 <<
bit)))
519 ndistinct = (-ndistinct) * maxtuples;
531 ndistinct =
Min(ndistinct, maxtuples);
533 return (
int) ndistinct;
554 bool updated =
false;
624 for (keyno = 0; keyno < nkeys; keyno++)
631 attno =
key->sk_attno;
634 switch (
key->sk_strategy)
650 elog(
ERROR,
"invalid strategy number %d",
key->sk_strategy);
687 Assert(filter_a && filter_b);
692 nbytes = (filter_a->
nbits) / 8;
695 for (
i = 0;
i < nbytes;
i++)
753 "number of distinct items expected in a BRIN page range",
755 -1.0, INT_MAX, offsetof(
BloomOptions, nDistinctPerRange));
758 "desired false-positive rate for the bloom filters",
783 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
784 errmsg(
"cannot accept a value of type %s",
"pg_brin_bloom_summary")));
825 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
826 errmsg(
"cannot accept a value of type %s",
"pg_brin_bloom_summary")));
static bool BlockNumberIsValid(BlockNumber blockNumber)
#define BrinGetPagesPerRange(relation)
static int brin_bloom_get_ndistinct(BrinDesc *bdesc, BloomOptions *opts)
#define BLOOM_DEFAULT_NDISTINCT_PER_RANGE
Datum brin_bloom_consistent(PG_FUNCTION_ARGS)
static void bloom_filter_size(int ndistinct, double false_positive_rate, int *nbytesp, int *nbitsp, int *nhashesp)
#define BloomGetNDistinctPerRange(opts)
struct BloomFilter BloomFilter
static BloomFilter * bloom_init(int ndistinct, double false_positive_rate)
Datum brin_bloom_options(PG_FUNCTION_ARGS)
struct BloomOptions BloomOptions
#define BLOOM_MAX_FALSE_POSITIVE_RATE
#define BLOOM_DEFAULT_FALSE_POSITIVE_RATE
static bool bloom_contains_value(BloomFilter *filter, uint32 value)
#define BLOOM_MAX_PROCNUMS
#define BloomGetFalsePositiveRate(opts)
static BloomFilter * bloom_add_value(BloomFilter *filter, uint32 value, bool *updated)
#define BloomMaxFilterSize
#define BLOOM_MIN_NDISTINCT_PER_RANGE
#define BloomEqualStrategyNumber
struct BloomOpaque BloomOpaque
#define BLOOM_MIN_FALSE_POSITIVE_RATE
Datum brin_bloom_union(PG_FUNCTION_ARGS)
Datum brin_bloom_summary_send(PG_FUNCTION_ARGS)
Datum brin_bloom_summary_out(PG_FUNCTION_ARGS)
static FmgrInfo * bloom_get_procinfo(BrinDesc *bdesc, uint16 attno, uint16 procnum)
Datum brin_bloom_add_value(PG_FUNCTION_ARGS)
Datum brin_bloom_summary_in(PG_FUNCTION_ARGS)
Datum brin_bloom_summary_recv(PG_FUNCTION_ARGS)
Datum brin_bloom_opcinfo(PG_FUNCTION_ARGS)
#define SizeofBrinOpcInfo(ncols)
#define RegProcedureIsValid(p)
#define PG_USED_FOR_ASSERTS_ONLY
#define FLEXIBLE_ARRAY_MEMBER
elog(ERROR, "%s: %s", p2, msg)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
Datum FunctionCall1Coll(FmgrInfo *flinfo, Oid collation, Datum arg1)
void fmgr_info_copy(FmgrInfo *dstinfo, FmgrInfo *srcinfo, MemoryContext destcxt)
#define PG_GETARG_POINTER(n)
#define PG_RETURN_CSTRING(x)
#define PG_GETARG_DATUM(n)
#define PG_DETOAST_DATUM_PACKED(datum)
#define PG_GET_OPCLASS_OPTIONS()
#define PG_DETOAST_DATUM(datum)
#define PG_GETARG_INT32(n)
#define PG_RETURN_POINTER(x)
#define PG_GET_COLLATION()
#define PG_RETURN_BOOL(x)
uint64 hash_bytes_uint32_extended(uint32 k, uint64 seed)
#define MaxHeapTuplesPerPage
FmgrInfo * index_getprocinfo(Relation irel, AttrNumber attnum, uint16 procnum)
RegProcedure index_getprocid(Relation irel, AttrNumber attnum, uint16 procnum)
if(TABLE==NULL||TABLE_index==NULL)
Assert(fmt[strlen(fmt) - 1] !='\n')
void * palloc0(Size size)
static AmcheckOptions opts
static uint32 DatumGetUInt32(Datum X)
static Datum PointerGetDatum(const void *X)
void init_local_reloptions(local_relopts *relopts, Size relopt_struct_size)
void add_local_real_reloption(local_relopts *relopts, const char *name, const char *desc, double default_val, double min_val, double max_val, int offset)
void appendStringInfo(StringInfo str, const char *fmt,...)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
char data[FLEXIBLE_ARRAY_MEMBER]
FmgrInfo extra_procinfos[BLOOM_MAX_PROCNUMS]
bool extra_proc_missing[BLOOM_MAX_PROCNUMS]
BrinOpcInfo * bd_info[FLEXIBLE_ARRAY_MEMBER]
TypeCacheEntry * oi_typcache[FLEXIBLE_ARRAY_MEMBER]
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
#define SET_VARSIZE(PTR, len)
Datum bit(PG_FUNCTION_ARGS)
Datum byteasend(PG_FUNCTION_ARGS)