131#include "utils/fmgrprotos.h"
134#define BloomEqualStrategyNumber 1
143#define BLOOM_MAX_PROCNUMS 1
144#define PROCNUM_HASH 11
150#define PROCNUM_BASE 11
170#define BLOOM_MIN_NDISTINCT_PER_RANGE 16
177#define BLOOM_DEFAULT_NDISTINCT_PER_RANGE -0.1
193#define BLOOM_MIN_FALSE_POSITIVE_RATE 0.0001
194#define BLOOM_MAX_FALSE_POSITIVE_RATE 0.25
195#define BLOOM_DEFAULT_FALSE_POSITIVE_RATE 0.01
197#define BloomGetNDistinctPerRange(opts) \
198 ((opts) && (((BloomOptions *) (opts))->nDistinctPerRange != 0) ? \
199 (((BloomOptions *) (opts))->nDistinctPerRange) : \
200 BLOOM_DEFAULT_NDISTINCT_PER_RANGE)
202#define BloomGetFalsePositiveRate(opts) \
203 ((opts) && (((BloomOptions *) (opts))->falsePositiveRate != 0.0) ? \
204 (((BloomOptions *) (opts))->falsePositiveRate) : \
205 BLOOM_DEFAULT_FALSE_POSITIVE_RATE)
212#define BloomMaxFilterSize \
213 MAXALIGN_DOWN(BLCKSZ - \
214 (MAXALIGN(SizeOfPageHeaderData + \
215 sizeof(ItemIdData)) + \
216 MAXALIGN(sizeof(BrinSpecialSpace)) + \
223#define BLOOM_SEED_1 0x71d924af
224#define BLOOM_SEED_2 0xba48b314
283 nbytes = ((nbits + 7) / 8);
290 k =
log(2.0) * nbits / ndistinct;
325 &nbytes, &nbits, &nhashes);
345 elog(
ERROR,
"the bloom filter is too large (%d > %zu)", nbytes,
358 filter->
nbits = nbits;
390 if (!(filter->
data[
byte] & (0x01 <<
bit)))
392 filter->
data[byte] |= (0x01 <<
bit);
427 if (!(filter->
data[
byte] & (0x01 <<
bit)))
529 return (
int) ndistinct;
568 column->bv_allnulls =
false;
620 for (keyno = 0; keyno < nkeys; keyno++)
627 attno = key->sk_attno;
628 value = key->sk_argument;
630 switch (key->sk_strategy)
646 elog(
ERROR,
"invalid strategy number %d", key->sk_strategy);
691 for (
i = 0;
i < nbytes;
i++)
740 errdetail_internal(
"The operator class is missing support function %d for column %d.",
755 "number of distinct items expected in a BRIN page range",
760 "desired false-positive rate for the bloom filters",
786 errmsg(
"cannot accept a value of type %s",
"pg_brin_bloom_summary")));
828 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)
static BloomFilter * bloom_init(int ndistinct, double false_positive_rate)
#define BloomGetNDistinctPerRange(opts)
Datum brin_bloom_options(PG_FUNCTION_ARGS)
#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)
#define BloomMaxFilterSize
#define BLOOM_MIN_NDISTINCT_PER_RANGE
#define BloomEqualStrategyNumber
#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)
static BloomFilter * bloom_add_value(BloomFilter *filter, uint32 value, bool *updated)
Datum brin_bloom_summary_recv(PG_FUNCTION_ARGS)
Datum brin_bloom_opcinfo(PG_FUNCTION_ARGS)
#define SizeofBrinOpcInfo(ncols)
Datum byteasend(PG_FUNCTION_ARGS)
#define RegProcedureIsValid(p)
#define PG_USED_FOR_ASSERTS_ONLY
#define Assert(condition)
#define FLEXIBLE_ARRAY_MEMBER
int errmsg_internal(const char *fmt,...)
int errdetail_internal(const char *fmt,...)
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_GET_OPCLASS_OPTIONS()
#define PG_DETOAST_DATUM(datum)
#define PG_GETARG_INT32(n)
#define PG_GETARG_BOOL(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)
void pfree(void *pointer)
void * palloc0(Size size)
static AmcheckOptions opts
static uint64 pg_popcount(const char *buf, int bytes)
static uint32 DatumGetUInt32(Datum X)
static Datum PointerGetDatum(const void *X)
static Pointer DatumGetPointer(Datum 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]
TypeCacheEntry * oi_typcache[FLEXIBLE_ARRAY_MEMBER]
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
static void SET_VARSIZE(void *PTR, Size len)
Datum bit(PG_FUNCTION_ARGS)