PostgreSQL Source Code git master
Loading...
Searching...
No Matches
bloom.h File Reference
#include "access/amapi.h"
#include "access/generic_xlog.h"
#include "access/itup.h"
#include "access/xlog.h"
#include "fmgr.h"
#include "nodes/pathnodes.h"
Include dependency graph for bloom.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  BloomPageOpaqueData
 
struct  BloomOptions
 
struct  BloomMetaPageData
 
struct  BloomState
 
struct  BloomTuple
 
struct  BloomScanOpaqueData
 

Macros

#define BLOOM_HASH_PROC   1
 
#define BLOOM_OPTIONS_PROC   2
 
#define BLOOM_NPROC   2
 
#define BLOOM_EQUAL_STRATEGY   1
 
#define BLOOM_NSTRATEGIES   1
 
#define BLOOM_META   (1<<0)
 
#define BLOOM_DELETED   (2<<0)
 
#define BLOOM_PAGE_ID   0xFF83
 
#define BloomPageGetOpaque(page)   ((BloomPageOpaque) PageGetSpecialPointer(page))
 
#define BloomPageGetMaxOffset(page)   (BloomPageGetOpaque(page)->maxoff)
 
#define BloomPageIsMeta(page)    ((BloomPageGetOpaque(page)->flags & BLOOM_META) != 0)
 
#define BloomPageIsDeleted(page)    ((BloomPageGetOpaque(page)->flags & BLOOM_DELETED) != 0)
 
#define BloomPageSetDeleted(page)    (BloomPageGetOpaque(page)->flags |= BLOOM_DELETED)
 
#define BloomPageSetNonDeleted(page)    (BloomPageGetOpaque(page)->flags &= ~BLOOM_DELETED)
 
#define BloomPageGetData(page)   ((BloomTuple *)PageGetContents(page))
 
#define BloomPageGetTuple(state, page, offset)
 
#define BloomPageGetNextTuple(state, tuple)    ((BloomTuple *)((char *)(tuple) + (state)->sizeOfBloomTuple))
 
#define BLOOM_METAPAGE_BLKNO   (0)
 
#define BLOOM_HEAD_BLKNO   (1) /* first data page */
 
#define SIGNWORDBITS   ((int) (BITS_PER_BYTE * sizeof(BloomSignatureWord)))
 
#define DEFAULT_BLOOM_LENGTH   (5 * SIGNWORDBITS)
 
#define MAX_BLOOM_LENGTH   (256 * SIGNWORDBITS)
 
#define DEFAULT_BLOOM_BITS   2
 
#define MAX_BLOOM_BITS   (MAX_BLOOM_LENGTH - 1)
 
#define BLOOM_MAGICK_NUMBER   (0xDBAC0DED)
 
#define BloomMetaBlockN   (sizeof(FreeBlockNumberArray) / sizeof(BlockNumber))
 
#define BloomPageGetMeta(page)   ((BloomMetaPageData *) PageGetContents(page))
 
#define BloomPageGetFreeSpace(state, page)
 
#define BLOOMTUPLEHDRSZ   offsetof(BloomTuple, sign)
 

Typedefs

typedef struct BloomPageOpaqueData BloomPageOpaqueData
 
typedef BloomPageOpaqueDataBloomPageOpaque
 
typedef uint16 BloomSignatureWord
 
typedef struct BloomOptions BloomOptions
 
typedef BlockNumber FreeBlockNumberArray[MAXALIGN_DOWN(BLCKSZ - SizeOfPageHeaderData - MAXALIGN(sizeof(BloomPageOpaqueData)) - MAXALIGN(sizeof(uint16) *2+sizeof(uint32)+sizeof(BloomOptions)))/sizeof(BlockNumber)]
 
typedef struct BloomMetaPageData BloomMetaPageData
 
typedef struct BloomState BloomState
 
typedef struct BloomTuple BloomTuple
 
typedef struct BloomScanOpaqueData BloomScanOpaqueData
 
typedef BloomScanOpaqueDataBloomScanOpaque
 

Functions

void initBloomState (BloomState *state, Relation index)
 
void BloomFillMetapage (Relation index, Page metaPage)
 
void BloomInitMetapage (Relation index, ForkNumber forknum)
 
void BloomInitPage (Page page, uint16 flags)
 
Buffer BloomNewBuffer (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)
 
bool blvalidate (Oid opclassoid)
 
bool blinsert (Relation index, Datum *values, bool *isnull, ItemPointer ht_ctid, Relation heapRel, IndexUniqueCheck checkUnique, bool indexUnchanged, struct IndexInfo *indexInfo)
 
IndexScanDesc blbeginscan (Relation r, int nkeys, int norderbys)
 
int64 blgetbitmap (IndexScanDesc scan, TIDBitmap *tbm)
 
void blrescan (IndexScanDesc scan, ScanKey scankey, int nscankeys, ScanKey orderbys, int norderbys)
 
void blendscan (IndexScanDesc scan)
 
IndexBuildResultblbuild (Relation heap, Relation index, struct IndexInfo *indexInfo)
 
void blbuildempty (Relation index)
 
IndexBulkDeleteResultblbulkdelete (IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
 
IndexBulkDeleteResultblvacuumcleanup (IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
 
byteabloptions (Datum reloptions, bool validate)
 
void blcostestimate (PlannerInfo *root, IndexPath *path, double loop_count, Cost *indexStartupCost, Cost *indexTotalCost, Selectivity *indexSelectivity, double *indexCorrelation, double *indexPages)
 

Macro Definition Documentation

◆ BLOOM_DELETED

#define BLOOM_DELETED   (2<<0)

Definition at line 47 of file bloom.h.

◆ BLOOM_EQUAL_STRATEGY

#define BLOOM_EQUAL_STRATEGY   1

Definition at line 29 of file bloom.h.

◆ BLOOM_HASH_PROC

#define BLOOM_HASH_PROC   1

Definition at line 24 of file bloom.h.

◆ BLOOM_HEAD_BLKNO

#define BLOOM_HEAD_BLKNO   (1) /* first data page */

Definition at line 79 of file bloom.h.

◆ BLOOM_MAGICK_NUMBER

#define BLOOM_MAGICK_NUMBER   (0xDBAC0DED)

Definition at line 128 of file bloom.h.

◆ BLOOM_META

#define BLOOM_META   (1<<0)

Definition at line 46 of file bloom.h.

◆ BLOOM_METAPAGE_BLKNO

#define BLOOM_METAPAGE_BLKNO   (0)

Definition at line 78 of file bloom.h.

◆ BLOOM_NPROC

#define BLOOM_NPROC   2

Definition at line 26 of file bloom.h.

◆ BLOOM_NSTRATEGIES

#define BLOOM_NSTRATEGIES   1

Definition at line 30 of file bloom.h.

◆ BLOOM_OPTIONS_PROC

#define BLOOM_OPTIONS_PROC   2

Definition at line 25 of file bloom.h.

◆ BLOOM_PAGE_ID

#define BLOOM_PAGE_ID   0xFF83

Definition at line 57 of file bloom.h.

◆ BloomMetaBlockN

#define BloomMetaBlockN   (sizeof(FreeBlockNumberArray) / sizeof(BlockNumber))

Definition at line 131 of file bloom.h.

◆ BloomPageGetData

#define BloomPageGetData (   page)    ((BloomTuple *)PageGetContents(page))

Definition at line 70 of file bloom.h.

◆ BloomPageGetFreeSpace

#define BloomPageGetFreeSpace (   state,
  page 
)
Value:
- BloomPageGetMaxOffset(page) * (state)->sizeOfBloomTuple \
#define BloomPageGetMaxOffset(page)
Definition bloom.h:61
#define SizeOfPageHeaderData
Definition bufpage.h:242
#define MAXALIGN(LEN)
Definition c.h:898
static int fb(int x)

Definition at line 149 of file bloom.h.

157{
158 ItemPointerData heapPtr;
160} BloomTuple;
161
162#define BLOOMTUPLEHDRSZ offsetof(BloomTuple, sign)
163
164/* Opaque data structure for bloom index scan */
165typedef struct BloomScanOpaqueData
166{
167 BloomSignatureWord *sign; /* Scan signature */
170
172
173/* blutils.c */
176extern void BloomInitMetapage(Relation index, ForkNumber forknum);
177extern void BloomInitPage(Page page, uint16 flags);
179extern void signValue(BloomState *state, BloomSignatureWord *sign, Datum value, int attno);
180extern BloomTuple *BloomFormTuple(BloomState *state, ItemPointer iptr, Datum *values, bool *isnull);
181extern bool BloomPageAddItem(BloomState *state, Page page, BloomTuple *tuple);
182
183/* blvalidate.c */
184extern bool blvalidate(Oid opclassoid);
185
186/* index access method interface functions */
187extern bool blinsert(Relation index, Datum *values, bool *isnull,
190 bool indexUnchanged,
191 struct IndexInfo *indexInfo);
192extern IndexScanDesc blbeginscan(Relation r, int nkeys, int norderbys);
193extern int64 blgetbitmap(IndexScanDesc scan, TIDBitmap *tbm);
194extern void blrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys,
195 ScanKey orderbys, int norderbys);
196extern void blendscan(IndexScanDesc scan);
198 struct IndexInfo *indexInfo);
199extern void blbuildempty(Relation index);
202 void *callback_state);
204 IndexBulkDeleteResult *stats);
205extern bytea *bloptions(Datum reloptions, bool validate);
206extern void blcostestimate(PlannerInfo *root, IndexPath *path,
207 double loop_count, Cost *indexStartupCost,
208 Cost *indexTotalCost, Selectivity *indexSelectivity,
209 double *indexCorrelation, double *indexPages);
210
211#endif
static bool validate(Port *port, const char *auth)
Definition auth-oauth.c:638
IndexBuildResult * blbuild(Relation heap, Relation index, struct IndexInfo *indexInfo)
Definition blinsert.c:122
bool blvalidate(Oid opclassoid)
Definition blvalidate.c:30
void BloomInitPage(Page page, uint16 flags)
Definition blutils.c:405
int64 blgetbitmap(IndexScanDesc scan, TIDBitmap *tbm)
Definition blscan.c:77
IndexScanDesc blbeginscan(Relation r, int nkeys, int norderbys)
Definition blscan.c:27
BloomTuple * BloomFormTuple(BloomState *state, ItemPointer iptr, Datum *values, bool *isnull)
Definition blutils.c:299
bool BloomPageAddItem(BloomState *state, Page page, BloomTuple *tuple)
Definition blutils.c:324
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
Buffer BloomNewBuffer(Relation index)
Definition blutils.c:359
IndexBulkDeleteResult * blbulkdelete(IndexVacuumInfo *info, IndexBulkDeleteResult *stats, IndexBulkDeleteCallback callback, void *callback_state)
Definition blvacuum.c:31
void BloomFillMetapage(Relation index, Page metaPage)
Definition blutils.c:420
bool blinsert(Relation index, Datum *values, bool *isnull, ItemPointer ht_ctid, Relation heapRel, IndexUniqueCheck checkUnique, bool indexUnchanged, struct IndexInfo *indexInfo)
Definition blinsert.c:175
void BloomInitMetapage(Relation index, ForkNumber forknum)
Definition blutils.c:452
bytea * bloptions(Datum reloptions, bool validate)
Definition blutils.c:481
IndexBulkDeleteResult * blvacuumcleanup(IndexVacuumInfo *info, IndexBulkDeleteResult *stats)
Definition blvacuum.c:188
uint16 BloomSignatureWord
Definition bloom.h:84
void signValue(BloomState *state, BloomSignatureWord *sign, Datum value, int attno)
Definition blutils.c:266
void initBloomState(BloomState *state, Relation index)
Definition blutils.c:167
BloomScanOpaqueData * BloomScanOpaque
Definition bloom.h:172
void blendscan(IndexScanDesc scan)
Definition blscan.c:64
void blrescan(IndexScanDesc scan, ScanKey scankey, int nscankeys, ScanKey orderbys, int norderbys)
Definition blscan.c:47
static Datum values[MAXATTR]
Definition bootstrap.c:188
int Buffer
Definition buf.h:23
PageData * Page
Definition bufpage.h:81
int64_t int64
Definition c.h:615
#define FLEXIBLE_ARRAY_MEMBER
Definition c.h:552
uint16_t uint16
Definition c.h:617
bool(* IndexBulkDeleteCallback)(ItemPointer itemptr, void *state)
Definition genam.h:95
IndexUniqueCheck
Definition genam.h:124
static struct @175 value
char sign
Definition informix.c:693
double Cost
Definition nodes.h:261
double Selectivity
Definition nodes.h:260
uint64_t Datum
Definition postgres.h:70
unsigned int Oid
tree ctl root
Definition radixtree.h:1857
ForkNumber
Definition relpath.h:56
BloomSignatureWord * sign
Definition bloom.h:168
BloomState state
Definition bloom.h:169
Definition type.h:96
Definition c.h:778
static void callback(struct sockaddr *addr, struct sockaddr *mask, void *unused)

◆ BloomPageGetMaxOffset

#define BloomPageGetMaxOffset (   page)    (BloomPageGetOpaque(page)->maxoff)

Definition at line 61 of file bloom.h.

◆ BloomPageGetMeta

#define BloomPageGetMeta (   page)    ((BloomMetaPageData *) PageGetContents(page))

Definition at line 133 of file bloom.h.

◆ BloomPageGetNextTuple

#define BloomPageGetNextTuple (   state,
  tuple 
)     ((BloomTuple *)((char *)(tuple) + (state)->sizeOfBloomTuple))

Definition at line 74 of file bloom.h.

◆ BloomPageGetOpaque

#define BloomPageGetOpaque (   page)    ((BloomPageOpaque) PageGetSpecialPointer(page))

Definition at line 60 of file bloom.h.

◆ BloomPageGetTuple

#define BloomPageGetTuple (   state,
  page,
  offset 
)
Value:
+ (state)->sizeOfBloomTuple * ((offset) - 1)))
static char * PageGetContents(Page page)
Definition bufpage.h:283

Definition at line 71 of file bloom.h.

◆ BloomPageIsDeleted

#define BloomPageIsDeleted (   page)     ((BloomPageGetOpaque(page)->flags & BLOOM_DELETED) != 0)

Definition at line 64 of file bloom.h.

◆ BloomPageIsMeta

#define BloomPageIsMeta (   page)     ((BloomPageGetOpaque(page)->flags & BLOOM_META) != 0)

Definition at line 62 of file bloom.h.

◆ BloomPageSetDeleted

#define BloomPageSetDeleted (   page)     (BloomPageGetOpaque(page)->flags |= BLOOM_DELETED)

Definition at line 66 of file bloom.h.

◆ BloomPageSetNonDeleted

#define BloomPageSetNonDeleted (   page)     (BloomPageGetOpaque(page)->flags &= ~BLOOM_DELETED)

Definition at line 68 of file bloom.h.

◆ BLOOMTUPLEHDRSZ

#define BLOOMTUPLEHDRSZ   offsetof(BloomTuple, sign)

Definition at line 163 of file bloom.h.

◆ DEFAULT_BLOOM_BITS

#define DEFAULT_BLOOM_BITS   2

Definition at line 97 of file bloom.h.

◆ DEFAULT_BLOOM_LENGTH

#define DEFAULT_BLOOM_LENGTH   (5 * SIGNWORDBITS)

Definition at line 91 of file bloom.h.

◆ MAX_BLOOM_BITS

#define MAX_BLOOM_BITS   (MAX_BLOOM_LENGTH - 1)

Definition at line 98 of file bloom.h.

◆ MAX_BLOOM_LENGTH

#define MAX_BLOOM_LENGTH   (256 * SIGNWORDBITS)

Definition at line 92 of file bloom.h.

◆ SIGNWORDBITS

#define SIGNWORDBITS   ((int) (BITS_PER_BYTE * sizeof(BloomSignatureWord)))

Definition at line 86 of file bloom.h.

Typedef Documentation

◆ BloomMetaPageData

◆ BloomOptions

◆ BloomPageOpaque

Definition at line 43 of file bloom.h.

◆ BloomPageOpaqueData

◆ BloomScanOpaque

Definition at line 172 of file bloom.h.

◆ BloomScanOpaqueData

◆ BloomSignatureWord

Definition at line 84 of file bloom.h.

◆ BloomState

◆ BloomTuple

◆ FreeBlockNumberArray

Function Documentation

◆ blbeginscan()

IndexScanDesc blbeginscan ( Relation  r,
int  nkeys,
int  norderbys 
)
extern

Definition at line 27 of file blscan.c.

28{
29 IndexScanDesc scan;
31
32 scan = RelationGetIndexScan(r, nkeys, norderbys);
33
35 initBloomState(&so->state, scan->indexRelation);
36 so->sign = NULL;
37
38 scan->opaque = so;
39
40 return scan;
41}
#define palloc_object(type)
Definition fe_memutils.h:74
IndexScanDesc RelationGetIndexScan(Relation indexRelation, int nkeys, int norderbys)
Definition genam.c:80
Relation indexRelation
Definition relscan.h:138

References fb(), IndexScanDescData::indexRelation, initBloomState(), IndexScanDescData::opaque, palloc_object, and RelationGetIndexScan().

Referenced by blhandler().

◆ blbuild()

IndexBuildResult * blbuild ( Relation  heap,
Relation  index,
struct IndexInfo indexInfo 
)
extern

Definition at line 122 of file blinsert.c.

123{
124 IndexBuildResult *result;
125 double reltuples;
127
129 elog(ERROR, "index \"%s\" already contains data",
131
132 /* Initialize the meta page */
134
135 /* Initialize the bloom build state */
136 memset(&buildstate, 0, sizeof(buildstate));
139 "Bloom build temporary context",
142
143 /* Do the heap scan */
144 reltuples = table_index_build_scan(heap, index, indexInfo, true, true,
146 NULL);
147
148 /* Flush last page if needed (it will be, unless heap was empty) */
149 if (buildstate.count > 0)
151
153
155 result->heap_tuples = reltuples;
156 result->index_tuples = buildstate.indtuples;
157
158 return result;
159}
static void initCachedPage(BloomBuildState *buildstate)
Definition blinsert.c:65
static void flushCachedPage(Relation index, BloomBuildState *buildstate)
Definition blinsert.c:48
static void bloomBuildCallback(Relation index, ItemPointer tid, Datum *values, bool *isnull, bool tupleIsAlive, void *state)
Definition blinsert.c:75
#define RelationGetNumberOfBlocks(reln)
Definition bufmgr.h:309
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:226
MemoryContext CurrentMemoryContext
Definition mcxt.c:160
void MemoryContextDelete(MemoryContext context)
Definition mcxt.c:472
#define AllocSetContextCreate
Definition memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition memutils.h:160
#define RelationGetRelationName(relation)
Definition rel.h:548
@ MAIN_FORKNUM
Definition relpath.h:58
double heap_tuples
Definition genam.h:40
double index_tuples
Definition genam.h:41
static double table_index_build_scan(Relation table_rel, Relation index_rel, IndexInfo *index_info, bool allow_sync, bool progress, IndexBuildCallback callback, void *callback_state, TableScanDesc scan)
Definition tableam.h:1768

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, bloomBuildCallback(), BloomInitMetapage(), CurrentMemoryContext, elog, ERROR, fb(), flushCachedPage(), IndexBuildResult::heap_tuples, IndexBuildResult::index_tuples, initBloomState(), initCachedPage(), MAIN_FORKNUM, MemoryContextDelete(), palloc_object, RelationGetNumberOfBlocks, RelationGetRelationName, and table_index_build_scan().

Referenced by blhandler().

◆ blbuildempty()

void blbuildempty ( Relation  index)
extern

Definition at line 165 of file blinsert.c.

166{
167 /* Initialize the meta page */
169}
@ INIT_FORKNUM
Definition relpath.h:61

References BloomInitMetapage(), and INIT_FORKNUM.

Referenced by blhandler().

◆ blbulkdelete()

IndexBulkDeleteResult * blbulkdelete ( IndexVacuumInfo info,
IndexBulkDeleteResult stats,
IndexBulkDeleteCallback  callback,
void callback_state 
)
extern

Definition at line 31 of file blvacuum.c.

33{
34 Relation index = info->index;
35 BlockNumber blkno,
36 npages;
37 FreeBlockNumberArray notFullPage;
38 int countPage = 0;
40 Buffer buffer;
41 Page page;
45 ReadStream *stream;
46
47 if (stats == NULL)
49
51
52 /*
53 * Iterate over the pages. We don't care about concurrently added pages,
54 * they can't contain tuples to delete.
55 */
57
58 /* Scan all blocks except the metapage using streaming reads */
60 p.last_exclusive = npages;
61
62 /*
63 * It is safe to use batchmode as block_range_read_stream_cb takes no
64 * locks.
65 */
69 info->strategy,
70 index,
73 &p,
74 0);
75
76 for (blkno = BLOOM_HEAD_BLKNO; blkno < npages; blkno++)
77 {
78 BloomTuple *itup,
79 *itupPtr,
80 *itupEnd;
81
82 vacuum_delay_point(false);
83
84 buffer = read_stream_next_buffer(stream, NULL);
85
88 page = GenericXLogRegisterBuffer(gxlogState, buffer, 0);
89
90 /* Ignore empty/deleted pages until blvacuumcleanup() */
91 if (PageIsNew(page) || BloomPageIsDeleted(page))
92 {
93 UnlockReleaseBuffer(buffer);
95 continue;
96 }
97
98 /*
99 * Iterate over the tuples. itup points to current tuple being
100 * scanned, itupPtr points to where to save next non-deleted tuple.
101 */
105 while (itup < itupEnd)
106 {
107 /* Do we have to delete this tuple? */
108 if (callback(&itup->heapPtr, callback_state))
109 {
110 /* Yes; adjust count of tuples that will be left on page */
111 BloomPageGetOpaque(page)->maxoff--;
112 stats->tuples_removed += 1;
113 }
114 else
115 {
116 /* No; copy it to itupPtr++, but skip copy if not needed */
117 if (itupPtr != itup)
118 memmove(itupPtr, itup, state.sizeOfBloomTuple);
120 }
121
122 itup = BloomPageGetNextTuple(&state, itup);
123 }
124
125 /* Assert that we counted correctly */
128
129 /*
130 * Add page to new notFullPage list if we will not mark page as
131 * deleted and there is free space on it
132 */
133 if (BloomPageGetMaxOffset(page) != 0 &&
134 BloomPageGetFreeSpace(&state, page) >= state.sizeOfBloomTuple &&
136 notFullPage[countPage++] = blkno;
137
138 /* Did we delete something? */
139 if (itupPtr != itup)
140 {
141 /* Is it empty page now? */
142 if (BloomPageGetMaxOffset(page) == 0)
144 /* Adjust pd_lower */
145 ((PageHeader) page)->pd_lower = (char *) itupPtr - page;
146 /* Finish WAL-logging */
148 }
149 else
150 {
151 /* Didn't change anything: abort WAL-logging */
153 }
154 UnlockReleaseBuffer(buffer);
155 }
156
158 read_stream_end(stream);
159
160 /*
161 * Update the metapage's notFullPage list with whatever we found. Our
162 * info could already be out of date at this point, but blinsert() will
163 * cope if so.
164 */
167
169 page = GenericXLogRegisterBuffer(gxlogState, buffer, 0);
170
172 memcpy(metaData->notFullPage, notFullPage, sizeof(BlockNumber) * countPage);
173 metaData->nStart = 0;
174 metaData->nEnd = countPage;
175
177 UnlockReleaseBuffer(buffer);
178
179 return stats;
180}
uint32 BlockNumber
Definition block.h:31
#define BloomPageGetOpaque(page)
Definition bloom.h:60
#define BloomPageGetFreeSpace(state, page)
Definition bloom.h:149
#define BloomPageGetMeta(page)
Definition bloom.h:133
BlockNumber FreeBlockNumberArray[MAXALIGN_DOWN(BLCKSZ - SizeOfPageHeaderData - MAXALIGN(sizeof(BloomPageOpaqueData)) - MAXALIGN(sizeof(uint16) *2+sizeof(uint32)+sizeof(BloomOptions)))/sizeof(BlockNumber)]
Definition bloom.h:115
#define BloomPageGetTuple(state, page, offset)
Definition bloom.h:71
#define BloomPageSetDeleted(page)
Definition bloom.h:66
#define BloomPageGetNextTuple(state, tuple)
Definition bloom.h:74
#define BloomPageIsDeleted(page)
Definition bloom.h:64
#define BLOOM_HEAD_BLKNO
Definition bloom.h:79
#define BloomMetaBlockN
Definition bloom.h:131
#define BLOOM_METAPAGE_BLKNO
Definition bloom.h:78
#define InvalidBuffer
Definition buf.h:25
void UnlockReleaseBuffer(Buffer buffer)
Definition bufmgr.c:5583
Buffer ReadBuffer(Relation reln, BlockNumber blockNum)
Definition bufmgr.c:879
@ BUFFER_LOCK_EXCLUSIVE
Definition bufmgr.h:222
static void LockBuffer(Buffer buffer, BufferLockMode mode)
Definition bufmgr.h:334
PageHeaderData * PageHeader
Definition bufpage.h:199
static bool PageIsNew(const PageData *page)
Definition bufpage.h:259
#define Assert(condition)
Definition c.h:945
#define palloc0_object(type)
Definition fe_memutils.h:75
Page GenericXLogRegisterBuffer(GenericXLogState *state, Buffer buffer, int flags)
GenericXLogState * GenericXLogStart(Relation relation)
XLogRecPtr GenericXLogFinish(GenericXLogState *state)
void GenericXLogAbort(GenericXLogState *state)
#define OffsetNumberNext(offsetNumber)
Definition off.h:52
#define FirstOffsetNumber
Definition off.h:27
Buffer read_stream_next_buffer(ReadStream *stream, void **per_buffer_data)
ReadStream * read_stream_begin_relation(int flags, BufferAccessStrategy strategy, Relation rel, ForkNumber forknum, ReadStreamBlockNumberCB callback, void *callback_private_data, size_t per_buffer_data_size)
void read_stream_end(ReadStream *stream)
BlockNumber block_range_read_stream_cb(ReadStream *stream, void *callback_private_data, void *per_buffer_data)
#define READ_STREAM_MAINTENANCE
Definition read_stream.h:28
#define READ_STREAM_USE_BATCHING
Definition read_stream.h:64
#define READ_STREAM_FULL
Definition read_stream.h:43
ItemPointerData heapPtr
Definition bloom.h:159
double tuples_removed
Definition genam.h:88
Relation index
Definition genam.h:54
BufferAccessStrategy strategy
Definition genam.h:61
void vacuum_delay_point(bool is_analyze)
Definition vacuum.c:2431

References Assert, block_range_read_stream_cb(), BLOOM_HEAD_BLKNO, BLOOM_METAPAGE_BLKNO, BloomMetaBlockN, BloomPageGetFreeSpace, BloomPageGetMaxOffset, BloomPageGetMeta, BloomPageGetNextTuple, BloomPageGetOpaque, BloomPageGetTuple, BloomPageIsDeleted, BloomPageSetDeleted, BUFFER_LOCK_EXCLUSIVE, callback(), BlockRangeReadStreamPrivate::current_blocknum, fb(), FirstOffsetNumber, GenericXLogAbort(), GenericXLogFinish(), GenericXLogRegisterBuffer(), GenericXLogStart(), BloomTuple::heapPtr, IndexVacuumInfo::index, initBloomState(), InvalidBuffer, BlockRangeReadStreamPrivate::last_exclusive, LockBuffer(), MAIN_FORKNUM, OffsetNumberNext, PageIsNew(), palloc0_object, read_stream_begin_relation(), read_stream_end(), READ_STREAM_FULL, READ_STREAM_MAINTENANCE, read_stream_next_buffer(), READ_STREAM_USE_BATCHING, ReadBuffer(), RelationGetNumberOfBlocks, IndexVacuumInfo::strategy, IndexBulkDeleteResult::tuples_removed, UnlockReleaseBuffer(), and vacuum_delay_point().

Referenced by blhandler().

◆ blcostestimate()

void blcostestimate ( PlannerInfo root,
IndexPath path,
double  loop_count,
Cost indexStartupCost,
Cost indexTotalCost,
Selectivity indexSelectivity,
double indexCorrelation,
double indexPages 
)
extern

Definition at line 22 of file blcost.c.

26{
28 GenericCosts costs = {0};
29
30 /* We have to visit all index tuples anyway */
31 costs.numIndexTuples = index->tuples;
32
33 /* As in btcostestimate, count only the metapage as non-leaf */
34 costs.numNonLeafPages = 1;
35
36 /* Use generic estimate */
37 genericcostestimate(root, path, loop_count, &costs);
38
39 *indexStartupCost = costs.indexStartupCost;
40 *indexTotalCost = costs.indexTotalCost;
41 *indexSelectivity = costs.indexSelectivity;
42 *indexCorrelation = costs.indexCorrelation;
44}
void genericcostestimate(PlannerInfo *root, IndexPath *path, double loop_count, GenericCosts *costs)
Definition selfuncs.c:7397
Selectivity indexSelectivity
Definition selfuncs.h:135
BlockNumber numNonLeafPages
Definition selfuncs.h:143
Cost indexStartupCost
Definition selfuncs.h:133
double indexCorrelation
Definition selfuncs.h:136
Cost indexTotalCost
Definition selfuncs.h:134
double numIndexPages
Definition selfuncs.h:139
double numIndexTuples
Definition selfuncs.h:140
IndexOptInfo * indexinfo
Definition pathnodes.h:2056

References fb(), genericcostestimate(), GenericCosts::indexCorrelation, IndexPath::indexinfo, GenericCosts::indexSelectivity, GenericCosts::indexStartupCost, GenericCosts::indexTotalCost, GenericCosts::numIndexPages, GenericCosts::numIndexTuples, GenericCosts::numNonLeafPages, and root.

Referenced by blhandler().

◆ blendscan()

void blendscan ( IndexScanDesc  scan)
extern

Definition at line 64 of file blscan.c.

65{
67
68 if (so->sign)
69 pfree(so->sign);
70 so->sign = NULL;
71}
void pfree(void *pointer)
Definition mcxt.c:1616

References fb(), IndexScanDescData::opaque, and pfree().

Referenced by blhandler().

◆ blgetbitmap()

int64 blgetbitmap ( IndexScanDesc  scan,
TIDBitmap tbm 
)
extern

Definition at line 77 of file blscan.c.

78{
79 int64 ntids = 0;
80 BlockNumber blkno,
81 npages;
82 int i;
86 ReadStream *stream;
87
88 if (so->sign == NULL)
89 {
90 /* New search: have to calculate search signature */
91 ScanKey skey = scan->keyData;
92
93 so->sign = palloc0_array(BloomSignatureWord, so->state.opts.bloomLength);
94
95 for (i = 0; i < scan->numberOfKeys; i++)
96 {
97 /*
98 * Assume bloom-indexable operators to be strict, so nothing could
99 * be found for NULL key.
100 */
101 if (skey->sk_flags & SK_ISNULL)
102 {
103 pfree(so->sign);
104 so->sign = NULL;
105 return 0;
106 }
107
108 /* Add next value to the signature */
109 signValue(&so->state, so->sign, skey->sk_argument,
110 skey->sk_attno - 1);
111
112 skey++;
113 }
114 }
115
116 /*
117 * We're going to read the whole index. This is why we use appropriate
118 * buffer access strategy.
119 */
123 if (scan->instrument)
124 scan->instrument->nsearches++;
125
126 /* Scan all blocks except the metapage using streaming reads */
128 p.last_exclusive = npages;
129
130 /*
131 * It is safe to use batchmode as block_range_read_stream_cb takes no
132 * locks.
133 */
136 bas,
137 scan->indexRelation,
140 &p,
141 0);
142
143 for (blkno = BLOOM_HEAD_BLKNO; blkno < npages; blkno++)
144 {
145 Buffer buffer;
146 Page page;
147
148 buffer = read_stream_next_buffer(stream, NULL);
150 page = BufferGetPage(buffer);
151
152 if (!PageIsNew(page) && !BloomPageIsDeleted(page))
153 {
154 OffsetNumber offset,
156
157 for (offset = 1; offset <= maxOffset; offset++)
158 {
159 BloomTuple *itup = BloomPageGetTuple(&so->state, page, offset);
160 bool res = true;
161
162 /* Check index signature with scan signature */
163 for (i = 0; i < so->state.opts.bloomLength; i++)
164 {
165 if ((itup->sign[i] & so->sign[i]) != so->sign[i])
166 {
167 res = false;
168 break;
169 }
170 }
171
172 /* Add matching tuples to bitmap */
173 if (res)
174 {
175 tbm_add_tuples(tbm, &itup->heapPtr, 1, true);
176 ntids++;
177 }
178 }
179 }
180
181 UnlockReleaseBuffer(buffer);
183 }
184
186 read_stream_end(stream);
188
189 return ntids;
190}
@ BAS_BULKREAD
Definition bufmgr.h:37
static Page BufferGetPage(Buffer buffer)
Definition bufmgr.h:472
@ BUFFER_LOCK_SHARE
Definition bufmgr.h:212
#define palloc0_array(type, count)
Definition fe_memutils.h:77
BufferAccessStrategy GetAccessStrategy(BufferAccessStrategyType btype)
Definition freelist.c:461
void FreeAccessStrategy(BufferAccessStrategy strategy)
Definition freelist.c:643
int i
Definition isn.c:77
#define CHECK_FOR_INTERRUPTS()
Definition miscadmin.h:123
uint16 OffsetNumber
Definition off.h:24
#define pgstat_count_index_scan(rel)
Definition pgstat.h:736
#define SK_ISNULL
Definition skey.h:115
BloomSignatureWord sign[FLEXIBLE_ARRAY_MEMBER]
Definition bloom.h:160
struct ScanKeyData * keyData
Definition relscan.h:142
struct IndexScanInstrumentation * instrument
Definition relscan.h:160
void tbm_add_tuples(TIDBitmap *tbm, const ItemPointerData *tids, int ntids, bool recheck)
Definition tidbitmap.c:367

References Assert, BAS_BULKREAD, block_range_read_stream_cb(), BLOOM_HEAD_BLKNO, BloomPageGetMaxOffset, BloomPageGetTuple, BloomPageIsDeleted, BUFFER_LOCK_SHARE, BufferGetPage(), CHECK_FOR_INTERRUPTS, BlockRangeReadStreamPrivate::current_blocknum, fb(), FreeAccessStrategy(), GetAccessStrategy(), BloomTuple::heapPtr, i, IndexScanDescData::indexRelation, IndexScanDescData::instrument, InvalidBuffer, IndexScanDescData::keyData, BlockRangeReadStreamPrivate::last_exclusive, LockBuffer(), MAIN_FORKNUM, IndexScanInstrumentation::nsearches, IndexScanDescData::numberOfKeys, IndexScanDescData::opaque, PageIsNew(), palloc0_array, pfree(), pgstat_count_index_scan, read_stream_begin_relation(), read_stream_end(), READ_STREAM_FULL, read_stream_next_buffer(), READ_STREAM_USE_BATCHING, RelationGetNumberOfBlocks, BloomTuple::sign, signValue(), SK_ISNULL, tbm_add_tuples(), and UnlockReleaseBuffer().

Referenced by blhandler().

◆ blinsert()

bool blinsert ( Relation  index,
Datum values,
bool isnull,
ItemPointer  ht_ctid,
Relation  heapRel,
IndexUniqueCheck  checkUnique,
bool  indexUnchanged,
struct IndexInfo indexInfo 
)
extern

Definition at line 175 of file blinsert.c.

180{
181 BloomState blstate;
182 BloomTuple *itup;
186 Buffer buffer,
188 Page page,
189 metaPage;
191 OffsetNumber nStart;
193
195 "Bloom insert temporary context",
197
199
200 initBloomState(&blstate, index);
201 itup = BloomFormTuple(&blstate, ht_ctid, values, isnull);
202
203 /*
204 * At first, try to insert new tuple to the first page in notFullPage
205 * array. If successful, we don't need to modify the meta page.
206 */
210
211 if (metaData->nEnd > metaData->nStart)
212 {
213 blkno = metaData->notFullPage[metaData->nStart];
214 Assert(blkno != InvalidBlockNumber);
215
216 /* Don't hold metabuffer lock while doing insert */
218
219 buffer = ReadBuffer(index, blkno);
221
223 page = GenericXLogRegisterBuffer(state, buffer, 0);
224
225 /*
226 * We might have found a page that was recently deleted by VACUUM. If
227 * so, we can reuse it, but we must reinitialize it.
228 */
229 if (PageIsNew(page) || BloomPageIsDeleted(page))
230 BloomInitPage(page, 0);
231
232 if (BloomPageAddItem(&blstate, page, itup))
233 {
234 /* Success! Apply the change, clean up, and exit */
236 UnlockReleaseBuffer(buffer);
240 return false;
241 }
242
243 /* Didn't fit, must try other pages */
245 UnlockReleaseBuffer(buffer);
246 }
247 else
248 {
249 /* No entries in notFullPage */
251 }
252
253 /*
254 * Try other pages in notFullPage array. We will have to change nStart in
255 * metapage. Thus, grab exclusive lock on metapage.
256 */
258
259 /* nStart might have changed while we didn't have lock */
260 nStart = metaData->nStart;
261
262 /* Skip first page if we already tried it above */
263 if (nStart < metaData->nEnd &&
264 blkno == metaData->notFullPage[nStart])
265 nStart++;
266
267 /*
268 * This loop iterates for each page we try from the notFullPage array, and
269 * will also initialize a GenericXLogState for the fallback case of having
270 * to allocate a new page.
271 */
272 for (;;)
273 {
275
276 /* get modifiable copy of metapage */
279
280 if (nStart >= metaData->nEnd)
281 break; /* no more entries in notFullPage array */
282
283 blkno = metaData->notFullPage[nStart];
284 Assert(blkno != InvalidBlockNumber);
285
286 buffer = ReadBuffer(index, blkno);
288 page = GenericXLogRegisterBuffer(state, buffer, 0);
289
290 /* Basically same logic as above */
291 if (PageIsNew(page) || BloomPageIsDeleted(page))
292 BloomInitPage(page, 0);
293
294 if (BloomPageAddItem(&blstate, page, itup))
295 {
296 /* Success! Apply the changes, clean up, and exit */
297 metaData->nStart = nStart;
299 UnlockReleaseBuffer(buffer);
303 return false;
304 }
305
306 /* Didn't fit, must try other pages */
308 UnlockReleaseBuffer(buffer);
309 nStart++;
310 }
311
312 /*
313 * Didn't find place to insert in notFullPage array. Allocate new page.
314 * (XXX is it good to do this while holding ex-lock on the metapage??)
315 */
316 buffer = BloomNewBuffer(index);
317
319 BloomInitPage(page, 0);
320
321 if (!BloomPageAddItem(&blstate, page, itup))
322 {
323 /* We shouldn't be here since we're inserting to an empty page */
324 elog(ERROR, "could not add new bloom tuple to empty page");
325 }
326
327 /* Reset notFullPage array to contain just this new page */
328 metaData->nStart = 0;
329 metaData->nEnd = 1;
330 metaData->notFullPage[0] = BufferGetBlockNumber(buffer);
331
332 /* Apply the changes, clean up, and exit */
334
335 UnlockReleaseBuffer(buffer);
337
340
341 return false;
342}
#define InvalidBlockNumber
Definition block.h:33
BlockNumber BufferGetBlockNumber(Buffer buffer)
Definition bufmgr.c:4426
void ReleaseBuffer(Buffer buffer)
Definition bufmgr.c:5566
@ BUFFER_LOCK_UNLOCK
Definition bufmgr.h:207
#define GENERIC_XLOG_FULL_IMAGE
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition palloc.h:124

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, Assert, BLOOM_METAPAGE_BLKNO, BloomFormTuple(), BloomInitPage(), BloomNewBuffer(), BloomPageAddItem(), BloomPageGetMeta, BloomPageIsDeleted, BUFFER_LOCK_EXCLUSIVE, BUFFER_LOCK_SHARE, BUFFER_LOCK_UNLOCK, BufferGetBlockNumber(), BufferGetPage(), CurrentMemoryContext, elog, ERROR, fb(), GENERIC_XLOG_FULL_IMAGE, GenericXLogAbort(), GenericXLogFinish(), GenericXLogRegisterBuffer(), GenericXLogStart(), initBloomState(), InvalidBlockNumber, LockBuffer(), MemoryContextDelete(), MemoryContextSwitchTo(), PageIsNew(), ReadBuffer(), ReleaseBuffer(), UnlockReleaseBuffer(), and values.

Referenced by blhandler().

◆ BloomFillMetapage()

void BloomFillMetapage ( Relation  index,
Page  metaPage 
)
extern

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 */
438 metadata = BloomPageGetMeta(metaPage);
439 memset(metadata, 0, sizeof(BloomMetaPageData));
440 metadata->magickNumber = BLOOM_MAGICK_NUMBER;
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 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
static AmcheckOptions opts
Definition pg_amcheck.c:112

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

Referenced by BloomInitMetapage().

◆ BloomFormTuple()

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

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
void * palloc0(Size size)
Definition mcxt.c:1417

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

Referenced by blinsert(), and bloomBuildCallback().

◆ BloomInitMetapage()

void BloomInitMetapage ( Relation  index,
ForkNumber  forknum 
)
extern

Definition at line 452 of file blutils.c.

453{
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 */
466
467 /* Initialize contents of meta page */
473
475}
void BloomFillMetapage(Relation index, Page metaPage)
Definition blutils.c:420
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Definition bufmgr.c:926
#define P_NEW
Definition bufmgr.h:200
@ RBM_NORMAL
Definition bufmgr.h:46

References Assert, BLOOM_METAPAGE_BLKNO, BloomFillMetapage(), BUFFER_LOCK_EXCLUSIVE, BufferGetBlockNumber(), fb(), 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 
)
extern

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 BLOOM_PAGE_ID
Definition bloom.h:57
void PageInit(Page page, Size pageSize, Size specialSize)
Definition bufpage.c:42
uint16 bloom_page_id
Definition bloom.h:40

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

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

◆ BloomNewBuffer()

Buffer BloomNewBuffer ( Relation  index)
extern

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}
Buffer ExtendBufferedRel(BufferManagerRelation bmr, ForkNumber forkNum, BufferAccessStrategy strategy, uint32 flags)
Definition bufmgr.c:979
bool ConditionalLockBuffer(Buffer buffer)
Definition bufmgr.c:6597
@ EB_LOCK_FIRST
Definition bufmgr.h:87
#define BMR_REL(p_rel)
Definition bufmgr.h:114
BlockNumber GetFreeIndexPage(Relation rel)
Definition indexfsm.c:38

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

Referenced by blinsert(), and flushCachedPage().

◆ BloomPageAddItem()

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

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}
OffsetNumber maxoff
Definition bloom.h:35

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

Referenced by blinsert(), and bloomBuildCallback().

◆ bloptions()

bytea * bloptions ( Datum  reloptions,
bool  validate 
)
extern

Definition at line 481 of file blutils.c.

482{
484
485 /* Parse the user-given reloptions */
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}
#define SIGNWORDBITS
Definition bloom.h:86
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
#define lengthof(array)
Definition c.h:875
void * build_reloptions(Datum reloptions, bool validate, relopt_kind kind, Size relopt_struct_size, const relopt_parse_elt *relopt_elems, int num_relopt_elems)
int bloomLength
Definition bloom.h:104

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

Referenced by blhandler().

◆ blrescan()

void blrescan ( IndexScanDesc  scan,
ScanKey  scankey,
int  nscankeys,
ScanKey  orderbys,
int  norderbys 
)
extern

Definition at line 47 of file blscan.c.

49{
51
52 if (so->sign)
53 pfree(so->sign);
54 so->sign = NULL;
55
56 if (scankey && scan->numberOfKeys > 0)
57 memcpy(scan->keyData, scankey, scan->numberOfKeys * sizeof(ScanKeyData));
58}

References fb(), IndexScanDescData::keyData, IndexScanDescData::numberOfKeys, IndexScanDescData::opaque, and pfree().

Referenced by blhandler().

◆ blvacuumcleanup()

IndexBulkDeleteResult * blvacuumcleanup ( IndexVacuumInfo info,
IndexBulkDeleteResult stats 
)
extern

Definition at line 188 of file blvacuum.c.

189{
190 Relation index = info->index;
191 BlockNumber npages,
192 blkno;
194 ReadStream *stream;
195
196 if (info->analyze_only)
197 return stats;
198
199 if (stats == NULL)
201
202 /*
203 * Iterate over the pages: insert deleted pages into FSM and collect
204 * statistics.
205 */
207 stats->num_pages = npages;
208 stats->pages_free = 0;
209 stats->num_index_tuples = 0;
210
211 /* Scan all blocks except the metapage using streaming reads */
213 p.last_exclusive = npages;
214
215 /*
216 * It is safe to use batchmode as block_range_read_stream_cb takes no
217 * locks.
218 */
222 info->strategy,
223 index,
226 &p,
227 0);
228
229 for (blkno = BLOOM_HEAD_BLKNO; blkno < npages; blkno++)
230 {
231 Buffer buffer;
232 Page page;
233
234 vacuum_delay_point(false);
235
236 buffer = read_stream_next_buffer(stream, NULL);
238 page = BufferGetPage(buffer);
239
240 if (PageIsNew(page) || BloomPageIsDeleted(page))
241 {
243 stats->pages_free++;
244 }
245 else
246 {
248 }
249
250 UnlockReleaseBuffer(buffer);
251 }
252
254 read_stream_end(stream);
255
257
258 return stats;
259}
void IndexFreeSpaceMapVacuum(Relation rel)
Definition indexfsm.c:71
void RecordFreeIndexPage(Relation rel, BlockNumber freeBlock)
Definition indexfsm.c:52
BlockNumber pages_free
Definition genam.h:91
BlockNumber num_pages
Definition genam.h:85
double num_index_tuples
Definition genam.h:87
bool analyze_only
Definition genam.h:56

References IndexVacuumInfo::analyze_only, Assert, block_range_read_stream_cb(), BLOOM_HEAD_BLKNO, BloomPageGetMaxOffset, BloomPageIsDeleted, BUFFER_LOCK_SHARE, BufferGetPage(), BlockRangeReadStreamPrivate::current_blocknum, fb(), IndexVacuumInfo::index, IndexFreeSpaceMapVacuum(), InvalidBuffer, BlockRangeReadStreamPrivate::last_exclusive, LockBuffer(), MAIN_FORKNUM, IndexBulkDeleteResult::num_index_tuples, IndexBulkDeleteResult::num_pages, PageIsNew(), IndexBulkDeleteResult::pages_free, palloc0_object, read_stream_begin_relation(), read_stream_end(), READ_STREAM_FULL, READ_STREAM_MAINTENANCE, read_stream_next_buffer(), READ_STREAM_USE_BATCHING, RecordFreeIndexPage(), RelationGetNumberOfBlocks, IndexVacuumInfo::strategy, UnlockReleaseBuffer(), and vacuum_delay_point().

Referenced by blhandler().

◆ blvalidate()

bool blvalidate ( Oid  opclassoid)
extern

Definition at line 30 of file blvalidate.c.

31{
32 bool result = true;
36 Oid opcintype;
38 char *opclassname;
39 char *opfamilyname;
41 *oprlist;
44 int i;
45 ListCell *lc;
46
47 /* Fetch opclass information */
50 elog(ERROR, "cache lookup failed for operator class %u", opclassoid);
52
53 opfamilyoid = classform->opcfamily;
54 opcintype = classform->opcintype;
55 opckeytype = classform->opckeytype;
57 opckeytype = opcintype;
58 opclassname = NameStr(classform->opcname);
59
60 /* Fetch opfamily information */
61 opfamilyname = get_opfamily_name(opfamilyoid, false);
62
63 /* Fetch all operators and support functions of the opfamily */
66
67 /* Check individual support functions */
68 for (i = 0; i < proclist->n_members; i++)
69 {
70 HeapTuple proctup = &proclist->members[i]->tuple;
72 bool ok;
73
74 /*
75 * All bloom support functions should be registered with matching
76 * left/right types
77 */
78 if (procform->amproclefttype != procform->amprocrighttype)
79 {
82 errmsg("bloom opfamily %s contains support procedure %s with cross-type registration",
83 opfamilyname,
84 format_procedure(procform->amproc))));
85 result = false;
86 }
87
88 /*
89 * We can't check signatures except within the specific opclass, since
90 * we need to know the associated opckeytype in many cases.
91 */
92 if (procform->amproclefttype != opcintype)
93 continue;
94
95 /* Check procedure numbers and function signatures */
96 switch (procform->amprocnum)
97 {
98 case BLOOM_HASH_PROC:
99 ok = check_amproc_signature(procform->amproc, INT4OID, false,
100 1, 1, opckeytype);
101 break;
104 break;
105 default:
108 errmsg("bloom opfamily %s contains function %s with invalid support number %d",
109 opfamilyname,
110 format_procedure(procform->amproc),
111 procform->amprocnum)));
112 result = false;
113 continue; /* don't want additional message */
114 }
115
116 if (!ok)
117 {
120 errmsg("bloom opfamily %s contains function %s with wrong signature for support number %d",
121 opfamilyname,
122 format_procedure(procform->amproc),
123 procform->amprocnum)));
124 result = false;
125 }
126 }
127
128 /* Check individual operators */
129 for (i = 0; i < oprlist->n_members; i++)
130 {
131 HeapTuple oprtup = &oprlist->members[i]->tuple;
133
134 /* Check it's allowed strategy for bloom */
135 if (oprform->amopstrategy < 1 ||
136 oprform->amopstrategy > BLOOM_NSTRATEGIES)
137 {
140 errmsg("bloom opfamily %s contains operator %s with invalid strategy number %d",
141 opfamilyname,
142 format_operator(oprform->amopopr),
143 oprform->amopstrategy)));
144 result = false;
145 }
146
147 /* bloom doesn't support ORDER BY operators */
148 if (oprform->amoppurpose != AMOP_SEARCH ||
149 OidIsValid(oprform->amopsortfamily))
150 {
153 errmsg("bloom opfamily %s contains invalid ORDER BY specification for operator %s",
154 opfamilyname,
155 format_operator(oprform->amopopr))));
156 result = false;
157 }
158
159 /* Check operator signature --- same for all bloom strategies */
160 if (!check_amop_signature(oprform->amopopr, BOOLOID,
161 oprform->amoplefttype,
162 oprform->amoprighttype))
163 {
166 errmsg("bloom opfamily %s contains operator %s with wrong signature",
167 opfamilyname,
168 format_operator(oprform->amopopr))));
169 result = false;
170 }
171 }
172
173 /* Now check for inconsistent groups of operators/functions */
176 foreach(lc, grouplist)
177 {
179
180 /* Remember the group exactly matching the test opclass */
181 if (thisgroup->lefttype == opcintype &&
182 thisgroup->righttype == opcintype)
184
185 /*
186 * There is not a lot we can do to check the operator sets, since each
187 * bloom opclass is more or less a law unto itself, and some contain
188 * only operators that are binary-compatible with the opclass datatype
189 * (meaning that empty operator sets can be OK). That case also means
190 * that we shouldn't insist on nonempty function sets except for the
191 * opclass's own group.
192 */
193 }
194
195 /* Check that the originally-named opclass is complete */
196 for (i = 1; i <= BLOOM_NPROC; i++)
197 {
198 if (opclassgroup &&
199 (opclassgroup->functionset & (((uint64) 1) << i)) != 0)
200 continue; /* got it */
201 if (i == BLOOM_OPTIONS_PROC)
202 continue; /* optional method */
205 errmsg("bloom opclass %s is missing support function %d",
206 opclassname, i)));
207 result = false;
208 }
209
213
214 return result;
215}
bool check_amproc_signature(Oid funcid, Oid restype, bool exact, int minargs, int maxargs,...)
Definition amvalidate.c:152
bool check_amop_signature(Oid opno, Oid restype, Oid lefttype, Oid righttype)
Definition amvalidate.c:206
List * identify_opfamily_groups(CatCList *oprlist, CatCList *proclist)
Definition amvalidate.c:43
bool check_amoptsproc_signature(Oid funcid)
Definition amvalidate.c:192
#define BLOOM_HASH_PROC
Definition bloom.h:24
#define BLOOM_NPROC
Definition bloom.h:26
#define BLOOM_NSTRATEGIES
Definition bloom.h:30
#define BLOOM_OPTIONS_PROC
Definition bloom.h:25
#define NameStr(name)
Definition c.h:837
uint64_t uint64
Definition c.h:619
#define OidIsValid(objectId)
Definition c.h:860
void ReleaseCatCacheList(CatCList *list)
Definition catcache.c:2114
int errcode(int sqlerrcode)
Definition elog.c:874
#define INFO
Definition elog.h:34
#define ereport(elevel,...)
Definition elog.h:150
#define HeapTupleIsValid(tuple)
Definition htup.h:78
static void * GETSTRUCT(const HeapTupleData *tuple)
char * get_opfamily_name(Oid opfid, bool missing_ok)
Definition lsyscache.c:1473
static char * errmsg
END_CATALOG_STRUCT typedef FormData_pg_amop * Form_pg_amop
Definition pg_amop.h:92
END_CATALOG_STRUCT typedef FormData_pg_amproc * Form_pg_amproc
Definition pg_amproc.h:72
#define lfirst(lc)
Definition pg_list.h:172
END_CATALOG_STRUCT typedef FormData_pg_opclass * Form_pg_opclass
Definition pg_opclass.h:87
static Datum ObjectIdGetDatum(Oid X)
Definition postgres.h:252
char * format_procedure(Oid procedure_oid)
Definition regproc.c:305
char * format_operator(Oid operator_oid)
Definition regproc.c:801
Definition pg_list.h:54
void ReleaseSysCache(HeapTuple tuple)
Definition syscache.c:265
HeapTuple SearchSysCache1(SysCacheIdentifier cacheId, Datum key1)
Definition syscache.c:221
#define SearchSysCacheList1(cacheId, key1)
Definition syscache.h:127

References BLOOM_HASH_PROC, BLOOM_NPROC, BLOOM_NSTRATEGIES, BLOOM_OPTIONS_PROC, check_amop_signature(), check_amoptsproc_signature(), check_amproc_signature(), elog, ereport, errcode(), errmsg, ERROR, fb(), Form_pg_amop, Form_pg_amproc, Form_pg_opclass, format_operator(), format_procedure(), get_opfamily_name(), GETSTRUCT(), HeapTupleIsValid, i, identify_opfamily_groups(), INFO, lfirst, NameStr, ObjectIdGetDatum(), OidIsValid, ReleaseCatCacheList(), ReleaseSysCache(), SearchSysCache1(), and SearchSysCacheList1.

Referenced by blhandler().

◆ initBloomState()

void initBloomState ( BloomState state,
Relation  index 
)
extern

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 BloomPageIsMeta(page)
Definition bloom.h:62
void fmgr_info_copy(FmgrInfo *dstinfo, FmgrInfo *srcinfo, MemoryContext destcxt)
Definition fmgr.c:582
FmgrInfo * index_getprocinfo(Relation irel, AttrNumber attnum, uint16 procnum)
Definition indexam.c:918
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition mcxt.c:1232
BloomOptions opts
Definition bloom.h:123
uint32 magickNumber
Definition bloom.h:120

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

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

◆ signValue()

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

Definition at line 266 of file blutils.c.

267{
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));
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:618
Datum FunctionCall1Coll(FmgrInfo *flinfo, Oid collation, Datum arg1)
Definition fmgr.c:1131
int j
Definition isn.c:78
static int32 DatumGetInt32(Datum X)
Definition postgres.h:202

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

Referenced by blgetbitmap(), and BloomFormTuple().