130 #include "utils/fmgrprotos.h"
133 #define BloomEqualStrategyNumber 1
142 #define BLOOM_MAX_PROCNUMS 1
143 #define PROCNUM_HASH 11
149 #define PROCNUM_BASE 11
169 #define BLOOM_MIN_NDISTINCT_PER_RANGE 16
176 #define BLOOM_DEFAULT_NDISTINCT_PER_RANGE -0.1
192 #define BLOOM_MIN_FALSE_POSITIVE_RATE 0.0001
193 #define BLOOM_MAX_FALSE_POSITIVE_RATE 0.25
194 #define BLOOM_DEFAULT_FALSE_POSITIVE_RATE 0.01
196 #define BloomGetNDistinctPerRange(opts) \
197 ((opts) && (((BloomOptions *) (opts))->nDistinctPerRange != 0) ? \
198 (((BloomOptions *) (opts))->nDistinctPerRange) : \
199 BLOOM_DEFAULT_NDISTINCT_PER_RANGE)
201 #define BloomGetFalsePositiveRate(opts) \
202 ((opts) && (((BloomOptions *) (opts))->falsePositiveRate != 0.0) ? \
203 (((BloomOptions *) (opts))->falsePositiveRate) : \
204 BLOOM_DEFAULT_FALSE_POSITIVE_RATE)
211 #define BloomMaxFilterSize \
212 MAXALIGN_DOWN(BLCKSZ - \
213 (MAXALIGN(SizeOfPageHeaderData + \
214 sizeof(ItemIdData)) + \
215 MAXALIGN(sizeof(BrinSpecialSpace)) + \
222 #define BLOOM_SEED_1 0x71d924af
223 #define BLOOM_SEED_2 0xba48b314
272 int *nbytesp,
int *nbitsp,
int *nhashesp)
279 nbits = ceil(-(ndistinct * log(false_positive_rate)) / pow(log(2.0), 2));
282 nbytes = ((nbits + 7) / 8);
289 k = log(2.0) * nbits / ndistinct;
290 k = (k - floor(k) >= 0.5) ? ceil(k) : floor(k);
320 Assert(false_positive_rate > 0 && false_positive_rate < 1);
324 &nbytes, &nbits, &nhashes);
344 elog(
ERROR,
"the bloom filter is too large (%d > %zu)", nbytes,
357 filter->
nbits = nbits;
389 if (!(filter->
data[
byte] & (0x01 <<
bit)))
391 filter->
data[byte] |= (0x01 <<
bit);
426 if (!(filter->
data[
byte] & (0x01 <<
bit)))
515 ndistinct = (-ndistinct) * maxtuples;
527 ndistinct =
Min(ndistinct, maxtuples);
529 return (
int) ndistinct;
550 bool updated =
false;
620 for (keyno = 0; keyno < nkeys; keyno++)
627 attno =
key->sk_attno;
630 switch (
key->sk_strategy)
646 elog(
ERROR,
"invalid strategy number %d",
key->sk_strategy);
683 Assert(filter_a && filter_b);
688 nbytes = (filter_a->
nbits) / 8;
691 for (
i = 0;
i < nbytes;
i++)
752 "number of distinct items expected in a BRIN page range",
754 -1.0, INT_MAX, offsetof(
BloomOptions, nDistinctPerRange));
757 "desired false-positive rate for the bloom filters",
782 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
783 errmsg(
"cannot accept a value of type %s",
"pg_brin_bloom_summary")));
824 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
825 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 Assert(condition)
#define FLEXIBLE_ARRAY_MEMBER
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_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)
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)
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)