PostgreSQL Source Code git master
blutils.c File Reference
#include "postgres.h"
#include "access/amapi.h"
#include "access/generic_xlog.h"
#include "access/reloptions.h"
#include "bloom.h"
#include "commands/vacuum.h"
#include "storage/bufmgr.h"
#include "storage/indexfsm.h"
#include "utils/memutils.h"
#include "varatt.h"
Include dependency graph for blutils.c:

Go to the source code of this file.

Macros

#define GETWORD(x, i)   ( *( (BloomSignatureWord *)(x) + ( (i) / SIGNWORDBITS ) ) )
 
#define CLRBIT(x, i)   GETWORD(x,i) &= ~( 0x01 << ( (i) % SIGNWORDBITS ) )
 
#define SETBIT(x, i)   GETWORD(x,i) |= ( 0x01 << ( (i) % SIGNWORDBITS ) )
 
#define GETBIT(x, i)   ( (GETWORD(x,i) >> ( (i) % SIGNWORDBITS )) & 0x01 )
 

Functions

 PG_FUNCTION_INFO_V1 (blhandler)
 
static int32 myRand (void)
 
static void mySrand (uint32 seed)
 
void _PG_init (void)
 
static BloomOptionsmakeDefaultBloomOptions (void)
 
Datum blhandler (PG_FUNCTION_ARGS)
 
void initBloomState (BloomState *state, Relation index)
 
void signValue (BloomState *state, BloomSignatureWord *sign, Datum value, int attno)
 
BloomTupleBloomFormTuple (BloomState *state, ItemPointer iptr, Datum *values, bool *isnull)
 
bool BloomPageAddItem (BloomState *state, Page page, BloomTuple *tuple)
 
Buffer BloomNewBuffer (Relation index)
 
void BloomInitPage (Page page, uint16 flags)
 
void BloomFillMetapage (Relation index, Page metaPage)
 
void BloomInitMetapage (Relation index, ForkNumber forknum)
 
byteabloptions (Datum reloptions, bool validate)
 

Variables

static relopt_kind bl_relopt_kind
 
static relopt_parse_elt bl_relopt_tab [INDEX_MAX_KEYS+1]
 
static int32 next
 

Macro Definition Documentation

◆ CLRBIT

#define CLRBIT (   x,
  i 
)    GETWORD(x,i) &= ~( 0x01 << ( (i) % SIGNWORDBITS ) )

Definition at line 28 of file blutils.c.

◆ GETBIT

#define GETBIT (   x,
  i 
)    ( (GETWORD(x,i) >> ( (i) % SIGNWORDBITS )) & 0x01 )

Definition at line 30 of file blutils.c.

◆ GETWORD

#define GETWORD (   x,
  i 
)    ( *( (BloomSignatureWord *)(x) + ( (i) / SIGNWORDBITS ) ) )

Definition at line 27 of file blutils.c.

◆ SETBIT

#define SETBIT (   x,
  i 
)    GETWORD(x,i) |= ( 0x01 << ( (i) % SIGNWORDBITS ) )

Definition at line 29 of file blutils.c.

Function Documentation

◆ _PG_init()

void _PG_init ( void  )

Definition at line 49 of file blutils.c.

50{
51 int i;
52 char buf[16];
53
55
56 /* Option for length of signature */
58 "Length of signature in bits",
61 bl_relopt_tab[0].optname = "length";
63 bl_relopt_tab[0].offset = offsetof(BloomOptions, bloomLength);
64
65 /* Number of bits for each possible index column: col1, col2, ... */
66 for (i = 0; i < INDEX_MAX_KEYS; i++)
67 {
68 snprintf(buf, sizeof(buf), "col%d", i + 1);
70 "Number of bits generated for each index column",
74 buf);
76 bl_relopt_tab[i + 1].offset = offsetof(BloomOptions, bitSize[0]) + sizeof(int) * i;
77 }
78}
#define DEFAULT_BLOOM_BITS
Definition: bloom.h:97
#define DEFAULT_BLOOM_LENGTH
Definition: bloom.h:91
#define MAX_BLOOM_BITS
Definition: bloom.h:98
#define MAX_BLOOM_LENGTH
Definition: bloom.h:92
static relopt_kind bl_relopt_kind
Definition: blutils.c:35
static relopt_parse_elt bl_relopt_tab[INDEX_MAX_KEYS+1]
Definition: blutils.c:38
int i
Definition: isn.c:77
#define AccessExclusiveLock
Definition: lockdefs.h:43
char * MemoryContextStrdup(MemoryContext context, const char *string)
Definition: mcxt.c:1768
MemoryContext TopMemoryContext
Definition: mcxt.c:166
#define INDEX_MAX_KEYS
static char buf[DEFAULT_XLOG_SEG_SIZE]
Definition: pg_test_fsync.c:71
#define snprintf
Definition: port.h:260
void add_int_reloption(bits32 kinds, const char *name, const char *desc, int default_val, int min_val, int max_val, LOCKMODE lockmode)
Definition: reloptions.c:921
relopt_kind add_reloption_kind(void)
Definition: reloptions.c:703
@ RELOPT_TYPE_INT
Definition: reloptions.h:32
const char * optname
Definition: reloptions.h:152
relopt_type opttype
Definition: reloptions.h:153

References AccessExclusiveLock, add_int_reloption(), add_reloption_kind(), bl_relopt_kind, bl_relopt_tab, buf, DEFAULT_BLOOM_BITS, DEFAULT_BLOOM_LENGTH, i, INDEX_MAX_KEYS, MAX_BLOOM_BITS, MAX_BLOOM_LENGTH, MemoryContextStrdup(), relopt_parse_elt::offset, relopt_parse_elt::optname, relopt_parse_elt::opttype, RELOPT_TYPE_INT, snprintf, and TopMemoryContext.

◆ blhandler()

Datum blhandler ( PG_FUNCTION_ARGS  )

Definition at line 103 of file blutils.c.

104{
105 static const IndexAmRoutine amroutine = {
106 .type = T_IndexAmRoutine,
107 .amstrategies = BLOOM_NSTRATEGIES,
108 .amsupport = BLOOM_NPROC,
109 .amoptsprocnum = BLOOM_OPTIONS_PROC,
110 .amcanorder = false,
111 .amcanorderbyop = false,
112 .amcanhash = false,
113 .amconsistentequality = false,
114 .amconsistentordering = false,
115 .amcanbackward = false,
116 .amcanunique = false,
117 .amcanmulticol = true,
118 .amoptionalkey = true,
119 .amsearcharray = false,
120 .amsearchnulls = false,
121 .amstorage = false,
122 .amclusterable = false,
123 .ampredlocks = false,
124 .amcanparallel = false,
125 .amcanbuildparallel = false,
126 .amcaninclude = false,
127 .amusemaintenanceworkmem = false,
128 .amparallelvacuumoptions =
130 .amkeytype = InvalidOid,
131
132 .ambuild = blbuild,
133 .ambuildempty = blbuildempty,
134 .aminsert = blinsert,
135 .aminsertcleanup = NULL,
136 .ambulkdelete = blbulkdelete,
137 .amvacuumcleanup = blvacuumcleanup,
138 .amcanreturn = NULL,
139 .amcostestimate = blcostestimate,
140 .amgettreeheight = NULL,
141 .amoptions = bloptions,
142 .amproperty = NULL,
143 .ambuildphasename = NULL,
144 .amvalidate = blvalidate,
145 .amadjustmembers = NULL,
146 .ambeginscan = blbeginscan,
147 .amrescan = blrescan,
148 .amgettuple = NULL,
149 .amgetbitmap = blgetbitmap,
150 .amendscan = blendscan,
151 .ammarkpos = NULL,
152 .amrestrpos = NULL,
153 .amestimateparallelscan = NULL,
154 .aminitparallelscan = NULL,
155 .amparallelrescan = NULL,
156 .amtranslatestrategy = NULL,
157 .amtranslatecmptype = NULL,
158 };
159
160 PG_RETURN_POINTER(&amroutine);
161}
void blcostestimate(PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
Definition: blcost.c:22
void blbuildempty(Relation index)
Definition: blinsert.c:165
IndexBuildResult * blbuild(Relation heap, Relation index, IndexInfo *indexInfo)
Definition: blinsert.c:122
bool blinsert(Relation index, Datum *values, bool *isnull, ItemPointer ht_ctid, Relation heapRel, IndexUniqueCheck checkUnique, bool indexUnchanged, IndexInfo *indexInfo)
Definition: blinsert.c:175
bool blvalidate(Oid opclassoid)
Definition: blvalidate.c:30
int64 blgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
Definition: blscan.c:75
IndexScanDesc blbeginscan(Relation r, int nkeys, int norderbys)
Definition: blscan.c:25
IndexBulkDeleteResult * blbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
Definition: blvacuum.c:30
#define BLOOM_NPROC
Definition: bloom.h:26
#define BLOOM_NSTRATEGIES
Definition: bloom.h:30
IndexBulkDeleteResult * blvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
Definition: blvacuum.c:164
#define BLOOM_OPTIONS_PROC
Definition: bloom.h:25
void blendscan(IndexScanDesc scan)
Definition: blscan.c:62
void blrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys, ScanKey orderbys, int norderbys)
Definition: blscan.c:45
bytea * bloptions(Datum reloptions, bool validate)
Definition: blutils.c:481
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:363
#define InvalidOid
Definition: postgres_ext.h:37
NodeTag type
Definition: amapi.h:234
#define VACUUM_OPTION_PARALLEL_CLEANUP
Definition: vacuum.h:63
#define VACUUM_OPTION_PARALLEL_BULKDEL
Definition: vacuum.h:48

References blbeginscan(), blbuild(), blbuildempty(), blbulkdelete(), blcostestimate(), blendscan(), blgetbitmap(), blinsert(), BLOOM_NPROC, BLOOM_NSTRATEGIES, BLOOM_OPTIONS_PROC, bloptions(), blrescan(), blvacuumcleanup(), blvalidate(), InvalidOid, PG_RETURN_POINTER, IndexAmRoutine::type, VACUUM_OPTION_PARALLEL_BULKDEL, and VACUUM_OPTION_PARALLEL_CLEANUP.

◆ BloomFillMetapage()

void BloomFillMetapage ( Relation  index,
Page  metaPage 
)

Definition at line 420 of file blutils.c.

421{
423 BloomMetaPageData *metadata;
424
425 /*
426 * Choose the index's options. If reloptions have been assigned, use
427 * those, otherwise create default options.
428 */
429 opts = (BloomOptions *) index->rd_options;
430 if (!opts)
432
433 /*
434 * Initialize contents of meta page, including a copy of the options,
435 * which are now frozen for the life of the index.
436 */
437 BloomInitPage(metaPage, BLOOM_META);
438 metadata = BloomPageGetMeta(metaPage);
439 memset(metadata, 0, sizeof(BloomMetaPageData));
441 metadata->opts = *opts;
442 ((PageHeader) metaPage)->pd_lower += sizeof(BloomMetaPageData);
443
444 /* If this fails, probably FreeBlockNumberArray size calc is wrong: */
445 Assert(((PageHeader) metaPage)->pd_lower <= ((PageHeader) metaPage)->pd_upper);
446}
#define BloomPageGetMeta(page)
Definition: bloom.h:133
struct BloomMetaPageData BloomMetaPageData
#define BLOOM_MAGICK_NUMBER
Definition: bloom.h:128
#define BLOOM_META
Definition: bloom.h:46
void BloomInitPage(Page page, uint16 flags)
Definition: blutils.c:405
static BloomOptions * makeDefaultBloomOptions(void)
Definition: blutils.c:84
PageHeaderData * PageHeader
Definition: bufpage.h:173
Assert(PointerIsAligned(start, uint64))
if(TABLE==NULL||TABLE_index==NULL)
Definition: isn.c:81
static AmcheckOptions opts
Definition: pg_amcheck.c:112
BloomOptions opts
Definition: bloom.h:123
uint32 magickNumber
Definition: bloom.h:120
Definition: type.h:96

References Assert(), BLOOM_MAGICK_NUMBER, BLOOM_META, BloomInitPage(), BloomPageGetMeta, if(), BloomMetaPageData::magickNumber, makeDefaultBloomOptions(), BloomMetaPageData::opts, and opts.

Referenced by BloomInitMetapage().

◆ BloomFormTuple()

BloomTuple * BloomFormTuple ( BloomState state,
ItemPointer  iptr,
Datum values,
bool *  isnull 
)

Definition at line 299 of file blutils.c.

300{
301 int i;
302 BloomTuple *res = (BloomTuple *) palloc0(state->sizeOfBloomTuple);
303
304 res->heapPtr = *iptr;
305
306 /* Blooming each column */
307 for (i = 0; i < state->nColumns; i++)
308 {
309 /* skip nulls */
310 if (isnull[i])
311 continue;
312
313 signValue(state, res->sign, values[i], i);
314 }
315
316 return res;
317}
void signValue(BloomState *state, BloomSignatureWord *sign, Datum value, int attno)
Definition: blutils.c:266
static Datum values[MAXATTR]
Definition: bootstrap.c:155
void * palloc0(Size size)
Definition: mcxt.c:1417
BloomSignatureWord sign[FLEXIBLE_ARRAY_MEMBER]
Definition: bloom.h:160
ItemPointerData heapPtr
Definition: bloom.h:159
Definition: regguts.h:323

References BloomTuple::heapPtr, i, palloc0(), BloomTuple::sign, signValue(), and values.

Referenced by blinsert(), and bloomBuildCallback().

◆ BloomInitMetapage()

void BloomInitMetapage ( Relation  index,
ForkNumber  forknum 
)

Definition at line 452 of file blutils.c.

453{
454 Buffer metaBuffer;
455 Page metaPage;
457
458 /*
459 * Make a new page; since it is first page it should be associated with
460 * block number 0 (BLOOM_METAPAGE_BLKNO). No need to hold the extension
461 * lock because there cannot be concurrent inserters yet.
462 */
463 metaBuffer = ReadBufferExtended(index, forknum, P_NEW, RBM_NORMAL, NULL);
466
467 /* Initialize contents of meta page */
469 metaPage = GenericXLogRegisterBuffer(state, metaBuffer,
471 BloomFillMetapage(index, metaPage);
473
474 UnlockReleaseBuffer(metaBuffer);
475}
#define BLOOM_METAPAGE_BLKNO
Definition: bloom.h:78
void BloomFillMetapage(Relation index, Page metaPage)
Definition: blutils.c:420
int Buffer
Definition: buf.h:23
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition: bufmgr.c:4318
void LockBuffer(Buffer buffer, BufferLockMode mode)
Definition: bufmgr.c:5699
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:5478
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Definition: bufmgr.c:886
#define P_NEW
Definition: bufmgr.h:198
@ BUFFER_LOCK_EXCLUSIVE
Definition: bufmgr.h:207
@ RBM_NORMAL
Definition: bufmgr.h:46
PageData * Page
Definition: bufpage.h:81
Page GenericXLogRegisterBuffer(GenericXLogState *state, Buffer buffer, int flags)
Definition: generic_xlog.c:299
GenericXLogState * GenericXLogStart(Relation relation)
Definition: generic_xlog.c:269
XLogRecPtr GenericXLogFinish(GenericXLogState *state)
Definition: generic_xlog.c:337
#define GENERIC_XLOG_FULL_IMAGE
Definition: generic_xlog.h:26

References Assert(), BLOOM_METAPAGE_BLKNO, BloomFillMetapage(), BUFFER_LOCK_EXCLUSIVE, BufferGetBlockNumber(), GENERIC_XLOG_FULL_IMAGE, GenericXLogFinish(), GenericXLogRegisterBuffer(), GenericXLogStart(), LockBuffer(), P_NEW, RBM_NORMAL, ReadBufferExtended(), and UnlockReleaseBuffer().

Referenced by blbuild(), and blbuildempty().

◆ BloomInitPage()

void BloomInitPage ( Page  page,
uint16  flags 
)

Definition at line 405 of file blutils.c.

406{
407 BloomPageOpaque opaque;
408
409 PageInit(page, BLCKSZ, sizeof(BloomPageOpaqueData));
410
411 opaque = BloomPageGetOpaque(page);
412 opaque->flags = flags;
414}
#define BloomPageGetOpaque(page)
Definition: bloom.h:60
#define BLOOM_PAGE_ID
Definition: bloom.h:57
void PageInit(Page page, Size pageSize, Size specialSize)
Definition: bufpage.c:42
uint16 flags
Definition: bloom.h:36
uint16 bloom_page_id
Definition: bloom.h:40

References BloomPageOpaqueData::bloom_page_id, BLOOM_PAGE_ID, BloomPageGetOpaque, BloomPageOpaqueData::flags, and PageInit().

Referenced by blinsert(), BloomFillMetapage(), and initCachedPage().

◆ BloomNewBuffer()

Buffer BloomNewBuffer ( Relation  index)

Definition at line 359 of file blutils.c.

360{
361 Buffer buffer;
362
363 /* First, try to get a page from FSM */
364 for (;;)
365 {
367
368 if (blkno == InvalidBlockNumber)
369 break;
370
371 buffer = ReadBuffer(index, blkno);
372
373 /*
374 * We have to guard against the possibility that someone else already
375 * recycled this page; the buffer may be locked if so.
376 */
377 if (ConditionalLockBuffer(buffer))
378 {
379 Page page = BufferGetPage(buffer);
380
381 if (PageIsNew(page))
382 return buffer; /* OK to use, if never initialized */
383
384 if (BloomPageIsDeleted(page))
385 return buffer; /* OK to use */
386
388 }
389
390 /* Can't use it, so release buffer and try again */
391 ReleaseBuffer(buffer);
392 }
393
394 /* Must extend the file */
397
398 return buffer;
399}
uint32 BlockNumber
Definition: block.h:31
#define InvalidBlockNumber
Definition: block.h:33
#define BloomPageIsDeleted(page)
Definition: bloom.h:64
Buffer ExtendBufferedRel(BufferManagerRelation bmr, ForkNumber forkNum, BufferAccessStrategy strategy, uint32 flags)
Definition: bufmgr.c:939
bool ConditionalLockBuffer(Buffer buffer)
Definition: bufmgr.c:5725
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:5461
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition: bufmgr.c:839
static Page BufferGetPage(Buffer buffer)
Definition: bufmgr.h:436
@ BUFFER_LOCK_UNLOCK
Definition: bufmgr.h:205
@ EB_LOCK_FIRST
Definition: bufmgr.h:87
#define BMR_REL(p_rel)
Definition: bufmgr.h:114
static bool PageIsNew(const PageData *page)
Definition: bufpage.h:233
BlockNumber GetFreeIndexPage(Relation rel)
Definition: indexfsm.c:38
@ MAIN_FORKNUM
Definition: relpath.h:58

References BloomPageIsDeleted, BMR_REL, BUFFER_LOCK_UNLOCK, BufferGetPage(), ConditionalLockBuffer(), EB_LOCK_FIRST, ExtendBufferedRel(), GetFreeIndexPage(), InvalidBlockNumber, LockBuffer(), MAIN_FORKNUM, PageIsNew(), ReadBuffer(), and ReleaseBuffer().

Referenced by blinsert(), and flushCachedPage().

◆ BloomPageAddItem()

bool BloomPageAddItem ( BloomState state,
Page  page,
BloomTuple tuple 
)

Definition at line 324 of file blutils.c.

325{
326 BloomTuple *itup;
327 BloomPageOpaque opaque;
328 char *ptr;
329
330 /* We shouldn't be pointed to an invalid page */
331 Assert(!PageIsNew(page) && !BloomPageIsDeleted(page));
332
333 /* Does new tuple fit on the page? */
334 if (BloomPageGetFreeSpace(state, page) < state->sizeOfBloomTuple)
335 return false;
336
337 /* Copy new tuple to the end of page */
338 opaque = BloomPageGetOpaque(page);
339 itup = BloomPageGetTuple(state, page, opaque->maxoff + 1);
340 memcpy(itup, tuple, state->sizeOfBloomTuple);
341
342 /* Adjust maxoff and pd_lower */
343 opaque->maxoff++;
344 ptr = (char *) BloomPageGetTuple(state, page, opaque->maxoff + 1);
345 ((PageHeader) page)->pd_lower = ptr - page;
346
347 /* Assert we didn't overrun available space */
348 Assert(((PageHeader) page)->pd_lower <= ((PageHeader) page)->pd_upper);
349
350 return true;
351}
#define BloomPageGetFreeSpace(state, page)
Definition: bloom.h:149
#define BloomPageGetTuple(state, page, offset)
Definition: bloom.h:71
OffsetNumber maxoff
Definition: bloom.h:35

References Assert(), BloomPageGetFreeSpace, BloomPageGetOpaque, BloomPageGetTuple, BloomPageIsDeleted, BloomPageOpaqueData::maxoff, and PageIsNew().

Referenced by blinsert(), and bloomBuildCallback().

◆ bloptions()

bytea * bloptions ( Datum  reloptions,
bool  validate 
)

Definition at line 481 of file blutils.c.

482{
483 BloomOptions *rdopts;
484
485 /* Parse the user-given reloptions */
486 rdopts = (BloomOptions *) build_reloptions(reloptions, validate,
488 sizeof(BloomOptions),
491
492 /* Convert signature length from # of bits to # to words, rounding up */
493 if (rdopts)
494 rdopts->bloomLength = (rdopts->bloomLength + SIGNWORDBITS - 1) / SIGNWORDBITS;
495
496 return (bytea *) rdopts;
497}
static bool validate(Port *port, const char *auth)
Definition: auth-oauth.c:638
#define SIGNWORDBITS
Definition: bloom.h:86
#define lengthof(array)
Definition: c.h:809
void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
Definition: reloptions.c:1954
int bloomLength
Definition: bloom.h:104
Definition: c.h:712

References bl_relopt_kind, bl_relopt_tab, BloomOptions::bloomLength, build_reloptions(), lengthof, SIGNWORDBITS, and validate().

Referenced by blhandler().

◆ initBloomState()

void initBloomState ( BloomState state,
Relation  index 
)

Definition at line 167 of file blutils.c.

168{
169 int i;
170
171 state->nColumns = index->rd_att->natts;
172
173 /* Initialize hash function for each attribute */
174 for (i = 0; i < index->rd_att->natts; i++)
175 {
176 fmgr_info_copy(&(state->hashFn[i]),
179 state->collations[i] = index->rd_indcollation[i];
180 }
181
182 /* Initialize amcache if needed with options from metapage */
183 if (!index->rd_amcache)
184 {
185 Buffer buffer;
186 Page page;
187 BloomMetaPageData *meta;
189
190 opts = MemoryContextAlloc(index->rd_indexcxt, sizeof(BloomOptions));
191
194
195 page = BufferGetPage(buffer);
196
197 if (!BloomPageIsMeta(page))
198 elog(ERROR, "Relation is not a bloom index");
199 meta = BloomPageGetMeta(BufferGetPage(buffer));
200
202 elog(ERROR, "Relation is not a bloom index");
203
204 *opts = meta->opts;
205
206 UnlockReleaseBuffer(buffer);
207
208 index->rd_amcache = opts;
209 }
210
211 memcpy(&state->opts, index->rd_amcache, sizeof(state->opts));
212 state->sizeOfBloomTuple = BLOOMTUPLEHDRSZ +
213 sizeof(BloomSignatureWord) * state->opts.bloomLength;
214}
#define BLOOMTUPLEHDRSZ
Definition: bloom.h:163
#define BLOOM_HASH_PROC
Definition: bloom.h:24
uint16 BloomSignatureWord
Definition: bloom.h:84
#define BloomPageIsMeta(page)
Definition: bloom.h:62
@ BUFFER_LOCK_SHARE
Definition: bufmgr.h:206
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
void fmgr_info_copy(FmgrInfo *dstinfo, FmgrInfo *srcinfo, MemoryContext destcxt)
Definition: fmgr.c:581
FmgrInfo * index_getprocinfo(Relation irel, AttrNumber attnum, uint16 procnum)
Definition: indexam.c:917
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:1232
MemoryContext CurrentMemoryContext
Definition: mcxt.c:160

References BLOOM_HASH_PROC, BLOOM_MAGICK_NUMBER, BLOOM_METAPAGE_BLKNO, BloomPageGetMeta, BloomPageIsMeta, BLOOMTUPLEHDRSZ, BUFFER_LOCK_SHARE, BufferGetPage(), CurrentMemoryContext, elog, ERROR, fmgr_info_copy(), i, index_getprocinfo(), LockBuffer(), BloomMetaPageData::magickNumber, MemoryContextAlloc(), BloomMetaPageData::opts, opts, ReadBuffer(), and UnlockReleaseBuffer().

Referenced by blbeginscan(), blbuild(), blbulkdelete(), and blinsert().

◆ makeDefaultBloomOptions()

static BloomOptions * makeDefaultBloomOptions ( void  )
static

Definition at line 84 of file blutils.c.

85{
87 int i;
88
90 /* Convert DEFAULT_BLOOM_LENGTH from # of bits to # of words */
91 opts->bloomLength = (DEFAULT_BLOOM_LENGTH + SIGNWORDBITS - 1) / SIGNWORDBITS;
92 for (i = 0; i < INDEX_MAX_KEYS; i++)
93 opts->bitSize[i] = DEFAULT_BLOOM_BITS;
95 return opts;
96}
#define palloc0_object(type)
Definition: fe_memutils.h:75
static void SET_VARSIZE(void *PTR, Size len)
Definition: varatt.h:432

References DEFAULT_BLOOM_BITS, DEFAULT_BLOOM_LENGTH, i, INDEX_MAX_KEYS, opts, palloc0_object, SET_VARSIZE(), and SIGNWORDBITS.

Referenced by BloomFillMetapage().

◆ myRand()

static int32 myRand ( void  )
static

Definition at line 228 of file blutils.c.

229{
230 /*----------
231 * Compute x = (7^5 * x) mod (2^31 - 1)
232 * without overflowing 31 bits:
233 * (2^31 - 1) = 127773 * (7^5) + 2836
234 * From "Random number generators: good ones are hard to find",
235 * Park and Miller, Communications of the ACM, vol. 31, no. 10,
236 * October 1988, p. 1195.
237 *----------
238 */
239 int32 hi,
240 lo,
241 x;
242
243 /* Must be in [1, 0x7ffffffe] range at this point. */
244 hi = next / 127773;
245 lo = next % 127773;
246 x = 16807 * lo - 2836 * hi;
247 if (x < 0)
248 x += 0x7fffffff;
249 next = x;
250 /* Transform to [0, 0x7ffffffd] range. */
251 return (x - 1);
252}
static int32 next
Definition: blutils.c:225
int32_t int32
Definition: c.h:548
int x
Definition: isn.c:75

References next, and x.

Referenced by signValue().

◆ mySrand()

static void mySrand ( uint32  seed)
static

Definition at line 255 of file blutils.c.

256{
257 next = seed;
258 /* Transform to [1, 0x7ffffffe] range. */
259 next = (next % 0x7ffffffe) + 1;
260}

References next.

Referenced by signValue().

◆ PG_FUNCTION_INFO_V1()

PG_FUNCTION_INFO_V1 ( blhandler  )

◆ signValue()

void signValue ( BloomState state,
BloomSignatureWord sign,
Datum  value,
int  attno 
)

Definition at line 266 of file blutils.c.

267{
268 uint32 hashVal;
269 int nBit,
270 j;
271
272 /*
273 * init generator with "column's" number to get "hashed" seed for new
274 * value. We don't want to map the same numbers from different columns
275 * into the same bits!
276 */
277 mySrand(attno);
278
279 /*
280 * Init hash sequence to map our value into bits. the same values in
281 * different columns will be mapped into different bits because of step
282 * above
283 */
284 hashVal = DatumGetInt32(FunctionCall1Coll(&state->hashFn[attno], state->collations[attno], value));
285 mySrand(hashVal ^ myRand());
286
287 for (j = 0; j < state->opts.bitSize[attno]; j++)
288 {
289 /* prevent multiple evaluation in SETBIT macro */
290 nBit = myRand() % (state->opts.bloomLength * SIGNWORDBITS);
291 SETBIT(sign, nBit);
292 }
293}
static int32 myRand(void)
Definition: blutils.c:228
#define SETBIT(x, i)
Definition: blutils.c:29
static void mySrand(uint32 seed)
Definition: blutils.c:255
uint32_t uint32
Definition: c.h:552
Datum FunctionCall1Coll(FmgrInfo *flinfo, Oid collation, Datum arg1)
Definition: fmgr.c:1130
static struct @171 value
char sign
Definition: informix.c:693
int j
Definition: isn.c:78
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:212

References DatumGetInt32(), FunctionCall1Coll(), j, myRand(), mySrand(), SETBIT, sign, SIGNWORDBITS, and value.

Referenced by blgetbitmap(), and BloomFormTuple().

Variable Documentation

◆ bl_relopt_kind

relopt_kind bl_relopt_kind
static

Definition at line 35 of file blutils.c.

Referenced by _PG_init(), and bloptions().

◆ bl_relopt_tab

relopt_parse_elt bl_relopt_tab[INDEX_MAX_KEYS+1]
static

Definition at line 38 of file blutils.c.

Referenced by _PG_init(), and bloptions().

◆ next

int32 next
static

Definition at line 225 of file blutils.c.

Referenced by _pglstat64(), _pgstat64(), addItemsToLeaf(), AllocSetDelete(), AllocSetReset(), appendBoolResult(), astreamer_gzip_decompressor_new(), astreamer_lz4_compressor_new(), astreamer_lz4_decompressor_new(), astreamer_recovery_injector_new(), astreamer_tar_archiver_new(), astreamer_tar_parser_new(), astreamer_tar_terminator_new(), astreamer_verify_content_new(), astreamer_zstd_compressor_new(), astreamer_zstd_decompressor_new(), AtEOSubXact_SPI(), AtSubAbort_Snapshot(), bbsink_gzip_new(), bbsink_lz4_new(), bbsink_progress_new(), bbsink_server_new(), bbsink_throttle_new(), bbsink_zstd_new(), CallSubXactCallbacks(), CallXactCallbacks(), deallocate_one(), delete_item_from_bucket(), delete_key_from_bucket(), descriptor_deallocate_all(), doLog(), dsa_trim(), ecpg_register_prepared_stmt(), ecpg_sqlda_align_add_size(), ECPGconnect(), encrypt_init(), encrypt_process(), entry_purge_tuples(), ExecHashTableDetachBatch(), ExecParallelHashNextTuple(), executeKeyValueMethod(), executeNextItem(), executeNumericItemMethod(), extract_jsp_path_expr_nodes(), find_struct(), find_struct_member(), find_variable(), flattenJsonPathParseItem(), FreeConfigVariables(), FreePageManagerGetInternal(), FreePagePopSpanLeader(), get_nextfield(), get_source_line(), get_typedef(), getNextFlagFromString(), GinDataLeafPageGetItems(), heap_lock_updated_tuple_rec(), intset_iterate_next(), IssuePendingWritebacks(), jspIsMutableWalker(), LagTrackerRead(), lrq_alloc(), make_new_segment(), merge_children(), myRand(), mySrand(), nextval_internal(), pg_event_trigger_dropped_objects(), pgstat_flush_pending_entries(), pkt_stream_flush(), pkt_stream_process(), plpgsql_destroy_econtext(), plpgsql_subxact_cb(), PostPrepare_smgr(), pqTraceOutputNchar(), prepare_common(), pushf_create(), ReadMultiXactIdRange(), rebin_segment(), RecordNewMultiXact(), RelationPreserveStorage(), remove_typedefs(), remove_variables(), ReorderBufferIterTXNNext(), replace_auto_config_value(), reset_variables(), ResourceOwnerReleaseInternal(), setCompoundAffixFlagValue(), SetSequence(), setval3_oid(), setval_oid(), simple_oid_list_destroy(), simple_ptr_list_destroy(), simple_string_list_destroy(), smgrDoPendingDeletes(), SPI_freetuptable(), StandbyReleaseXidEntryLocks(), unicode_normalize(), unlink_segment(), unlink_span(), and validate_log_connections_options().