129#include "utils/fmgrprotos.h"
132#define BloomEqualStrategyNumber 1
141#define BLOOM_MAX_PROCNUMS 1
142#define PROCNUM_HASH 11
148#define PROCNUM_BASE 11
168#define BLOOM_MIN_NDISTINCT_PER_RANGE 16
175#define BLOOM_DEFAULT_NDISTINCT_PER_RANGE -0.1
191#define BLOOM_MIN_FALSE_POSITIVE_RATE 0.0001
192#define BLOOM_MAX_FALSE_POSITIVE_RATE 0.25
193#define BLOOM_DEFAULT_FALSE_POSITIVE_RATE 0.01
195#define BloomGetNDistinctPerRange(opts) \
196 ((opts) && (((BloomOptions *) (opts))->nDistinctPerRange != 0) ? \
197 (((BloomOptions *) (opts))->nDistinctPerRange) : \
198 BLOOM_DEFAULT_NDISTINCT_PER_RANGE)
200#define BloomGetFalsePositiveRate(opts) \
201 ((opts) && (((BloomOptions *) (opts))->falsePositiveRate != 0.0) ? \
202 (((BloomOptions *) (opts))->falsePositiveRate) : \
203 BLOOM_DEFAULT_FALSE_POSITIVE_RATE)
210#define BloomMaxFilterSize \
211 MAXALIGN_DOWN(BLCKSZ - \
212 (MAXALIGN(SizeOfPageHeaderData + \
213 sizeof(ItemIdData)) + \
214 MAXALIGN(sizeof(BrinSpecialSpace)) + \
221#define BLOOM_SEED_1 0x71d924af
222#define BLOOM_SEED_2 0xba48b314
271 int *nbytesp,
int *nbitsp,
int *nhashesp)
278 nbits = ceil(-(ndistinct * log(false_positive_rate)) / pow(log(2.0), 2));
281 nbytes = ((nbits + 7) / 8);
288 k = log(2.0) * nbits / ndistinct;
289 k = (k - floor(k) >= 0.5) ? ceil(k) : floor(k);
319 Assert(false_positive_rate > 0 && false_positive_rate < 1);
323 &nbytes, &nbits, &nhashes);
343 elog(
ERROR,
"the bloom filter is too large (%d > %zu)", nbytes,
356 filter->
nbits = nbits;
388 if (!(filter->
data[
byte] & (0x01 <<
bit)))
390 filter->
data[byte] |= (0x01 <<
bit);
425 if (!(filter->
data[
byte] & (0x01 <<
bit)))
514 ndistinct = (-ndistinct) * maxtuples;
526 ndistinct =
Min(ndistinct, maxtuples);
528 return (
int) ndistinct;
549 bool updated =
false;
619 for (keyno = 0; keyno < nkeys; keyno++)
626 attno =
key->sk_attno;
629 switch (
key->sk_strategy)
645 elog(
ERROR,
"invalid strategy number %d",
key->sk_strategy);
682 Assert(filter_a && filter_b);
687 nbytes = (filter_a->
nbits) / 8;
690 for (
i = 0;
i < nbytes;
i++)
751 "number of distinct items expected in a BRIN page range",
753 -1.0, INT_MAX, offsetof(
BloomOptions, nDistinctPerRange));
756 "desired false-positive rate for the bloom filters",
781 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
782 errmsg(
"cannot accept a value of type %s",
"pg_brin_bloom_summary")));
823 (
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
824 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)
struct BloomFilter BloomFilter
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)
#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)
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)
#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)