PostgreSQL Source Code git master
Loading...
Searching...
No Matches
blscan.c File Reference
#include "postgres.h"
#include "access/relscan.h"
#include "bloom.h"
#include "executor/instrument_node.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "storage/bufmgr.h"
Include dependency graph for blscan.c:

Go to the source code of this file.

Functions

IndexScanDesc blbeginscan (Relation r, int nkeys, int norderbys)
 
void blrescan (IndexScanDesc scan, ScanKey scankey, int nscankeys, ScanKey orderbys, int norderbys)
 
void blendscan (IndexScanDesc scan)
 
int64 blgetbitmap (IndexScanDesc scan, TIDBitmap *tbm)
 

Function Documentation

◆ blbeginscan()

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

Definition at line 26 of file blscan.c.

27{
28 IndexScanDesc scan;
30
31 scan = RelationGetIndexScan(r, nkeys, norderbys);
32
34 initBloomState(&so->state, scan->indexRelation);
35 so->sign = NULL;
36
37 scan->opaque = so;
38
39 return scan;
40}
void initBloomState(BloomState *state, Relation index)
Definition blutils.c:167
BloomScanOpaqueData * BloomScanOpaque
Definition bloom.h:172
#define palloc_object(type)
Definition fe_memutils.h:74
IndexScanDesc RelationGetIndexScan(Relation indexRelation, int nkeys, int norderbys)
Definition genam.c:80
static int fb(int x)
Relation indexRelation
Definition relscan.h:138

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

Referenced by blhandler().

◆ blendscan()

void blendscan ( IndexScanDesc  scan)

Definition at line 63 of file blscan.c.

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

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

Referenced by blhandler().

◆ blgetbitmap()

int64 blgetbitmap ( IndexScanDesc  scan,
TIDBitmap tbm 
)

Definition at line 76 of file blscan.c.

77{
78 int64 ntids = 0;
80 npages;
81 int i;
84
85 if (so->sign == NULL)
86 {
87 /* New search: have to calculate search signature */
88 ScanKey skey = scan->keyData;
89
90 so->sign = palloc0_array(BloomSignatureWord, so->state.opts.bloomLength);
91
92 for (i = 0; i < scan->numberOfKeys; i++)
93 {
94 /*
95 * Assume bloom-indexable operators to be strict, so nothing could
96 * be found for NULL key.
97 */
98 if (skey->sk_flags & SK_ISNULL)
99 {
100 pfree(so->sign);
101 so->sign = NULL;
102 return 0;
103 }
104
105 /* Add next value to the signature */
106 signValue(&so->state, so->sign, skey->sk_argument,
107 skey->sk_attno - 1);
108
109 skey++;
110 }
111 }
112
113 /*
114 * We're going to read the whole index. This is why we use appropriate
115 * buffer access strategy.
116 */
120 if (scan->instrument)
121 scan->instrument->nsearches++;
122
123 for (blkno = BLOOM_HEAD_BLKNO; blkno < npages; blkno++)
124 {
125 Buffer buffer;
126 Page page;
127
129 blkno, RBM_NORMAL, bas);
130
132 page = BufferGetPage(buffer);
133
134 if (!PageIsNew(page) && !BloomPageIsDeleted(page))
135 {
136 OffsetNumber offset,
138
139 for (offset = 1; offset <= maxOffset; offset++)
140 {
141 BloomTuple *itup = BloomPageGetTuple(&so->state, page, offset);
142 bool res = true;
143
144 /* Check index signature with scan signature */
145 for (i = 0; i < so->state.opts.bloomLength; i++)
146 {
147 if ((itup->sign[i] & so->sign[i]) != so->sign[i])
148 {
149 res = false;
150 break;
151 }
152 }
153
154 /* Add matching tuples to bitmap */
155 if (res)
156 {
157 tbm_add_tuples(tbm, &itup->heapPtr, 1, true);
158 ntids++;
159 }
160 }
161 }
162
163 UnlockReleaseBuffer(buffer);
165 }
167
168 return ntids;
169}
uint32 BlockNumber
Definition block.h:31
#define BloomPageGetMaxOffset(page)
Definition bloom.h:61
#define BloomPageGetTuple(state, page, offset)
Definition bloom.h:71
uint16 BloomSignatureWord
Definition bloom.h:84
void signValue(BloomState *state, BloomSignatureWord *sign, Datum value, int attno)
Definition blutils.c:266
#define BloomPageIsDeleted(page)
Definition bloom.h:64
#define BLOOM_HEAD_BLKNO
Definition bloom.h:79
int Buffer
Definition buf.h:23
void UnlockReleaseBuffer(Buffer buffer)
Definition bufmgr.c:5518
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Definition bufmgr.c:911
@ BAS_BULKREAD
Definition bufmgr.h:37
#define RelationGetNumberOfBlocks(reln)
Definition bufmgr.h:307
static Page BufferGetPage(Buffer buffer)
Definition bufmgr.h:466
@ BUFFER_LOCK_SHARE
Definition bufmgr.h:210
static void LockBuffer(Buffer buffer, BufferLockMode mode)
Definition bufmgr.h:328
@ RBM_NORMAL
Definition bufmgr.h:46
static bool PageIsNew(const PageData *page)
Definition bufpage.h:233
PageData * Page
Definition bufpage.h:81
int64_t int64
Definition c.h:543
#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:705
@ MAIN_FORKNUM
Definition relpath.h:58
#define SK_ISNULL
Definition skey.h:115
BloomSignatureWord sign[FLEXIBLE_ARRAY_MEMBER]
Definition bloom.h:160
ItemPointerData heapPtr
Definition bloom.h:159
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 BAS_BULKREAD, BLOOM_HEAD_BLKNO, BloomPageGetMaxOffset, BloomPageGetTuple, BloomPageIsDeleted, BUFFER_LOCK_SHARE, BufferGetPage(), CHECK_FOR_INTERRUPTS, fb(), FreeAccessStrategy(), GetAccessStrategy(), BloomTuple::heapPtr, i, IndexScanDescData::indexRelation, IndexScanDescData::instrument, IndexScanDescData::keyData, LockBuffer(), MAIN_FORKNUM, IndexScanInstrumentation::nsearches, IndexScanDescData::numberOfKeys, IndexScanDescData::opaque, PageIsNew(), palloc0_array, pfree(), pgstat_count_index_scan, RBM_NORMAL, ReadBufferExtended(), RelationGetNumberOfBlocks, BloomTuple::sign, signValue(), SK_ISNULL, tbm_add_tuples(), and UnlockReleaseBuffer().

Referenced by blhandler().

◆ blrescan()

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

Definition at line 46 of file blscan.c.

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

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

Referenced by blhandler().