PostgreSQL Source Code git master
Loading...
Searching...
No Matches
nodeBitmapHeapscan.h File Reference
#include "access/parallel.h"
#include "nodes/execnodes.h"
Include dependency graph for nodeBitmapHeapscan.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

BitmapHeapScanStateExecInitBitmapHeapScan (BitmapHeapScan *node, EState *estate, int eflags)
 
void ExecEndBitmapHeapScan (BitmapHeapScanState *node)
 
void ExecReScanBitmapHeapScan (BitmapHeapScanState *node)
 
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

◆ ExecBitmapHeapEstimate()

void ExecBitmapHeapEstimate ( BitmapHeapScanState node,
ParallelContext pcxt 
)
extern

Definition at line 493 of file nodeBitmapHeapscan.c.

495{
496 Size size;
497
498 size = MAXALIGN(sizeof(ParallelBitmapHeapState));
499
500 /* account for instrumentation, if required */
501 if (node->ss.ps.instrument && pcxt->nworkers > 0)
502 {
503 size = add_size(size, offsetof(SharedBitmapHeapInstrumentation, sinstrument));
504 size = add_size(size, mul_size(pcxt->nworkers, sizeof(BitmapHeapScanInstrumentation)));
505 }
506
507 shm_toc_estimate_chunk(&pcxt->estimator, size);
509}
#define MAXALIGN(LEN)
Definition c.h:898
size_t Size
Definition c.h:691
static int fb(int x)
#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:485
Size mul_size(Size s1, Size s2)
Definition shmem.c:500
shm_toc_estimator estimator
Definition parallel.h:43
Instrumentation * instrument
Definition execnodes.h:1187
PlanState ps
Definition execnodes.h:1633

References add_size(), ParallelContext::estimator, fb(), 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 
)
extern

Definition at line 518 of file nodeBitmapHeapscan.c.

520{
523 dsa_area *dsa = node->ss.ps.state->es_query_dsa;
524 char *ptr;
525 Size size;
526
527 /* If there's no DSA, there are no workers; initialize nothing. */
528 if (dsa == NULL)
529 return;
530
531 size = MAXALIGN(sizeof(ParallelBitmapHeapState));
532 if (node->ss.ps.instrument && pcxt->nworkers > 0)
533 {
534 size = add_size(size, offsetof(SharedBitmapHeapInstrumentation, sinstrument));
535 size = add_size(size, mul_size(pcxt->nworkers, sizeof(BitmapHeapScanInstrumentation)));
536 }
537
538 ptr = shm_toc_allocate(pcxt->toc, size);
539 pstate = (ParallelBitmapHeapState *) ptr;
540 ptr += MAXALIGN(sizeof(ParallelBitmapHeapState));
541 if (node->ss.ps.instrument && pcxt->nworkers > 0)
542 sinstrument = (SharedBitmapHeapInstrumentation *) ptr;
543
544 pstate->tbmiterator = 0;
545
546 /* Initialize the mutex */
547 SpinLockInit(&pstate->mutex);
548 pstate->state = BM_INITIAL;
549
550 ConditionVariableInit(&pstate->cv);
551
552 if (sinstrument)
553 {
554 sinstrument->num_workers = pcxt->nworkers;
555
556 /* ensure any unfilled slots will contain zeroes */
557 memset(sinstrument->sinstrument, 0,
559 }
560
561 shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pstate);
562 node->pstate = pstate;
563 node->sinstrument = sinstrument;
564}
void ConditionVariableInit(ConditionVariable *cv)
@ BM_INITIAL
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
ParallelBitmapHeapState * pstate
Definition execnodes.h:1855
SharedBitmapHeapInstrumentation * sinstrument
Definition execnodes.h:1856
struct dsa_area * es_query_dsa
Definition execnodes.h:764
shm_toc * toc
Definition parallel.h:46
Plan * plan
Definition execnodes.h:1177
EState * state
Definition execnodes.h:1179
int plan_node_id
Definition plannodes.h:231
BitmapHeapScanInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER]

References add_size(), BM_INITIAL, ConditionVariableInit(), ParallelBitmapHeapState::cv, EState::es_query_dsa, fb(), 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, ParallelBitmapHeapState::state, PlanState::state, ParallelBitmapHeapState::tbmiterator, and ParallelContext::toc.

Referenced by ExecParallelInitializeDSM().

◆ ExecBitmapHeapInitializeWorker()

void ExecBitmapHeapInitializeWorker ( BitmapHeapScanState node,
ParallelWorkerContext pwcxt 
)
extern

Definition at line 598 of file nodeBitmapHeapscan.c.

600{
601 char *ptr;
602
603 Assert(node->ss.ps.state->es_query_dsa != NULL);
604
605 ptr = shm_toc_lookup(pwcxt->toc, node->ss.ps.plan->plan_node_id, false);
606
607 node->pstate = (ParallelBitmapHeapState *) ptr;
608 ptr += MAXALIGN(sizeof(ParallelBitmapHeapState));
609
610 if (node->ss.ps.instrument)
612}
#define Assert(condition)
Definition c.h:945
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition shm_toc.c:232

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

Referenced by ExecParallelInitializeWorker().

◆ ExecBitmapHeapReInitializeDSM()

void ExecBitmapHeapReInitializeDSM ( BitmapHeapScanState node,
ParallelContext pcxt 
)
extern

Definition at line 573 of file nodeBitmapHeapscan.c.

575{
576 ParallelBitmapHeapState *pstate = node->pstate;
577 dsa_area *dsa = node->ss.ps.state->es_query_dsa;
578
579 /* If there's no DSA, there are no workers; do nothing. */
580 if (dsa == NULL)
581 return;
582
583 pstate->state = BM_INITIAL;
584
585 if (DsaPointerIsValid(pstate->tbmiterator))
586 tbm_free_shared_area(dsa, pstate->tbmiterator);
587
589}
#define InvalidDsaPointer
Definition dsa.h:78
#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)
extern

Definition at line 621 of file nodeBitmapHeapscan.c.

622{
623 SharedBitmapHeapInstrumentation *sinstrument = node->sinstrument;
624 Size size;
625
626 if (sinstrument == NULL)
627 return;
628
629 size = offsetof(SharedBitmapHeapInstrumentation, sinstrument)
630 + sinstrument->num_workers * sizeof(BitmapHeapScanInstrumentation);
631
632 node->sinstrument = palloc(size);
633 memcpy(node->sinstrument, sinstrument, size);
634}
void * palloc(Size size)
Definition mcxt.c:1387

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

Referenced by ExecParallelRetrieveInstrumentation().

◆ ExecEndBitmapHeapScan()

void ExecEndBitmapHeapScan ( BitmapHeapScanState node)
extern

Definition at line 306 of file nodeBitmapHeapscan.c.

307{
309
310 /*
311 * When ending a parallel worker, copy the statistics gathered by the
312 * worker back into shared memory so that it can be picked up by the main
313 * process to report in EXPLAIN ANALYZE.
314 */
315 if (node->sinstrument != NULL && IsParallelWorker())
316 {
318
319 Assert(ParallelWorkerNumber < node->sinstrument->num_workers);
321
322 /*
323 * Here we accumulate the stats rather than performing memcpy on
324 * node->stats into si. When a Gather/GatherMerge node finishes it
325 * will perform planner shutdown on the workers. On rescan it will
326 * spin up new workers which will have a new BitmapHeapScanState and
327 * zeroed stats.
328 */
330 si->lossy_pages += node->stats.lossy_pages;
331 }
332
333 /*
334 * extract information from the node
335 */
337
338 /*
339 * close down subplans
340 */
342
343 if (scanDesc)
344 {
345 /*
346 * End iteration on iterators saved in scan descriptor if they have
347 * not already been cleaned up.
348 */
349 if (!tbm_exhausted(&scanDesc->st.rs_tbmiterator))
350 tbm_end_iterate(&scanDesc->st.rs_tbmiterator);
351
352 /*
353 * close table scan
354 */
356 }
357
358 /*
359 * release bitmaps and buffers if any
360 */
361 if (node->tbm)
362 tbm_free(node->tbm);
363}
int ParallelWorkerNumber
Definition parallel.c:117
void ExecEndNode(PlanState *node)
#define outerPlanState(node)
Definition execnodes.h:1273
#define IsParallelWorker()
Definition parallel.h:62
BitmapHeapScanInstrumentation stats
Definition execnodes.h:1853
struct TableScanDescData * ss_currentScanDesc
Definition execnodes.h:1635
static void table_endscan(TableScanDesc scan)
Definition tableam.h:1004
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 Assert, BitmapHeapScanInstrumentation::exact_pages, ExecEndNode(), fb(), IsParallelWorker, BitmapHeapScanInstrumentation::lossy_pages, outerPlanState, ParallelWorkerNumber, 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 
)
extern

Definition at line 372 of file nodeBitmapHeapscan.c.

373{
376
377 /* check for unsupported flags */
379
380 /*
381 * Assert caller didn't ask for an unsafe snapshot --- see comments at
382 * head of file.
383 */
385
386 /*
387 * create state structure
388 */
390 scanstate->ss.ps.plan = (Plan *) node;
391 scanstate->ss.ps.state = estate;
392 scanstate->ss.ps.ExecProcNode = ExecBitmapHeapScan;
393
394 scanstate->tbm = NULL;
395
396 /* Zero the statistics counters */
398
399 scanstate->initialized = false;
400 scanstate->pstate = NULL;
401 scanstate->recheck = true;
402
403 /*
404 * Miscellaneous initialization
405 *
406 * create expression context for node
407 */
408 ExecAssignExprContext(estate, &scanstate->ss.ps);
409
410 /*
411 * open the scan relation
412 */
413 currentRelation = ExecOpenScanRelation(estate, node->scan.scanrelid, eflags);
414
415 /*
416 * initialize child nodes
417 */
418 outerPlanState(scanstate) = ExecInitNode(outerPlan(node), estate, eflags);
419
420 /*
421 * get the scan type from the relation descriptor.
422 */
423 ExecInitScanTupleSlot(estate, &scanstate->ss,
427
428 /*
429 * Initialize result type and projection.
430 */
433
434 /*
435 * initialize child expressions
436 */
437 scanstate->ss.ps.qual =
438 ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
439 scanstate->bitmapqualorig =
441
442 scanstate->ss.ss_currentRelation = currentRelation;
443
444 /*
445 * all done.
446 */
447 return scanstate;
448}
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:747
#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:265
#define RelationGetDescr(relation)
Definition rel.h:540
#define IsMVCCSnapshot(snapshot)
Definition snapmgr.h:59
List * bitmapqualorig
Definition plannodes.h:710
Snapshot es_snapshot
Definition execnodes.h:672
Index scanrelid
Definition plannodes.h:540
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)
extern

Definition at line 265 of file nodeBitmapHeapscan.c.

266{
268
270
271 if (scan)
272 {
273 /*
274 * End iteration on iterators saved in scan descriptor if they have
275 * not already been cleaned up.
276 */
277 if (!tbm_exhausted(&scan->st.rs_tbmiterator))
279
280 /* rescan to release any page pin */
282 }
283
284 /* release bitmaps and buffers if any */
285 if (node->tbm)
286 tbm_free(node->tbm);
287 node->tbm = NULL;
288 node->initialized = false;
289 node->recheck = true;
290
291 ExecScanReScan(&node->ss);
292
293 /*
294 * if chgParam of subnode is not null then plan will be re-scanned by
295 * first ExecProcNode.
296 */
297 if (outerPlan->chgParam == NULL)
299}
void ExecReScan(PlanState *node)
Definition execAmi.c:78
void ExecScanReScan(ScanState *node)
Definition execScan.c:108
TBMIterator rs_tbmiterator
Definition relscan.h:46
union TableScanDescData::@52 st
static void table_rescan(TableScanDesc scan, ScanKeyData *key)
Definition tableam.h:1013

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().