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)
 

Function Documentation

◆ ExecBitmapHeapEstimate()

void ExecBitmapHeapEstimate ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 803 of file nodeBitmapHeapscan.c.

805 {
807  shm_toc_estimate_keys(&pcxt->estimator, 1);
808 }
#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:41

References ParallelContext::estimator, shm_toc_estimate_chunk, and shm_toc_estimate_keys.

Referenced by ExecParallelEstimate().

◆ ExecBitmapHeapInitializeDSM()

void ExecBitmapHeapInitializeDSM ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 817 of file nodeBitmapHeapscan.c.

819 {
820  ParallelBitmapHeapState *pstate;
821  dsa_area *dsa = node->ss.ps.state->es_query_dsa;
822 
823  /* If there's no DSA, there are no workers; initialize nothing. */
824  if (dsa == NULL)
825  return;
826 
827  pstate = shm_toc_allocate(pcxt->toc, sizeof(ParallelBitmapHeapState));
828 
829  pstate->tbmiterator = 0;
830  pstate->prefetch_iterator = 0;
831 
832  /* Initialize the mutex */
833  SpinLockInit(&pstate->mutex);
834  pstate->prefetch_pages = 0;
835  pstate->prefetch_target = 0;
836  pstate->state = BM_INITIAL;
837 
838  ConditionVariableInit(&pstate->cv);
839 
840  shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pstate);
841  node->pstate = pstate;
842 }
void ConditionVariableInit(ConditionVariable *cv)
@ BM_INITIAL
Definition: execnodes.h:1762
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:1827
struct dsa_area * es_query_dsa
Definition: execnodes.h:704
SharedBitmapState state
Definition: execnodes.h:1786
dsa_pointer tbmiterator
Definition: execnodes.h:1781
ConditionVariable cv
Definition: execnodes.h:1787
dsa_pointer prefetch_iterator
Definition: execnodes.h:1782
shm_toc * toc
Definition: parallel.h:44
Plan * plan
Definition: execnodes.h:1118
EState * state
Definition: execnodes.h:1120
int plan_node_id
Definition: plannodes.h:151
PlanState ps
Definition: execnodes.h:1565
Definition: dsa.c:348

References BM_INITIAL, ConditionVariableInit(), ParallelBitmapHeapState::cv, EState::es_query_dsa, ParallelBitmapHeapState::mutex, 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(), 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 880 of file nodeBitmapHeapscan.c.

882 {
883  ParallelBitmapHeapState *pstate;
884 
885  Assert(node->ss.ps.state->es_query_dsa != NULL);
886 
887  pstate = shm_toc_lookup(pwcxt->toc, node->ss.ps.plan->plan_node_id, false);
888  node->pstate = pstate;
889 }
#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::plan, Plan::plan_node_id, ScanState::ps, BitmapHeapScanState::pstate, shm_toc_lookup(), BitmapHeapScanState::ss, PlanState::state, and ParallelWorkerContext::toc.

Referenced by ExecParallelInitializeWorker().

◆ ExecBitmapHeapReInitializeDSM()

void ExecBitmapHeapReInitializeDSM ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 851 of file nodeBitmapHeapscan.c.

853 {
854  ParallelBitmapHeapState *pstate = node->pstate;
855  dsa_area *dsa = node->ss.ps.state->es_query_dsa;
856 
857  /* If there's no DSA, there are no workers; do nothing. */
858  if (dsa == NULL)
859  return;
860 
861  pstate->state = BM_INITIAL;
862 
863  if (DsaPointerIsValid(pstate->tbmiterator))
864  tbm_free_shared_area(dsa, pstate->tbmiterator);
865 
868 
869  pstate->tbmiterator = InvalidDsaPointer;
871 }
#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().

◆ ExecEndBitmapHeapScan()

void ExecEndBitmapHeapScan ( BitmapHeapScanState node)

Definition at line 626 of file nodeBitmapHeapscan.c.

627 {
628  TableScanDesc scanDesc;
629 
630  /*
631  * extract information from the node
632  */
633  scanDesc = node->ss.ss_currentScanDesc;
634 
635  /*
636  * close down subplans
637  */
639 
640  /*
641  * release bitmaps and buffers if any
642  */
643  if (node->tbmiterator)
645  if (node->prefetch_iterator)
647  if (node->tbm)
648  tbm_free(node->tbm);
649  if (node->shared_tbmiterator)
651  if (node->shared_prefetch_iterator)
653  if (node->pvmbuffer != InvalidBuffer)
654  ReleaseBuffer(node->pvmbuffer);
655 
656  /*
657  * close heap scan
658  */
659  if (scanDesc)
660  table_endscan(scanDesc);
661 
662 }
#define InvalidBuffer
Definition: buf.h:25
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:4850
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:557
#define outerPlanState(node)
Definition: execnodes.h:1214
TBMIterator * tbmiterator
Definition: execnodes.h:1815
TIDBitmap * tbm
Definition: execnodes.h:1814
TBMIterator * prefetch_iterator
Definition: execnodes.h:1820
TBMSharedIterator * shared_prefetch_iterator
Definition: execnodes.h:1826
TBMSharedIterator * shared_tbmiterator
Definition: execnodes.h:1825
struct TableScanDescData * ss_currentScanDesc
Definition: execnodes.h:1567
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:991
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 ExecEndNode(), InvalidBuffer, outerPlanState, BitmapHeapScanState::prefetch_iterator, BitmapHeapScanState::pvmbuffer, ReleaseBuffer(), BitmapHeapScanState::shared_prefetch_iterator, BitmapHeapScanState::shared_tbmiterator, BitmapHeapScanState::ss, ScanState::ss_currentScanDesc, 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 671 of file nodeBitmapHeapscan.c.

672 {
673  BitmapHeapScanState *scanstate;
674  Relation currentRelation;
675 
676  /* check for unsupported flags */
677  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
678 
679  /*
680  * Assert caller didn't ask for an unsafe snapshot --- see comments at
681  * head of file.
682  */
684 
685  /*
686  * create state structure
687  */
688  scanstate = makeNode(BitmapHeapScanState);
689  scanstate->ss.ps.plan = (Plan *) node;
690  scanstate->ss.ps.state = estate;
691  scanstate->ss.ps.ExecProcNode = ExecBitmapHeapScan;
692 
693  scanstate->tbm = NULL;
694  scanstate->tbmiterator = NULL;
695  scanstate->tbmres = NULL;
696  scanstate->pvmbuffer = InvalidBuffer;
697  scanstate->exact_pages = 0;
698  scanstate->lossy_pages = 0;
699  scanstate->prefetch_iterator = NULL;
700  scanstate->prefetch_pages = 0;
701  scanstate->prefetch_target = 0;
702  scanstate->initialized = false;
703  scanstate->shared_tbmiterator = NULL;
704  scanstate->shared_prefetch_iterator = NULL;
705  scanstate->pstate = NULL;
706 
707  /*
708  * Miscellaneous initialization
709  *
710  * create expression context for node
711  */
712  ExecAssignExprContext(estate, &scanstate->ss.ps);
713 
714  /*
715  * open the scan relation
716  */
717  currentRelation = ExecOpenScanRelation(estate, node->scan.scanrelid, eflags);
718 
719  /*
720  * initialize child nodes
721  */
722  outerPlanState(scanstate) = ExecInitNode(outerPlan(node), estate, eflags);
723 
724  /*
725  * get the scan type from the relation descriptor.
726  */
727  ExecInitScanTupleSlot(estate, &scanstate->ss,
728  RelationGetDescr(currentRelation),
729  table_slot_callbacks(currentRelation));
730 
731  /*
732  * Initialize result type and projection.
733  */
734  ExecInitResultTypeTL(&scanstate->ss.ps);
735  ExecAssignScanProjectionInfo(&scanstate->ss);
736 
737  /*
738  * initialize child expressions
739  */
740  scanstate->ss.ps.qual =
741  ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
742  scanstate->bitmapqualorig =
743  ExecInitQual(node->bitmapqualorig, (PlanState *) scanstate);
744 
745  /*
746  * Maximum number of prefetches for the tablespace if configured,
747  * otherwise the current value of the effective_io_concurrency GUC.
748  */
749  scanstate->prefetch_maximum =
750  get_tablespace_io_concurrency(currentRelation->rd_rel->reltablespace);
751 
752  scanstate->ss.ss_currentRelation = currentRelation;
753 
754  /*
755  * all done.
756  */
757  return scanstate;
758 }
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:1813
TBMIterateResult * tbmres
Definition: execnodes.h:1816
List * bitmapqualorig
Definition: plannodes.h:541
Snapshot es_snapshot
Definition: execnodes.h:624
ExprState * qual
Definition: execnodes.h:1139
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1124
Form_pg_class rd_rel
Definition: rel.h:111
Relation ss_currentRelation
Definition: execnodes.h:1566
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, BitmapHeapScanState::exact_pages, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecAssignScanProjectionInfo(), ExecBitmapHeapScan(), ExecInitNode(), ExecInitQual(), ExecInitResultTypeTL(), ExecInitScanTupleSlot(), ExecOpenScanRelation(), PlanState::ExecProcNode, get_tablespace_io_concurrency(), BitmapHeapScanState::initialized, InvalidBuffer, IsMVCCSnapshot, BitmapHeapScanState::lossy_pages, 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, 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:1000

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