PostgreSQL Source Code  git master
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 
)

Definition at line 828 of file nodeBitmapHeapscan.c.

830 {
831  Size size;
832 
834 
835  /* account for instrumentation, if required */
836  if (node->ss.ps.instrument && pcxt->nworkers > 0)
837  {
838  size = add_size(size, offsetof(SharedBitmapHeapInstrumentation, sinstrument));
840  }
841 
843  shm_toc_estimate_keys(&pcxt->estimator, 1);
844 }
#define MAXALIGN(LEN)
Definition: c.h:811
size_t Size
Definition: c.h:605
#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
static pg_noinline void Size size
Definition: slab.c:607
shm_toc_estimator estimator
Definition: parallel.h:41
Instrumentation * instrument
Definition: execnodes.h:1126
PlanState ps
Definition: execnodes.h:1563

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

Referenced by ExecParallelEstimate().

◆ ExecBitmapHeapInitializeDSM()

void ExecBitmapHeapInitializeDSM ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 853 of file nodeBitmapHeapscan.c.

855 {
856  ParallelBitmapHeapState *pstate;
857  SharedBitmapHeapInstrumentation *sinstrument = NULL;
858  dsa_area *dsa = node->ss.ps.state->es_query_dsa;
859  char *ptr;
860  Size size;
861 
862  /* If there's no DSA, there are no workers; initialize nothing. */
863  if (dsa == NULL)
864  return;
865 
867  if (node->ss.ps.instrument && pcxt->nworkers > 0)
868  {
869  size = add_size(size, offsetof(SharedBitmapHeapInstrumentation, sinstrument));
871  }
872 
873  ptr = shm_toc_allocate(pcxt->toc, size);
874  pstate = (ParallelBitmapHeapState *) ptr;
875  ptr += MAXALIGN(sizeof(ParallelBitmapHeapState));
876  if (node->ss.ps.instrument && pcxt->nworkers > 0)
877  sinstrument = (SharedBitmapHeapInstrumentation *) ptr;
878 
879  pstate->tbmiterator = 0;
880  pstate->prefetch_iterator = 0;
881 
882  /* Initialize the mutex */
883  SpinLockInit(&pstate->mutex);
884  pstate->prefetch_pages = 0;
885  pstate->prefetch_target = 0;
886  pstate->state = BM_INITIAL;
887 
888  ConditionVariableInit(&pstate->cv);
889 
890  if (sinstrument)
891  {
892  sinstrument->num_workers = pcxt->nworkers;
893 
894  /* ensure any unfilled slots will contain zeroes */
895  memset(sinstrument->sinstrument, 0,
896  pcxt->nworkers * sizeof(BitmapHeapScanInstrumentation));
897  }
898 
899  shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pstate);
900  node->pstate = pstate;
901  node->sinstrument = sinstrument;
902 }
void ConditionVariableInit(ConditionVariable *cv)
@ BM_INITIAL
Definition: execnodes.h:1777
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:171
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
#define SpinLockInit(lock)
Definition: spin.h:60
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1855
SharedBitmapHeapInstrumentation * sinstrument
Definition: execnodes.h:1856
struct dsa_area * es_query_dsa
Definition: execnodes.h:704
SharedBitmapState state
Definition: execnodes.h:1801
dsa_pointer tbmiterator
Definition: execnodes.h:1796
ConditionVariable cv
Definition: execnodes.h:1802
dsa_pointer prefetch_iterator
Definition: execnodes.h:1797
shm_toc * toc
Definition: parallel.h:44
Plan * plan
Definition: execnodes.h:1116
EState * state
Definition: execnodes.h:1118
int plan_node_id
Definition: plannodes.h:151
BitmapHeapScanInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER]
Definition: execnodes.h:1816
Definition: dsa.c:348

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, ParallelBitmapHeapState::prefetch_iterator, ParallelBitmapHeapState::prefetch_pages, ParallelBitmapHeapState::prefetch_target, ScanState::ps, BitmapHeapScanState::pstate, shm_toc_allocate(), shm_toc_insert(), SharedBitmapHeapInstrumentation::sinstrument, BitmapHeapScanState::sinstrument, size, 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 940 of file nodeBitmapHeapscan.c.

942 {
943  char *ptr;
944 
945  Assert(node->ss.ps.state->es_query_dsa != NULL);
946 
947  ptr = shm_toc_lookup(pwcxt->toc, node->ss.ps.plan->plan_node_id, false);
948 
949  node->pstate = (ParallelBitmapHeapState *) ptr;
950  ptr += MAXALIGN(sizeof(ParallelBitmapHeapState));
951 
952  if (node->ss.ps.instrument)
954 }
#define Assert(condition)
Definition: c.h:858
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 911 of file nodeBitmapHeapscan.c.

913 {
914  ParallelBitmapHeapState *pstate = node->pstate;
915  dsa_area *dsa = node->ss.ps.state->es_query_dsa;
916 
917  /* If there's no DSA, there are no workers; do nothing. */
918  if (dsa == NULL)
919  return;
920 
921  pstate->state = BM_INITIAL;
922 
923  if (DsaPointerIsValid(pstate->tbmiterator))
924  tbm_free_shared_area(dsa, pstate->tbmiterator);
925 
928 
929  pstate->tbmiterator = InvalidDsaPointer;
931 }
#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:341

References BM_INITIAL, DsaPointerIsValid, EState::es_query_dsa, InvalidDsaPointer, ParallelBitmapHeapState::prefetch_iterator, 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 963 of file nodeBitmapHeapscan.c.

964 {
965  SharedBitmapHeapInstrumentation *sinstrument = node->sinstrument;
966  Size size;
967 
968  if (sinstrument == NULL)
969  return;
970 
971  size = offsetof(SharedBitmapHeapInstrumentation, sinstrument)
972  + sinstrument->num_workers * sizeof(BitmapHeapScanInstrumentation);
973 
974  node->sinstrument = palloc(size);
975  memcpy(node->sinstrument, sinstrument, size);
976 }
struct BitmapHeapScanInstrumentation BitmapHeapScanInstrumentation
void * palloc(Size size)
Definition: mcxt.c:1317

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

Referenced by ExecParallelRetrieveInstrumentation().

◆ ExecEndBitmapHeapScan()

void ExecEndBitmapHeapScan ( BitmapHeapScanState node)

Definition at line 626 of file nodeBitmapHeapscan.c.

627 {
628  TableScanDesc scanDesc;
629 
630  /*
631  * When ending a parallel worker, copy the statistics gathered by the
632  * worker back into shared memory so that it can be picked up by the main
633  * process to report in EXPLAIN ANALYZE.
634  */
635  if (node->sinstrument != NULL && IsParallelWorker())
636  {
638 
639  Assert(ParallelWorkerNumber <= node->sinstrument->num_workers);
641 
642  /*
643  * Here we accumulate the stats rather than performing memcpy on
644  * node->stats into si. When a Gather/GatherMerge node finishes it
645  * will perform planner shutdown on the workers. On rescan it will
646  * spin up new workers which will have a new BitmapHeapScanState and
647  * zeroed stats.
648  */
649  si->exact_pages += node->stats.exact_pages;
650  si->lossy_pages += node->stats.lossy_pages;
651  }
652 
653  /*
654  * extract information from the node
655  */
656  scanDesc = node->ss.ss_currentScanDesc;
657 
658  /*
659  * close down subplans
660  */
662 
663  /*
664  * release bitmaps and buffers if any
665  */
666  if (node->tbmiterator)
668  if (node->prefetch_iterator)
670  if (node->tbm)
671  tbm_free(node->tbm);
672  if (node->shared_tbmiterator)
674  if (node->shared_prefetch_iterator)
676  if (node->pvmbuffer != InvalidBuffer)
677  ReleaseBuffer(node->pvmbuffer);
678 
679  /*
680  * close heap scan
681  */
682  if (scanDesc)
683  table_endscan(scanDesc);
684 
685 }
int ParallelWorkerNumber
Definition: parallel.c:112
#define InvalidBuffer
Definition: buf.h:25
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:4936
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:557
#define outerPlanState(node)
Definition: execnodes.h:1212
#define IsParallelWorker()
Definition: parallel.h:60
BitmapHeapScanInstrumentation stats
Definition: execnodes.h:1847
TBMIterator * tbmiterator
Definition: execnodes.h:1844
TIDBitmap * tbm
Definition: execnodes.h:1843
TBMIterator * prefetch_iterator
Definition: execnodes.h:1848
TBMSharedIterator * shared_prefetch_iterator
Definition: execnodes.h:1854
TBMSharedIterator * shared_tbmiterator
Definition: execnodes.h:1853
struct TableScanDescData * ss_currentScanDesc
Definition: execnodes.h:1565
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:1019
void tbm_free(TIDBitmap *tbm)
Definition: tidbitmap.c:322
void tbm_end_iterate(TBMIterator *iterator)
Definition: tidbitmap.c:1146
void tbm_end_shared_iterate(TBMSharedIterator *iterator)
Definition: tidbitmap.c:1158

References Assert, BitmapHeapScanInstrumentation::exact_pages, ExecEndNode(), InvalidBuffer, IsParallelWorker, BitmapHeapScanInstrumentation::lossy_pages, outerPlanState, ParallelWorkerNumber, BitmapHeapScanState::prefetch_iterator, BitmapHeapScanState::pvmbuffer, ReleaseBuffer(), BitmapHeapScanState::shared_prefetch_iterator, BitmapHeapScanState::shared_tbmiterator, SharedBitmapHeapInstrumentation::sinstrument, BitmapHeapScanState::sinstrument, BitmapHeapScanState::ss, ScanState::ss_currentScanDesc, BitmapHeapScanState::stats, table_endscan(), BitmapHeapScanState::tbm, tbm_end_iterate(), tbm_end_shared_iterate(), tbm_free(), and BitmapHeapScanState::tbmiterator.

Referenced by ExecEndNode().

◆ ExecInitBitmapHeapScan()

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

Definition at line 694 of file nodeBitmapHeapscan.c.

695 {
696  BitmapHeapScanState *scanstate;
697  Relation currentRelation;
698 
699  /* check for unsupported flags */
700  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
701 
702  /*
703  * Assert caller didn't ask for an unsafe snapshot --- see comments at
704  * head of file.
705  */
707 
708  /*
709  * create state structure
710  */
711  scanstate = makeNode(BitmapHeapScanState);
712  scanstate->ss.ps.plan = (Plan *) node;
713  scanstate->ss.ps.state = estate;
714  scanstate->ss.ps.ExecProcNode = ExecBitmapHeapScan;
715 
716  scanstate->tbm = NULL;
717  scanstate->tbmiterator = NULL;
718  scanstate->tbmres = NULL;
719  scanstate->pvmbuffer = InvalidBuffer;
720 
721  /* Zero the statistics counters */
722  memset(&scanstate->stats, 0, sizeof(BitmapHeapScanInstrumentation));
723 
724  scanstate->prefetch_iterator = NULL;
725  scanstate->prefetch_pages = 0;
726  scanstate->prefetch_target = 0;
727  scanstate->initialized = false;
728  scanstate->shared_tbmiterator = NULL;
729  scanstate->shared_prefetch_iterator = NULL;
730  scanstate->pstate = NULL;
731 
732  /*
733  * Miscellaneous initialization
734  *
735  * create expression context for node
736  */
737  ExecAssignExprContext(estate, &scanstate->ss.ps);
738 
739  /*
740  * open the scan relation
741  */
742  currentRelation = ExecOpenScanRelation(estate, node->scan.scanrelid, eflags);
743 
744  /*
745  * initialize child nodes
746  */
747  outerPlanState(scanstate) = ExecInitNode(outerPlan(node), estate, eflags);
748 
749  /*
750  * get the scan type from the relation descriptor.
751  */
752  ExecInitScanTupleSlot(estate, &scanstate->ss,
753  RelationGetDescr(currentRelation),
754  table_slot_callbacks(currentRelation));
755 
756  /*
757  * Initialize result type and projection.
758  */
759  ExecInitResultTypeTL(&scanstate->ss.ps);
760  ExecAssignScanProjectionInfo(&scanstate->ss);
761 
762  /*
763  * initialize child expressions
764  */
765  scanstate->ss.ps.qual =
766  ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
767  scanstate->bitmapqualorig =
768  ExecInitQual(node->bitmapqualorig, (PlanState *) scanstate);
769 
770  /*
771  * Maximum number of prefetches for the tablespace if configured,
772  * otherwise the current value of the effective_io_concurrency GUC.
773  */
774  scanstate->prefetch_maximum =
775  get_tablespace_io_concurrency(currentRelation->rd_rel->reltablespace);
776 
777  scanstate->ss.ss_currentRelation = currentRelation;
778 
779  /*
780  * all done.
781  */
782  return scanstate;
783 }
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:220
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:142
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:270
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1898
void ExecInitResultTypeTL(PlanState *planstate)
Definition: execTuples.c:1842
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:483
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:697
#define EXEC_FLAG_BACKWARD
Definition: executor.h:68
#define EXEC_FLAG_MARK
Definition: executor.h:69
static TupleTableSlot * ExecBitmapHeapScan(PlanState *pstate)
#define makeNode(_type_)
Definition: nodes.h:155
#define outerPlan(node)
Definition: plannodes.h:182
#define RelationGetDescr(relation)
Definition: rel.h:531
#define IsMVCCSnapshot(snapshot)
Definition: snapmgr.h:62
int get_tablespace_io_concurrency(Oid spcid)
Definition: spccache.c:215
ExprState * bitmapqualorig
Definition: execnodes.h:1842
TBMIterateResult * tbmres
Definition: execnodes.h:1845
List * bitmapqualorig
Definition: plannodes.h:541
Snapshot es_snapshot
Definition: execnodes.h:624
ExprState * qual
Definition: execnodes.h:1137
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1122
Form_pg_class rd_rel
Definition: rel.h:111
Relation ss_currentRelation
Definition: execnodes.h:1564
Index scanrelid
Definition: plannodes.h:389
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition: tableam.c:58

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, get_tablespace_io_concurrency(), BitmapHeapScanState::initialized, InvalidBuffer, IsMVCCSnapshot, makeNode, outerPlan, outerPlanState, PlanState::plan, BitmapHeapScanState::prefetch_iterator, BitmapHeapScanState::prefetch_maximum, BitmapHeapScanState::prefetch_pages, BitmapHeapScanState::prefetch_target, ScanState::ps, BitmapHeapScanState::pstate, BitmapHeapScanState::pvmbuffer, PlanState::qual, RelationData::rd_rel, RelationGetDescr, BitmapHeapScan::scan, Scan::scanrelid, BitmapHeapScanState::shared_prefetch_iterator, BitmapHeapScanState::shared_tbmiterator, BitmapHeapScanState::ss, ScanState::ss_currentRelation, PlanState::state, BitmapHeapScanState::stats, table_slot_callbacks(), BitmapHeapScanState::tbm, BitmapHeapScanState::tbmiterator, and BitmapHeapScanState::tbmres.

Referenced by ExecInitNode().

◆ ExecReScanBitmapHeapScan()

void ExecReScanBitmapHeapScan ( BitmapHeapScanState node)

Definition at line 581 of file nodeBitmapHeapscan.c.

582 {
584 
585  /* rescan to release any page pin */
586  if (node->ss.ss_currentScanDesc)
587  table_rescan(node->ss.ss_currentScanDesc, NULL);
588 
589  /* release bitmaps and buffers if any */
590  if (node->tbmiterator)
592  if (node->prefetch_iterator)
594  if (node->shared_tbmiterator)
596  if (node->shared_prefetch_iterator)
598  if (node->tbm)
599  tbm_free(node->tbm);
600  if (node->pvmbuffer != InvalidBuffer)
601  ReleaseBuffer(node->pvmbuffer);
602  node->tbm = NULL;
603  node->tbmiterator = NULL;
604  node->tbmres = NULL;
605  node->prefetch_iterator = NULL;
606  node->initialized = false;
607  node->shared_tbmiterator = NULL;
608  node->shared_prefetch_iterator = NULL;
609  node->pvmbuffer = InvalidBuffer;
610 
611  ExecScanReScan(&node->ss);
612 
613  /*
614  * if chgParam of subnode is not null then plan will be re-scanned by
615  * first ExecProcNode.
616  */
617  if (outerPlan->chgParam == NULL)
619 }
void ExecReScan(PlanState *node)
Definition: execAmi.c:76
void ExecScanReScan(ScanState *node)
Definition: execScan.c:297
static void table_rescan(TableScanDesc scan, struct ScanKeyData *key)
Definition: tableam.h:1028

References ExecReScan(), ExecScanReScan(), BitmapHeapScanState::initialized, InvalidBuffer, outerPlan, outerPlanState, BitmapHeapScanState::prefetch_iterator, BitmapHeapScanState::pvmbuffer, ReleaseBuffer(), BitmapHeapScanState::shared_prefetch_iterator, BitmapHeapScanState::shared_tbmiterator, BitmapHeapScanState::ss, ScanState::ss_currentScanDesc, table_rescan(), BitmapHeapScanState::tbm, tbm_end_iterate(), tbm_end_shared_iterate(), tbm_free(), BitmapHeapScanState::tbmiterator, and BitmapHeapScanState::tbmres.

Referenced by ExecReScan().