PostgreSQL Source Code git master
Loading...
Searching...
No Matches
nodeBitmapHeapscan.c File Reference
#include "postgres.h"
#include "access/relscan.h"
#include "access/tableam.h"
#include "access/visibilitymap.h"
#include "executor/executor.h"
#include "executor/instrument.h"
#include "executor/nodeBitmapHeapscan.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "storage/bufmgr.h"
#include "storage/condition_variable.h"
#include "utils/dsa.h"
#include "utils/rel.h"
#include "utils/spccache.h"
#include "utils/wait_event.h"
Include dependency graph for nodeBitmapHeapscan.c:

Go to the source code of this file.

Data Structures

struct  ParallelBitmapHeapState
 

Typedefs

typedef struct ParallelBitmapHeapState ParallelBitmapHeapState
 

Enumerations

enum  SharedBitmapState { BM_INITIAL , BM_INPROGRESS , BM_FINISHED }
 

Functions

static void BitmapTableScanSetup (BitmapHeapScanState *node)
 
static TupleTableSlotBitmapHeapNext (BitmapHeapScanState *node)
 
static void BitmapDoneInitializingSharedState (ParallelBitmapHeapState *pstate)
 
static bool BitmapShouldInitializeSharedState (ParallelBitmapHeapState *pstate)
 
static bool BitmapHeapRecheck (BitmapHeapScanState *node, TupleTableSlot *slot)
 
static TupleTableSlotExecBitmapHeapScan (PlanState *pstate)
 
void ExecReScanBitmapHeapScan (BitmapHeapScanState *node)
 
void ExecEndBitmapHeapScan (BitmapHeapScanState *node)
 
BitmapHeapScanStateExecInitBitmapHeapScan (BitmapHeapScan *node, EState *estate, int eflags)
 
void ExecBitmapHeapEstimate (BitmapHeapScanState *node, ParallelContext *pcxt)
 
void ExecBitmapHeapInitializeDSM (BitmapHeapScanState *node, ParallelContext *pcxt)
 
void ExecBitmapHeapReInitializeDSM (BitmapHeapScanState *node, ParallelContext *pcxt)
 
void ExecBitmapHeapInitializeWorker (BitmapHeapScanState *node, ParallelWorkerContext *pwcxt)
 
void ExecBitmapHeapInstrumentEstimate (BitmapHeapScanState *node, ParallelContext *pcxt)
 
void ExecBitmapHeapInstrumentInitDSM (BitmapHeapScanState *node, ParallelContext *pcxt)
 
void ExecBitmapHeapInstrumentInitWorker (BitmapHeapScanState *node, ParallelWorkerContext *pwcxt)
 
void ExecBitmapHeapRetrieveInstrumentation (BitmapHeapScanState *node)
 

Typedef Documentation

◆ ParallelBitmapHeapState

Enumeration Type Documentation

◆ SharedBitmapState

Enumerator
BM_INITIAL 
BM_INPROGRESS 
BM_FINISHED 

Definition at line 72 of file nodeBitmapHeapscan.c.

73{
SharedBitmapState
@ BM_INITIAL
@ BM_FINISHED
@ BM_INPROGRESS

Function Documentation

◆ BitmapDoneInitializingSharedState()

static void BitmapDoneInitializingSharedState ( ParallelBitmapHeapState pstate)
inlinestatic

Definition at line 229 of file nodeBitmapHeapscan.c.

230{
231 SpinLockAcquire(&pstate->mutex);
232 pstate->state = BM_FINISHED;
233 SpinLockRelease(&pstate->mutex);
235}
void ConditionVariableBroadcast(ConditionVariable *cv)
static void SpinLockRelease(volatile slock_t *lock)
Definition spin.h:62
static void SpinLockAcquire(volatile slock_t *lock)
Definition spin.h:56

References BM_FINISHED, ConditionVariableBroadcast(), ParallelBitmapHeapState::cv, ParallelBitmapHeapState::mutex, SpinLockAcquire(), SpinLockRelease(), and ParallelBitmapHeapState::state.

Referenced by BitmapTableScanSetup().

◆ BitmapHeapNext()

static TupleTableSlot * BitmapHeapNext ( BitmapHeapScanState node)
static

Definition at line 174 of file nodeBitmapHeapscan.c.

175{
176 ExprContext *econtext = node->ss.ps.ps_ExprContext;
177 TupleTableSlot *slot = node->ss.ss_ScanTupleSlot;
178
179 /*
180 * If we haven't yet performed the underlying index scan, do it, and begin
181 * the iteration over the bitmap.
182 */
183 if (!node->initialized)
185
187 slot, &node->recheck,
188 &node->stats.lossy_pages,
189 &node->stats.exact_pages))
190 {
191 /*
192 * Continuing in previously obtained page.
193 */
195
196 /*
197 * If we are using lossy info, we have to recheck the qual conditions
198 * at every tuple.
199 */
200 if (node->recheck)
201 {
202 econtext->ecxt_scantuple = slot;
203 if (!ExecQualAndReset(node->bitmapqualorig, econtext))
204 {
205 /* Fails recheck, so drop it and loop back for another */
206 InstrCountFiltered2(node, 1);
207 ExecClearTuple(slot);
208 continue;
209 }
210 }
211
212 /* OK to return this tuple */
213 return slot;
214 }
215
216 /*
217 * if we get here it means we are at the end of the scan..
218 */
219 return ExecClearTuple(slot);
220}
#define InstrCountFiltered2(node, delta)
Definition execnodes.h:1312
static bool ExecQualAndReset(ExprState *state, ExprContext *econtext)
Definition executor.h:556
#define CHECK_FOR_INTERRUPTS()
Definition miscadmin.h:125
static void BitmapTableScanSetup(BitmapHeapScanState *node)
ExprState * bitmapqualorig
Definition execnodes.h:1878
BitmapHeapScanInstrumentation stats
Definition execnodes.h:1880
TupleTableSlot * ecxt_scantuple
Definition execnodes.h:287
ExprContext * ps_ExprContext
Definition execnodes.h:1242
TupleTableSlot * ss_ScanTupleSlot
Definition execnodes.h:1662
PlanState ps
Definition execnodes.h:1659
struct TableScanDescData * ss_currentScanDesc
Definition execnodes.h:1661
static bool table_scan_bitmap_next_tuple(TableScanDesc scan, TupleTableSlot *slot, bool *recheck, uint64 *lossy_pages, uint64 *exact_pages)
Definition tableam.h:2037
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition tuptable.h:476

References BitmapHeapScanState::bitmapqualorig, BitmapTableScanSetup(), CHECK_FOR_INTERRUPTS, ExprContext::ecxt_scantuple, BitmapHeapScanInstrumentation::exact_pages, ExecClearTuple(), ExecQualAndReset(), BitmapHeapScanState::initialized, InstrCountFiltered2, BitmapHeapScanInstrumentation::lossy_pages, ScanState::ps, PlanState::ps_ExprContext, BitmapHeapScanState::recheck, BitmapHeapScanState::ss, ScanState::ss_currentScanDesc, ScanState::ss_ScanTupleSlot, BitmapHeapScanState::stats, and table_scan_bitmap_next_tuple().

Referenced by ExecBitmapHeapScan().

◆ BitmapHeapRecheck()

static bool BitmapHeapRecheck ( BitmapHeapScanState node,
TupleTableSlot slot 
)
static

Definition at line 241 of file nodeBitmapHeapscan.c.

242{
243 ExprContext *econtext;
244
245 /*
246 * extract necessary information from index scan node
247 */
248 econtext = node->ss.ps.ps_ExprContext;
249
250 /* Does the tuple meet the original qual conditions? */
251 econtext->ecxt_scantuple = slot;
252 return ExecQualAndReset(node->bitmapqualorig, econtext);
253}

References BitmapHeapScanState::bitmapqualorig, ExprContext::ecxt_scantuple, ExecQualAndReset(), ScanState::ps, PlanState::ps_ExprContext, and BitmapHeapScanState::ss.

Referenced by ExecBitmapHeapScan().

◆ BitmapShouldInitializeSharedState()

static bool BitmapShouldInitializeSharedState ( ParallelBitmapHeapState pstate)
static

Definition at line 477 of file nodeBitmapHeapscan.c.

478{
480
481 while (1)
482 {
483 SpinLockAcquire(&pstate->mutex);
484 state = pstate->state;
485 if (pstate->state == BM_INITIAL)
486 pstate->state = BM_INPROGRESS;
487 SpinLockRelease(&pstate->mutex);
488
489 /* Exit if bitmap is done, or if we're the leader. */
490 if (state != BM_INPROGRESS)
491 break;
492
493 /* Wait for the leader to wake us up. */
495 }
496
498
499 return (state == BM_INITIAL);
500}
bool ConditionVariableCancelSleep(void)
void ConditionVariableSleep(ConditionVariable *cv, uint32 wait_event_info)
static int fb(int x)

References BM_INITIAL, BM_INPROGRESS, ConditionVariableCancelSleep(), ConditionVariableSleep(), ParallelBitmapHeapState::cv, fb(), ParallelBitmapHeapState::mutex, SpinLockAcquire(), SpinLockRelease(), and ParallelBitmapHeapState::state.

Referenced by BitmapTableScanSetup().

◆ BitmapTableScanSetup()

static void BitmapTableScanSetup ( BitmapHeapScanState node)
static

Definition at line 102 of file nodeBitmapHeapscan.c.

103{
104 TBMIterator tbmiterator = {0};
105 ParallelBitmapHeapState *pstate = node->pstate;
106 dsa_area *dsa = node->ss.ps.state->es_query_dsa;
107
108 if (!pstate)
109 {
111
112 if (!node->tbm || !IsA(node->tbm, TIDBitmap))
113 elog(ERROR, "unrecognized result from subplan");
114 }
115 else if (BitmapShouldInitializeSharedState(pstate))
116 {
117 /*
118 * The leader will immediately come out of the function, but others
119 * will be blocked until leader populates the TBM and wakes them up.
120 */
122 if (!node->tbm || !IsA(node->tbm, TIDBitmap))
123 elog(ERROR, "unrecognized result from subplan");
124
125 /*
126 * Prepare to iterate over the TBM. This will return the dsa_pointer
127 * of the iterator state which will be used by multiple processes to
128 * iterate jointly.
129 */
131
132 /* We have initialized the shared state so wake up others. */
134 }
135
136 tbmiterator = tbm_begin_iterate(node->tbm, dsa,
137 pstate ?
138 pstate->tbmiterator :
140
141 /*
142 * If this is the first scan of the underlying table, create the table
143 * scan descriptor and begin the scan.
144 */
145 if (!node->ss.ss_currentScanDesc)
146 {
147 uint32 flags = SO_NONE;
148
149 if (ScanRelIsReadOnly(&node->ss))
150 flags |= SO_HINT_REL_READ_ONLY;
151
153 flags |= SO_SCAN_INSTRUMENT;
154
155 node->ss.ss_currentScanDesc =
157 node->ss.ps.state->es_snapshot,
158 0,
159 NULL,
160 flags);
161 }
162
163 node->ss.ss_currentScanDesc->st.rs_tbmiterator = tbmiterator;
164 node->initialized = true;
165}
uint32_t uint32
Definition c.h:624
#define InvalidDsaPointer
Definition dsa.h:78
#define ERROR
Definition elog.h:40
#define elog(elevel,...)
Definition elog.h:228
Node * MultiExecProcNode(PlanState *node)
bool ScanRelIsReadOnly(ScanState *ss)
Definition execUtils.c:751
#define outerPlanState(node)
Definition execnodes.h:1299
@ INSTRUMENT_IO
Definition instrument.h:67
static bool BitmapShouldInitializeSharedState(ParallelBitmapHeapState *pstate)
static void BitmapDoneInitializingSharedState(ParallelBitmapHeapState *pstate)
#define IsA(nodeptr, _type_)
Definition nodes.h:164
ParallelBitmapHeapState * pstate
Definition execnodes.h:1882
struct dsa_area * es_query_dsa
Definition execnodes.h:788
int es_instrument
Definition execnodes.h:756
Snapshot es_snapshot
Definition execnodes.h:696
EState * state
Definition execnodes.h:1203
Relation ss_currentRelation
Definition execnodes.h:1660
TBMIterator rs_tbmiterator
Definition relscan.h:47
union TableScanDescData::@55 st
@ SO_HINT_REL_READ_ONLY
Definition tableam.h:71
@ SO_NONE
Definition tableam.h:49
@ SO_SCAN_INSTRUMENT
Definition tableam.h:74
static TableScanDesc table_beginscan_bm(Relation rel, Snapshot snapshot, int nkeys, ScanKeyData *key, uint32 flags)
Definition tableam.h:992
dsa_pointer tbm_prepare_shared_iterate(TIDBitmap *tbm)
Definition tidbitmap.c:752
TBMIterator tbm_begin_iterate(TIDBitmap *tbm, dsa_area *dsa, dsa_pointer dsp)
Definition tidbitmap.c:1571

References BitmapDoneInitializingSharedState(), BitmapShouldInitializeSharedState(), elog, ERROR, EState::es_instrument, EState::es_query_dsa, EState::es_snapshot, fb(), BitmapHeapScanState::initialized, INSTRUMENT_IO, InvalidDsaPointer, IsA, MultiExecProcNode(), outerPlanState, ScanState::ps, BitmapHeapScanState::pstate, TableScanDescData::rs_tbmiterator, ScanRelIsReadOnly(), SO_HINT_REL_READ_ONLY, SO_NONE, SO_SCAN_INSTRUMENT, BitmapHeapScanState::ss, ScanState::ss_currentRelation, ScanState::ss_currentScanDesc, TableScanDescData::st, PlanState::state, table_beginscan_bm(), BitmapHeapScanState::tbm, tbm_begin_iterate(), tbm_prepare_shared_iterate(), and ParallelBitmapHeapState::tbmiterator.

Referenced by BitmapHeapNext().

◆ ExecBitmapHeapEstimate()

void ExecBitmapHeapEstimate ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 510 of file nodeBitmapHeapscan.c.

512{
516}
#define MAXALIGN(LEN)
Definition c.h:896
#define shm_toc_estimate_chunk(e, sz)
Definition shm_toc.h:51
#define shm_toc_estimate_keys(e, cnt)
Definition shm_toc.h:53
shm_toc_estimator estimator
Definition parallel.h:43

References ParallelContext::estimator, MAXALIGN, shm_toc_estimate_chunk, and shm_toc_estimate_keys.

Referenced by ExecParallelEstimate().

◆ ExecBitmapHeapInitializeDSM()

void ExecBitmapHeapInitializeDSM ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 525 of file nodeBitmapHeapscan.c.

527{
529 dsa_area *dsa = node->ss.ps.state->es_query_dsa;
530
531 /* If there's no DSA, there are no workers; initialize nothing. */
532 if (dsa == NULL)
533 return;
534
535 pstate = (ParallelBitmapHeapState *)
536 shm_toc_allocate(pcxt->toc,
538
539 pstate->tbmiterator = 0;
540
541 /* Initialize the mutex */
542 SpinLockInit(&pstate->mutex);
543 pstate->state = BM_INITIAL;
544
545 ConditionVariableInit(&pstate->cv);
546
547 shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pstate);
548 node->pstate = pstate;
549}
void ConditionVariableInit(ConditionVariable *cv)
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition shm_toc.c:88
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition shm_toc.c:171
static void SpinLockInit(volatile slock_t *lock)
Definition spin.h:50
shm_toc * toc
Definition parallel.h:46
Plan * plan
Definition execnodes.h:1201
int plan_node_id
Definition plannodes.h:233

References BM_INITIAL, ConditionVariableInit(), ParallelBitmapHeapState::cv, EState::es_query_dsa, fb(), MAXALIGN, ParallelBitmapHeapState::mutex, PlanState::plan, Plan::plan_node_id, ScanState::ps, BitmapHeapScanState::pstate, shm_toc_allocate(), shm_toc_insert(), SpinLockInit(), BitmapHeapScanState::ss, ParallelBitmapHeapState::state, PlanState::state, ParallelBitmapHeapState::tbmiterator, and ParallelContext::toc.

Referenced by ExecParallelInitializeDSM().

◆ ExecBitmapHeapInitializeWorker()

void ExecBitmapHeapInitializeWorker ( BitmapHeapScanState node,
ParallelWorkerContext pwcxt 
)

Definition at line 583 of file nodeBitmapHeapscan.c.

585{
586 Assert(node->ss.ps.state->es_query_dsa != NULL);
587
589 shm_toc_lookup(pwcxt->toc, node->ss.ps.plan->plan_node_id, false);
590}
#define Assert(condition)
Definition c.h:943
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition shm_toc.c:239

References Assert, EState::es_query_dsa, fb(), PlanState::plan, Plan::plan_node_id, ScanState::ps, BitmapHeapScanState::pstate, shm_toc_lookup(), BitmapHeapScanState::ss, and PlanState::state.

Referenced by ExecParallelInitializeWorker().

◆ ExecBitmapHeapInstrumentEstimate()

void ExecBitmapHeapInstrumentEstimate ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 597 of file nodeBitmapHeapscan.c.

599{
600 Size size;
601
602 if (!node->ss.ps.instrument || pcxt->nworkers == 0)
603 return;
604
607 shm_toc_estimate_chunk(&pcxt->estimator, size);
609}
size_t Size
Definition c.h:689
Size add_size(Size s1, Size s2)
Definition shmem.c:1048
Size mul_size(Size s1, Size s2)
Definition shmem.c:1063
NodeInstrumentation * instrument
Definition execnodes.h:1211

References add_size(), ParallelContext::estimator, fb(), PlanState::instrument, mul_size(), ParallelContext::nworkers, ScanState::ps, shm_toc_estimate_chunk, shm_toc_estimate_keys, and BitmapHeapScanState::ss.

Referenced by ExecParallelEstimate().

◆ ExecBitmapHeapInstrumentInitDSM()

void ExecBitmapHeapInstrumentInitDSM ( BitmapHeapScanState node,
ParallelContext pcxt 
)

◆ ExecBitmapHeapInstrumentInitWorker()

◆ ExecBitmapHeapReInitializeDSM()

void ExecBitmapHeapReInitializeDSM ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 558 of file nodeBitmapHeapscan.c.

560{
561 ParallelBitmapHeapState *pstate = node->pstate;
562 dsa_area *dsa = node->ss.ps.state->es_query_dsa;
563
564 /* If there's no DSA, there are no workers; do nothing. */
565 if (dsa == NULL)
566 return;
567
568 pstate->state = BM_INITIAL;
569
570 if (DsaPointerIsValid(pstate->tbmiterator))
571 tbm_free_shared_area(dsa, pstate->tbmiterator);
572
574}
#define DsaPointerIsValid(x)
Definition dsa.h:106
void tbm_free_shared_area(dsa_area *dsa, dsa_pointer dp)
Definition tidbitmap.c:331

References BM_INITIAL, DsaPointerIsValid, EState::es_query_dsa, fb(), InvalidDsaPointer, ScanState::ps, BitmapHeapScanState::pstate, BitmapHeapScanState::ss, ParallelBitmapHeapState::state, PlanState::state, tbm_free_shared_area(), and ParallelBitmapHeapState::tbmiterator.

Referenced by ExecParallelReInitializeDSM().

◆ ExecBitmapHeapRetrieveInstrumentation()

void ExecBitmapHeapRetrieveInstrumentation ( BitmapHeapScanState node)

Definition at line 661 of file nodeBitmapHeapscan.c.

662{
663 SharedBitmapHeapInstrumentation *sinstrument = node->sinstrument;
664 Size size;
665
666 if (sinstrument == NULL)
667 return;
668
669 size = offsetof(SharedBitmapHeapInstrumentation, sinstrument)
670 + sinstrument->num_workers * sizeof(BitmapHeapScanInstrumentation);
671
672 node->sinstrument = palloc(size);
673 memcpy(node->sinstrument, sinstrument, size);
674}
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
void * palloc(Size size)
Definition mcxt.c:1387

References fb(), memcpy(), SharedBitmapHeapInstrumentation::num_workers, palloc(), and BitmapHeapScanState::sinstrument.

Referenced by ExecParallelRetrieveInstrumentation().

◆ ExecBitmapHeapScan()

static TupleTableSlot * ExecBitmapHeapScan ( PlanState pstate)
static

Definition at line 260 of file nodeBitmapHeapscan.c.

261{
263
264 return ExecScan(&node->ss,
267}
TupleTableSlot * ExecScan(ScanState *node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd)
Definition execScan.c:47
bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)
Definition executor.h:590
TupleTableSlot *(* ExecScanAccessMtd)(ScanState *node)
Definition executor.h:589
static TupleTableSlot * BitmapHeapNext(BitmapHeapScanState *node)
static bool BitmapHeapRecheck(BitmapHeapScanState *node, TupleTableSlot *slot)
#define castNode(_type_, nodeptr)
Definition nodes.h:182

References BitmapHeapNext(), BitmapHeapRecheck(), castNode, ExecScan(), and BitmapHeapScanState::ss.

Referenced by ExecInitBitmapHeapScan().

◆ ExecEndBitmapHeapScan()

void ExecEndBitmapHeapScan ( BitmapHeapScanState node)

Definition at line 315 of file nodeBitmapHeapscan.c.

316{
318
319 /*
320 * When ending a parallel worker, copy the statistics gathered by the
321 * worker back into shared memory so that it can be picked up by the main
322 * process to report in EXPLAIN ANALYZE.
323 */
324 if (node->sinstrument != NULL && IsParallelWorker())
325 {
327
328 Assert(ParallelWorkerNumber < node->sinstrument->num_workers);
330
331 /*
332 * Here we accumulate the stats rather than performing memcpy on
333 * node->stats into si. When a Gather/GatherMerge node finishes it
334 * will perform planner shutdown on the workers. On rescan it will
335 * spin up new workers which will have a new BitmapHeapScanState and
336 * zeroed stats.
337 */
339 si->lossy_pages += node->stats.lossy_pages;
340
341 /* collect I/O instrumentation for this process */
342 if (node->ss.ss_currentScanDesc &&
344 {
345 AccumulateIOStats(&si->stats.io,
347 }
348 }
349
350 /*
351 * extract information from the node
352 */
354
355 /*
356 * close down subplans
357 */
359
360 if (scanDesc)
361 {
362 /*
363 * End iteration on iterators saved in scan descriptor if they have
364 * not already been cleaned up.
365 */
366 if (!tbm_exhausted(&scanDesc->st.rs_tbmiterator))
367 tbm_end_iterate(&scanDesc->st.rs_tbmiterator);
368
369 /*
370 * close table scan
371 */
373 }
374
375 /*
376 * release bitmaps and buffers if any
377 */
378 if (node->tbm)
379 tbm_free(node->tbm);
380}
int ParallelWorkerNumber
Definition parallel.c:117
void ExecEndNode(PlanState *node)
#define IsParallelWorker()
Definition parallel.h:62
static void AccumulateIOStats(IOStats *dst, IOStats *src)
BitmapHeapScanInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER]
struct TableScanInstrumentation * rs_instrument
Definition relscan.h:72
static void table_endscan(TableScanDesc scan)
Definition tableam.h:1061
void tbm_free(TIDBitmap *tbm)
Definition tidbitmap.c:312
void tbm_end_iterate(TBMIterator *iterator)
Definition tidbitmap.c:1594
static bool tbm_exhausted(TBMIterator *iterator)
Definition tidbitmap.h:118

References AccumulateIOStats(), Assert, BitmapHeapScanInstrumentation::exact_pages, ExecEndNode(), fb(), TableScanInstrumentation::io, IsParallelWorker, BitmapHeapScanInstrumentation::lossy_pages, outerPlanState, ParallelWorkerNumber, TableScanDescData::rs_instrument, SharedBitmapHeapInstrumentation::sinstrument, BitmapHeapScanState::sinstrument, BitmapHeapScanState::ss, ScanState::ss_currentScanDesc, BitmapHeapScanState::stats, table_endscan(), BitmapHeapScanState::tbm, tbm_end_iterate(), tbm_exhausted(), and tbm_free().

Referenced by ExecEndNode().

◆ ExecInitBitmapHeapScan()

BitmapHeapScanState * ExecInitBitmapHeapScan ( BitmapHeapScan node,
EState estate,
int  eflags 
)

Definition at line 389 of file nodeBitmapHeapscan.c.

390{
393
394 /* check for unsupported flags */
396
397 /*
398 * Assert caller didn't ask for an unsafe snapshot --- see comments at
399 * head of file.
400 */
402
403 /*
404 * create state structure
405 */
407 scanstate->ss.ps.plan = (Plan *) node;
408 scanstate->ss.ps.state = estate;
409 scanstate->ss.ps.ExecProcNode = ExecBitmapHeapScan;
410
411 scanstate->tbm = NULL;
412
413 /* Zero the statistics counters */
415
416 scanstate->initialized = false;
417 scanstate->pstate = NULL;
418 scanstate->recheck = true;
419
420 /*
421 * Miscellaneous initialization
422 *
423 * create expression context for node
424 */
425 ExecAssignExprContext(estate, &scanstate->ss.ps);
426
427 /*
428 * open the scan relation
429 */
430 currentRelation = ExecOpenScanRelation(estate, node->scan.scanrelid, eflags);
431
432 /*
433 * initialize child nodes
434 */
435 outerPlanState(scanstate) = ExecInitNode(outerPlan(node), estate, eflags);
436
437 /*
438 * get the scan type from the relation descriptor.
439 */
440 ExecInitScanTupleSlot(estate, &scanstate->ss,
444
445 /*
446 * Initialize result type and projection.
447 */
450
451 /*
452 * initialize child expressions
453 */
454 scanstate->ss.ps.qual =
455 ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
456 scanstate->bitmapqualorig =
458
459 scanstate->ss.ss_currentRelation = currentRelation;
460
461 /*
462 * all done.
463 */
464 return scanstate;
465}
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition execExpr.c:250
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
void ExecAssignScanProjectionInfo(ScanState *node)
Definition execScan.c:81
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops, uint16 flags)
void ExecInitResultTypeTL(PlanState *planstate)
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition execUtils.c:490
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition execUtils.c:768
#define EXEC_FLAG_BACKWARD
Definition executor.h:70
#define EXEC_FLAG_MARK
Definition executor.h:71
static TupleTableSlot * ExecBitmapHeapScan(PlanState *pstate)
#define makeNode(_type_)
Definition nodes.h:161
#define outerPlan(node)
Definition plannodes.h:267
#define RelationGetDescr(relation)
Definition rel.h:542
#define IsMVCCSnapshot(snapshot)
Definition snapmgr.h:59
List * bitmapqualorig
Definition plannodes.h:714
Index scanrelid
Definition plannodes.h:544
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition tableam.c:59
#define TTS_FLAG_OBEYS_NOT_NULL_CONSTRAINTS
Definition tuptable.h:102

References Assert, BitmapHeapScan::bitmapqualorig, EState::es_snapshot, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecAssignScanProjectionInfo(), ExecBitmapHeapScan(), ExecInitNode(), ExecInitQual(), ExecInitResultTypeTL(), ExecInitScanTupleSlot(), ExecOpenScanRelation(), fb(), IsMVCCSnapshot, makeNode, outerPlan, outerPlanState, RelationGetDescr, BitmapHeapScan::scan, Scan::scanrelid, table_slot_callbacks(), and TTS_FLAG_OBEYS_NOT_NULL_CONSTRAINTS.

Referenced by ExecInitNode().

◆ ExecReScanBitmapHeapScan()

void ExecReScanBitmapHeapScan ( BitmapHeapScanState node)

Definition at line 274 of file nodeBitmapHeapscan.c.

275{
277
279
280 if (scan)
281 {
282 /*
283 * End iteration on iterators saved in scan descriptor if they have
284 * not already been cleaned up.
285 */
286 if (!tbm_exhausted(&scan->st.rs_tbmiterator))
288
289 /* rescan to release any page pin */
291 }
292
293 /* release bitmaps and buffers if any */
294 if (node->tbm)
295 tbm_free(node->tbm);
296 node->tbm = NULL;
297 node->initialized = false;
298 node->recheck = true;
299
300 ExecScanReScan(&node->ss);
301
302 /*
303 * if chgParam of subnode is not null then plan will be re-scanned by
304 * first ExecProcNode.
305 */
306 if (outerPlan->chgParam == NULL)
308}
void ExecReScan(PlanState *node)
Definition execAmi.c:78
void ExecScanReScan(ScanState *node)
Definition execScan.c:108
static void table_rescan(TableScanDesc scan, ScanKeyData *key)
Definition tableam.h:1070

References ExecReScan(), ExecScanReScan(), fb(), BitmapHeapScanState::initialized, outerPlan, outerPlanState, BitmapHeapScanState::recheck, TableScanDescData::rs_tbmiterator, BitmapHeapScanState::ss, ScanState::ss_currentScanDesc, TableScanDescData::st, table_rescan(), BitmapHeapScanState::tbm, tbm_end_iterate(), tbm_exhausted(), and tbm_free().

Referenced by ExecReScan().