PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
nodeBitmapHeapscan.c File Reference
#include "postgres.h"
#include <math.h>
#include "access/relscan.h"
#include "access/tableam.h"
#include "access/visibilitymap.h"
#include "executor/executor.h"
#include "executor/nodeBitmapHeapscan.h"
#include "miscadmin.h"
#include "pgstat.h"
#include "storage/bufmgr.h"
#include "utils/rel.h"
#include "utils/spccache.h"
Include dependency graph for nodeBitmapHeapscan.c:

Go to the source code of this file.

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 ExecBitmapHeapRetrieveInstrumentation (BitmapHeapScanState *node)
 

Function Documentation

◆ BitmapDoneInitializingSharedState()

static void BitmapDoneInitializingSharedState ( ParallelBitmapHeapState pstate)
inlinestatic

Definition at line 181 of file nodeBitmapHeapscan.c.

182{
183 SpinLockAcquire(&pstate->mutex);
184 pstate->state = BM_FINISHED;
185 SpinLockRelease(&pstate->mutex);
187}
void ConditionVariableBroadcast(ConditionVariable *cv)
@ BM_FINISHED
Definition: execnodes.h:1843
#define SpinLockRelease(lock)
Definition: spin.h:61
#define SpinLockAcquire(lock)
Definition: spin.h:59
SharedBitmapState state
Definition: execnodes.h:1858
ConditionVariable cv
Definition: execnodes.h:1859

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 126 of file nodeBitmapHeapscan.c.

127{
128 ExprContext *econtext = node->ss.ps.ps_ExprContext;
129 TupleTableSlot *slot = node->ss.ss_ScanTupleSlot;
130
131 /*
132 * If we haven't yet performed the underlying index scan, do it, and begin
133 * the iteration over the bitmap.
134 */
135 if (!node->initialized)
137
139 slot, &node->recheck,
140 &node->stats.lossy_pages,
141 &node->stats.exact_pages))
142 {
143 /*
144 * Continuing in previously obtained page.
145 */
147
148 /*
149 * If we are using lossy info, we have to recheck the qual conditions
150 * at every tuple.
151 */
152 if (node->recheck)
153 {
154 econtext->ecxt_scantuple = slot;
155 if (!ExecQualAndReset(node->bitmapqualorig, econtext))
156 {
157 /* Fails recheck, so drop it and loop back for another */
158 InstrCountFiltered2(node, 1);
159 ExecClearTuple(slot);
160 continue;
161 }
162 }
163
164 /* OK to return this tuple */
165 return slot;
166 }
167
168 /*
169 * if we get here it means we are at the end of the scan..
170 */
171 return ExecClearTuple(slot);
172}
#define InstrCountFiltered2(node, delta)
Definition: execnodes.h:1268
static bool ExecQualAndReset(ExprState *state, ExprContext *econtext)
Definition: executor.h:568
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:123
static void BitmapTableScanSetup(BitmapHeapScanState *node)
ExprState * bitmapqualorig
Definition: execnodes.h:1891
BitmapHeapScanInstrumentation stats
Definition: execnodes.h:1893
TupleTableSlot * ecxt_scantuple
Definition: execnodes.h:268
ExprContext * ps_ExprContext
Definition: execnodes.h:1198
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1618
PlanState ps
Definition: execnodes.h:1615
struct TableScanDescData * ss_currentScanDesc
Definition: execnodes.h:1617
static bool table_scan_bitmap_next_tuple(TableScanDesc scan, TupleTableSlot *slot, bool *recheck, uint64 *lossy_pages, uint64 *exact_pages)
Definition: tableam.h:1925
static TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: tuptable.h:458

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 193 of file nodeBitmapHeapscan.c.

194{
195 ExprContext *econtext;
196
197 /*
198 * extract necessary information from index scan node
199 */
200 econtext = node->ss.ps.ps_ExprContext;
201
202 /* Does the tuple meet the original qual conditions? */
203 econtext->ecxt_scantuple = slot;
204 return ExecQualAndReset(node->bitmapqualorig, econtext);
205}

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 420 of file nodeBitmapHeapscan.c.

421{
423
424 while (1)
425 {
426 SpinLockAcquire(&pstate->mutex);
427 state = pstate->state;
428 if (pstate->state == BM_INITIAL)
429 pstate->state = BM_INPROGRESS;
430 SpinLockRelease(&pstate->mutex);
431
432 /* Exit if bitmap is done, or if we're the leader. */
433 if (state != BM_INPROGRESS)
434 break;
435
436 /* Wait for the leader to wake us up. */
437 ConditionVariableSleep(&pstate->cv, WAIT_EVENT_PARALLEL_BITMAP_SCAN);
438 }
439
441
442 return (state == BM_INITIAL);
443}
bool ConditionVariableCancelSleep(void)
void ConditionVariableSleep(ConditionVariable *cv, uint32 wait_event_info)
SharedBitmapState
Definition: execnodes.h:1840
@ BM_INITIAL
Definition: execnodes.h:1841
@ BM_INPROGRESS
Definition: execnodes.h:1842
Definition: regguts.h:323

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

Referenced by BitmapTableScanSetup().

◆ BitmapTableScanSetup()

static void BitmapTableScanSetup ( BitmapHeapScanState node)
static

Definition at line 63 of file nodeBitmapHeapscan.c.

64{
65 TBMIterator tbmiterator = {0};
66 ParallelBitmapHeapState *pstate = node->pstate;
67 dsa_area *dsa = node->ss.ps.state->es_query_dsa;
68
69 if (!pstate)
70 {
72
73 if (!node->tbm || !IsA(node->tbm, TIDBitmap))
74 elog(ERROR, "unrecognized result from subplan");
75 }
76 else if (BitmapShouldInitializeSharedState(pstate))
77 {
78 /*
79 * The leader will immediately come out of the function, but others
80 * will be blocked until leader populates the TBM and wakes them up.
81 */
83 if (!node->tbm || !IsA(node->tbm, TIDBitmap))
84 elog(ERROR, "unrecognized result from subplan");
85
86 /*
87 * Prepare to iterate over the TBM. This will return the dsa_pointer
88 * of the iterator state which will be used by multiple processes to
89 * iterate jointly.
90 */
92
93 /* We have initialized the shared state so wake up others. */
95 }
96
97 tbmiterator = tbm_begin_iterate(node->tbm, dsa,
98 pstate ?
99 pstate->tbmiterator :
101
102 /*
103 * If this is the first scan of the underlying table, create the table
104 * scan descriptor and begin the scan.
105 */
106 if (!node->ss.ss_currentScanDesc)
107 {
108 node->ss.ss_currentScanDesc =
110 node->ss.ps.state->es_snapshot,
111 0,
112 NULL);
113 }
114
115 node->ss.ss_currentScanDesc->st.rs_tbmiterator = tbmiterator;
116 node->initialized = true;
117}
#define InvalidDsaPointer
Definition: dsa.h:78
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:225
Node * MultiExecProcNode(PlanState *node)
Definition: execProcnode.c:507
#define outerPlanState(node)
Definition: execnodes.h:1255
static bool BitmapShouldInitializeSharedState(ParallelBitmapHeapState *pstate)
static void BitmapDoneInitializingSharedState(ParallelBitmapHeapState *pstate)
#define IsA(nodeptr, _type_)
Definition: nodes.h:164
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1895
TIDBitmap * tbm
Definition: execnodes.h:1892
struct dsa_area * es_query_dsa
Definition: execnodes.h:751
Snapshot es_snapshot
Definition: execnodes.h:657
dsa_pointer tbmiterator
Definition: execnodes.h:1856
EState * state
Definition: execnodes.h:1161
Relation ss_currentRelation
Definition: execnodes.h:1616
TBMIterator rs_tbmiterator
Definition: relscan.h:47
union TableScanDescData::@49 st
Definition: dsa.c:348
static TableScanDesc table_beginscan_bm(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key)
Definition: tableam.h:915
dsa_pointer tbm_prepare_shared_iterate(TIDBitmap *tbm)
Definition: tidbitmap.c:754
TBMIterator tbm_begin_iterate(TIDBitmap *tbm, dsa_area *dsa, dsa_pointer dsp)
Definition: tidbitmap.c:1574

References BitmapDoneInitializingSharedState(), BitmapShouldInitializeSharedState(), elog, ERROR, EState::es_query_dsa, EState::es_snapshot, BitmapHeapScanState::initialized, InvalidDsaPointer, IsA, MultiExecProcNode(), outerPlanState, ScanState::ps, BitmapHeapScanState::pstate, TableScanDescData::rs_tbmiterator, 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 453 of file nodeBitmapHeapscan.c.

455{
456 Size size;
457
458 size = MAXALIGN(sizeof(ParallelBitmapHeapState));
459
460 /* account for instrumentation, if required */
461 if (node->ss.ps.instrument && pcxt->nworkers > 0)
462 {
463 size = add_size(size, offsetof(SharedBitmapHeapInstrumentation, sinstrument));
464 size = add_size(size, mul_size(pcxt->nworkers, sizeof(BitmapHeapScanInstrumentation)));
465 }
466
467 shm_toc_estimate_chunk(&pcxt->estimator, size);
469}
#define MAXALIGN(LEN)
Definition: c.h:782
size_t Size
Definition: c.h:576
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53
Size add_size(Size s1, Size s2)
Definition: shmem.c:493
Size mul_size(Size s1, Size s2)
Definition: shmem.c:510
shm_toc_estimator estimator
Definition: parallel.h:41
Instrumentation * instrument
Definition: execnodes.h:1169

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

Referenced by ExecParallelEstimate().

◆ ExecBitmapHeapInitializeDSM()

void ExecBitmapHeapInitializeDSM ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 478 of file nodeBitmapHeapscan.c.

480{
482 SharedBitmapHeapInstrumentation *sinstrument = NULL;
483 dsa_area *dsa = node->ss.ps.state->es_query_dsa;
484 char *ptr;
485 Size size;
486
487 /* If there's no DSA, there are no workers; initialize nothing. */
488 if (dsa == NULL)
489 return;
490
491 size = MAXALIGN(sizeof(ParallelBitmapHeapState));
492 if (node->ss.ps.instrument && pcxt->nworkers > 0)
493 {
494 size = add_size(size, offsetof(SharedBitmapHeapInstrumentation, sinstrument));
495 size = add_size(size, mul_size(pcxt->nworkers, sizeof(BitmapHeapScanInstrumentation)));
496 }
497
498 ptr = shm_toc_allocate(pcxt->toc, size);
499 pstate = (ParallelBitmapHeapState *) ptr;
500 ptr += MAXALIGN(sizeof(ParallelBitmapHeapState));
501 if (node->ss.ps.instrument && pcxt->nworkers > 0)
502 sinstrument = (SharedBitmapHeapInstrumentation *) ptr;
503
504 pstate->tbmiterator = 0;
505
506 /* Initialize the mutex */
507 SpinLockInit(&pstate->mutex);
508 pstate->state = BM_INITIAL;
509
510 ConditionVariableInit(&pstate->cv);
511
512 if (sinstrument)
513 {
514 sinstrument->num_workers = pcxt->nworkers;
515
516 /* ensure any unfilled slots will contain zeroes */
517 memset(sinstrument->sinstrument, 0,
519 }
520
521 shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pstate);
522 node->pstate = pstate;
523 node->sinstrument = sinstrument;
524}
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
#define SpinLockInit(lock)
Definition: spin.h:57
SharedBitmapHeapInstrumentation * sinstrument
Definition: execnodes.h:1896
shm_toc * toc
Definition: parallel.h:44
Plan * plan
Definition: execnodes.h:1159
int plan_node_id
Definition: plannodes.h:207
BitmapHeapScanInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER]
Definition: execnodes.h:1873

References add_size(), BM_INITIAL, ConditionVariableInit(), ParallelBitmapHeapState::cv, EState::es_query_dsa, PlanState::instrument, MAXALIGN, mul_size(), ParallelBitmapHeapState::mutex, SharedBitmapHeapInstrumentation::num_workers, ParallelContext::nworkers, PlanState::plan, Plan::plan_node_id, ScanState::ps, BitmapHeapScanState::pstate, shm_toc_allocate(), shm_toc_insert(), SharedBitmapHeapInstrumentation::sinstrument, BitmapHeapScanState::sinstrument, SpinLockInit, BitmapHeapScanState::ss, PlanState::state, ParallelBitmapHeapState::state, ParallelBitmapHeapState::tbmiterator, and ParallelContext::toc.

Referenced by ExecParallelInitializeDSM().

◆ ExecBitmapHeapInitializeWorker()

void ExecBitmapHeapInitializeWorker ( BitmapHeapScanState node,
ParallelWorkerContext pwcxt 
)

Definition at line 558 of file nodeBitmapHeapscan.c.

560{
561 char *ptr;
562
563 Assert(node->ss.ps.state->es_query_dsa != NULL);
564
565 ptr = shm_toc_lookup(pwcxt->toc, node->ss.ps.plan->plan_node_id, false);
566
567 node->pstate = (ParallelBitmapHeapState *) ptr;
568 ptr += MAXALIGN(sizeof(ParallelBitmapHeapState));
569
570 if (node->ss.ps.instrument)
572}
Assert(PointerIsAligned(start, uint64))
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232

References Assert(), EState::es_query_dsa, PlanState::instrument, MAXALIGN, PlanState::plan, Plan::plan_node_id, ScanState::ps, BitmapHeapScanState::pstate, shm_toc_lookup(), BitmapHeapScanState::sinstrument, BitmapHeapScanState::ss, PlanState::state, and ParallelWorkerContext::toc.

Referenced by ExecParallelInitializeWorker().

◆ ExecBitmapHeapReInitializeDSM()

void ExecBitmapHeapReInitializeDSM ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 533 of file nodeBitmapHeapscan.c.

535{
536 ParallelBitmapHeapState *pstate = node->pstate;
537 dsa_area *dsa = node->ss.ps.state->es_query_dsa;
538
539 /* If there's no DSA, there are no workers; do nothing. */
540 if (dsa == NULL)
541 return;
542
543 pstate->state = BM_INITIAL;
544
545 if (DsaPointerIsValid(pstate->tbmiterator))
546 tbm_free_shared_area(dsa, pstate->tbmiterator);
547
549}
#define DsaPointerIsValid(x)
Definition: dsa.h:106
void tbm_free_shared_area(dsa_area *dsa, dsa_pointer dp)
Definition: tidbitmap.c:330

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

Referenced by ExecParallelReInitializeDSM().

◆ ExecBitmapHeapRetrieveInstrumentation()

void ExecBitmapHeapRetrieveInstrumentation ( BitmapHeapScanState node)

Definition at line 581 of file nodeBitmapHeapscan.c.

582{
583 SharedBitmapHeapInstrumentation *sinstrument = node->sinstrument;
584 Size size;
585
586 if (sinstrument == NULL)
587 return;
588
589 size = offsetof(SharedBitmapHeapInstrumentation, sinstrument)
590 + sinstrument->num_workers * sizeof(BitmapHeapScanInstrumentation);
591
592 node->sinstrument = palloc(size);
593 memcpy(node->sinstrument, sinstrument, size);
594}
struct BitmapHeapScanInstrumentation BitmapHeapScanInstrumentation
void * palloc(Size size)
Definition: mcxt.c:1945

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

Referenced by ExecParallelRetrieveInstrumentation().

◆ ExecBitmapHeapScan()

static TupleTableSlot * ExecBitmapHeapScan ( PlanState pstate)
static

Definition at line 212 of file nodeBitmapHeapscan.c.

213{
215
216 return ExecScan(&node->ss,
219}
TupleTableSlot * ExecScan(ScanState *node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd)
Definition: execScan.c:47
bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)
Definition: executor.h:602
TupleTableSlot *(* ExecScanAccessMtd)(ScanState *node)
Definition: executor.h:601
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 267 of file nodeBitmapHeapscan.c.

268{
269 TableScanDesc scanDesc;
270
271 /*
272 * When ending a parallel worker, copy the statistics gathered by the
273 * worker back into shared memory so that it can be picked up by the main
274 * process to report in EXPLAIN ANALYZE.
275 */
276 if (node->sinstrument != NULL && IsParallelWorker())
277 {
279
280 Assert(ParallelWorkerNumber <= node->sinstrument->num_workers);
282
283 /*
284 * Here we accumulate the stats rather than performing memcpy on
285 * node->stats into si. When a Gather/GatherMerge node finishes it
286 * will perform planner shutdown on the workers. On rescan it will
287 * spin up new workers which will have a new BitmapHeapScanState and
288 * zeroed stats.
289 */
290 si->exact_pages += node->stats.exact_pages;
291 si->lossy_pages += node->stats.lossy_pages;
292 }
293
294 /*
295 * extract information from the node
296 */
297 scanDesc = node->ss.ss_currentScanDesc;
298
299 /*
300 * close down subplans
301 */
303
304 if (scanDesc)
305 {
306 /*
307 * End iteration on iterators saved in scan descriptor if they have
308 * not already been cleaned up.
309 */
310 if (!tbm_exhausted(&scanDesc->st.rs_tbmiterator))
312
313 /*
314 * close table scan
315 */
316 table_endscan(scanDesc);
317 }
318
319 /*
320 * release bitmaps and buffers if any
321 */
322 if (node->tbm)
323 tbm_free(node->tbm);
324}
int ParallelWorkerNumber
Definition: parallel.c:115
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:562
#define IsParallelWorker()
Definition: parallel.h:60
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:979
void tbm_free(TIDBitmap *tbm)
Definition: tidbitmap.c:311
void tbm_end_iterate(TBMIterator *iterator)
Definition: tidbitmap.c:1597
static bool tbm_exhausted(TBMIterator *iterator)
Definition: tidbitmap.h:119

References Assert(), BitmapHeapScanInstrumentation::exact_pages, ExecEndNode(), IsParallelWorker, BitmapHeapScanInstrumentation::lossy_pages, outerPlanState, ParallelWorkerNumber, TableScanDescData::rs_tbmiterator, SharedBitmapHeapInstrumentation::sinstrument, BitmapHeapScanState::sinstrument, BitmapHeapScanState::ss, ScanState::ss_currentScanDesc, TableScanDescData::st, 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 333 of file nodeBitmapHeapscan.c.

334{
335 BitmapHeapScanState *scanstate;
336 Relation currentRelation;
337
338 /* check for unsupported flags */
340
341 /*
342 * Assert caller didn't ask for an unsafe snapshot --- see comments at
343 * head of file.
344 */
346
347 /*
348 * create state structure
349 */
350 scanstate = makeNode(BitmapHeapScanState);
351 scanstate->ss.ps.plan = (Plan *) node;
352 scanstate->ss.ps.state = estate;
354
355 scanstate->tbm = NULL;
356
357 /* Zero the statistics counters */
358 memset(&scanstate->stats, 0, sizeof(BitmapHeapScanInstrumentation));
359
360 scanstate->initialized = false;
361 scanstate->pstate = NULL;
362 scanstate->recheck = true;
363
364 /*
365 * Miscellaneous initialization
366 *
367 * create expression context for node
368 */
369 ExecAssignExprContext(estate, &scanstate->ss.ps);
370
371 /*
372 * open the scan relation
373 */
374 currentRelation = ExecOpenScanRelation(estate, node->scan.scanrelid, eflags);
375
376 /*
377 * initialize child nodes
378 */
379 outerPlanState(scanstate) = ExecInitNode(outerPlan(node), estate, eflags);
380
381 /*
382 * get the scan type from the relation descriptor.
383 */
384 ExecInitScanTupleSlot(estate, &scanstate->ss,
385 RelationGetDescr(currentRelation),
386 table_slot_callbacks(currentRelation));
387
388 /*
389 * Initialize result type and projection.
390 */
391 ExecInitResultTypeTL(&scanstate->ss.ps);
392 ExecAssignScanProjectionInfo(&scanstate->ss);
393
394 /*
395 * initialize child expressions
396 */
397 scanstate->ss.ps.qual =
398 ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
399 scanstate->bitmapqualorig =
400 ExecInitQual(node->bitmapqualorig, (PlanState *) scanstate);
401
402 scanstate->ss.ss_currentRelation = currentRelation;
403
404 /*
405 * all done.
406 */
407 return scanstate;
408}
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:229
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:142
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:81
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:2000
void ExecInitResultTypeTL(PlanState *planstate)
Definition: execTuples.c:1944
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:486
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:743
#define EXEC_FLAG_BACKWARD
Definition: executor.h:69
#define EXEC_FLAG_MARK
Definition: executor.h:70
static TupleTableSlot * ExecBitmapHeapScan(PlanState *pstate)
#define makeNode(_type_)
Definition: nodes.h:161
#define outerPlan(node)
Definition: plannodes.h:241
#define RelationGetDescr(relation)
Definition: rel.h:542
#define IsMVCCSnapshot(snapshot)
Definition: snapmgr.h:55
List * bitmapqualorig
Definition: plannodes.h:653
ExprState * qual
Definition: execnodes.h:1180
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1165
Index scanrelid
Definition: plannodes.h:483
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition: tableam.c:59

References Assert(), BitmapHeapScanState::bitmapqualorig, BitmapHeapScan::bitmapqualorig, EState::es_snapshot, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecAssignScanProjectionInfo(), ExecBitmapHeapScan(), ExecInitNode(), ExecInitQual(), ExecInitResultTypeTL(), ExecInitScanTupleSlot(), ExecOpenScanRelation(), PlanState::ExecProcNode, BitmapHeapScanState::initialized, IsMVCCSnapshot, makeNode, outerPlan, outerPlanState, PlanState::plan, ScanState::ps, BitmapHeapScanState::pstate, PlanState::qual, BitmapHeapScanState::recheck, RelationGetDescr, BitmapHeapScan::scan, Scan::scanrelid, BitmapHeapScanState::ss, ScanState::ss_currentRelation, PlanState::state, BitmapHeapScanState::stats, table_slot_callbacks(), and BitmapHeapScanState::tbm.

Referenced by ExecInitNode().

◆ ExecReScanBitmapHeapScan()

void ExecReScanBitmapHeapScan ( BitmapHeapScanState node)

Definition at line 226 of file nodeBitmapHeapscan.c.

227{
229
231
232 if (scan)
233 {
234 /*
235 * End iteration on iterators saved in scan descriptor if they have
236 * not already been cleaned up.
237 */
238 if (!tbm_exhausted(&scan->st.rs_tbmiterator))
240
241 /* rescan to release any page pin */
243 }
244
245 /* release bitmaps and buffers if any */
246 if (node->tbm)
247 tbm_free(node->tbm);
248 node->tbm = NULL;
249 node->initialized = false;
250 node->recheck = true;
251
252 ExecScanReScan(&node->ss);
253
254 /*
255 * if chgParam of subnode is not null then plan will be re-scanned by
256 * first ExecProcNode.
257 */
258 if (outerPlan->chgParam == NULL)
260}
void ExecReScan(PlanState *node)
Definition: execAmi.c:77
void ExecScanReScan(ScanState *node)
Definition: execScan.c:108
static void table_rescan(TableScanDesc scan, struct ScanKeyData *key)
Definition: tableam.h:988

References ExecReScan(), ExecScanReScan(), 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().