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

846 {
847  EState *estate = node->ss.ps.state;
848 
849  node->pscan_len = add_size(offsetof(ParallelBitmapHeapState,
850  phs_snapshot_data),
852 
854  shm_toc_estimate_keys(&pcxt->estimator, 1);
855 }
#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:502
Size EstimateSnapshotSpace(Snapshot snapshot)
Definition: snapmgr.c:1667
Snapshot es_snapshot
Definition: execnodes.h:616
shm_toc_estimator estimator
Definition: parallel.h:42
EState * state
Definition: execnodes.h:1039
PlanState ps
Definition: execnodes.h:1474

References add_size(), EState::es_snapshot, EstimateSnapshotSpace(), ParallelContext::estimator, ScanState::ps, BitmapHeapScanState::pscan_len, shm_toc_estimate_chunk, shm_toc_estimate_keys, BitmapHeapScanState::ss, and PlanState::state.

Referenced by ExecParallelEstimate().

◆ ExecBitmapHeapInitializeDSM()

void ExecBitmapHeapInitializeDSM ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 864 of file nodeBitmapHeapscan.c.

866 {
867  ParallelBitmapHeapState *pstate;
868  EState *estate = node->ss.ps.state;
869  dsa_area *dsa = node->ss.ps.state->es_query_dsa;
870 
871  /* If there's no DSA, there are no workers; initialize nothing. */
872  if (dsa == NULL)
873  return;
874 
875  pstate = shm_toc_allocate(pcxt->toc, node->pscan_len);
876 
877  pstate->tbmiterator = 0;
878  pstate->prefetch_iterator = 0;
879 
880  /* Initialize the mutex */
881  SpinLockInit(&pstate->mutex);
882  pstate->prefetch_pages = 0;
883  pstate->prefetch_target = 0;
884  pstate->state = BM_INITIAL;
885 
886  ConditionVariableInit(&pstate->cv);
888 
889  shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pstate);
890  node->pstate = pstate;
891 }
void ConditionVariableInit(ConditionVariable *cv)
@ BM_INITIAL
Definition: execnodes.h:1671
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
void SerializeSnapshot(Snapshot snapshot, char *start_address)
Definition: snapmgr.c:1691
#define SpinLockInit(lock)
Definition: spin.h:60
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1746
struct dsa_area * es_query_dsa
Definition: execnodes.h:696
SharedBitmapState state
Definition: execnodes.h:1696
dsa_pointer tbmiterator
Definition: execnodes.h:1691
ConditionVariable cv
Definition: execnodes.h:1697
dsa_pointer prefetch_iterator
Definition: execnodes.h:1692
char phs_snapshot_data[FLEXIBLE_ARRAY_MEMBER]
Definition: execnodes.h:1698
shm_toc * toc
Definition: parallel.h:45
Plan * plan
Definition: execnodes.h:1037
int plan_node_id
Definition: plannodes.h:152
Definition: dsa.c:367

References BM_INITIAL, ConditionVariableInit(), ParallelBitmapHeapState::cv, EState::es_query_dsa, EState::es_snapshot, ParallelBitmapHeapState::mutex, ParallelBitmapHeapState::phs_snapshot_data, PlanState::plan, Plan::plan_node_id, ParallelBitmapHeapState::prefetch_iterator, ParallelBitmapHeapState::prefetch_pages, ParallelBitmapHeapState::prefetch_target, ScanState::ps, BitmapHeapScanState::pscan_len, BitmapHeapScanState::pstate, SerializeSnapshot(), 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 929 of file nodeBitmapHeapscan.c.

931 {
932  ParallelBitmapHeapState *pstate;
933  Snapshot snapshot;
934 
935  Assert(node->ss.ps.state->es_query_dsa != NULL);
936 
937  pstate = shm_toc_lookup(pwcxt->toc, node->ss.ps.plan->plan_node_id, false);
938  node->pstate = pstate;
939 
940  snapshot = RestoreSnapshot(pstate->phs_snapshot_data);
942 }
Assert(fmt[strlen(fmt) - 1] !='\n')
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232
Snapshot RestoreSnapshot(char *start_address)
Definition: snapmgr.c:1750
struct TableScanDescData * ss_currentScanDesc
Definition: execnodes.h:1476
void table_scan_update_snapshot(TableScanDesc scan, Snapshot snapshot)
Definition: tableam.c:124

References Assert(), EState::es_query_dsa, ParallelBitmapHeapState::phs_snapshot_data, PlanState::plan, Plan::plan_node_id, ScanState::ps, BitmapHeapScanState::pstate, RestoreSnapshot(), shm_toc_lookup(), BitmapHeapScanState::ss, ScanState::ss_currentScanDesc, PlanState::state, table_scan_update_snapshot(), and ParallelWorkerContext::toc.

Referenced by ExecParallelInitializeWorker().

◆ ExecBitmapHeapReInitializeDSM()

void ExecBitmapHeapReInitializeDSM ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 900 of file nodeBitmapHeapscan.c.

902 {
903  ParallelBitmapHeapState *pstate = node->pstate;
904  dsa_area *dsa = node->ss.ps.state->es_query_dsa;
905 
906  /* If there's no DSA, there are no workers; do nothing. */
907  if (dsa == NULL)
908  return;
909 
910  pstate->state = BM_INITIAL;
911 
912  if (DsaPointerIsValid(pstate->tbmiterator))
913  tbm_free_shared_area(dsa, pstate->tbmiterator);
914 
917 
918  pstate->tbmiterator = InvalidDsaPointer;
920 }
#define InvalidDsaPointer
Definition: dsa.h:78
#define DsaPointerIsValid(x)
Definition: dsa.h:81
void tbm_free_shared_area(dsa_area *dsa, dsa_pointer dp)
Definition: tidbitmap.c:340

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

650 {
651  TableScanDesc scanDesc;
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->vmbuffer != InvalidBuffer)
677  ReleaseBuffer(node->vmbuffer);
678  if (node->pvmbuffer != InvalidBuffer)
679  ReleaseBuffer(node->pvmbuffer);
680 
681  /*
682  * close heap scan
683  */
684  table_endscan(scanDesc);
685 }
#define InvalidBuffer
Definition: buf.h:25
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:4480
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:557
#define outerPlanState(node)
Definition: execnodes.h:1133
TBMIterator * tbmiterator
Definition: execnodes.h:1730
TIDBitmap * tbm
Definition: execnodes.h:1729
TBMIterator * prefetch_iterator
Definition: execnodes.h:1738
TBMSharedIterator * shared_prefetch_iterator
Definition: execnodes.h:1745
TBMSharedIterator * shared_tbmiterator
Definition: execnodes.h:1744
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:1009
void tbm_free(TIDBitmap *tbm)
Definition: tidbitmap.c:321
void tbm_end_iterate(TBMIterator *iterator)
Definition: tidbitmap.c:1145
void tbm_end_shared_iterate(TBMSharedIterator *iterator)
Definition: tidbitmap.c:1157

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(), BitmapHeapScanState::tbmiterator, and BitmapHeapScanState::vmbuffer.

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->return_empty_tuples = 0;
720  scanstate->vmbuffer = InvalidBuffer;
721  scanstate->pvmbuffer = InvalidBuffer;
722  scanstate->exact_pages = 0;
723  scanstate->lossy_pages = 0;
724  scanstate->prefetch_iterator = NULL;
725  scanstate->prefetch_pages = 0;
726  scanstate->prefetch_target = 0;
727  scanstate->pscan_len = 0;
728  scanstate->initialized = false;
729  scanstate->shared_tbmiterator = NULL;
730  scanstate->shared_prefetch_iterator = NULL;
731  scanstate->pstate = NULL;
732 
733  /*
734  * We can potentially skip fetching heap pages if we do not need any
735  * columns of the table, either for checking non-indexable quals or for
736  * returning data. This test is a bit simplistic, as it checks the
737  * stronger condition that there's no qual or return tlist at all. But in
738  * most cases it's probably not worth working harder than that.
739  */
740  scanstate->can_skip_fetch = (node->scan.plan.qual == NIL &&
741  node->scan.plan.targetlist == NIL);
742 
743  /*
744  * Miscellaneous initialization
745  *
746  * create expression context for node
747  */
748  ExecAssignExprContext(estate, &scanstate->ss.ps);
749 
750  /*
751  * open the scan relation
752  */
753  currentRelation = ExecOpenScanRelation(estate, node->scan.scanrelid, eflags);
754 
755  /*
756  * initialize child nodes
757  */
758  outerPlanState(scanstate) = ExecInitNode(outerPlan(node), estate, eflags);
759 
760  /*
761  * get the scan type from the relation descriptor.
762  */
763  ExecInitScanTupleSlot(estate, &scanstate->ss,
764  RelationGetDescr(currentRelation),
765  table_slot_callbacks(currentRelation));
766 
767  /*
768  * Initialize result type and projection.
769  */
770  ExecInitResultTypeTL(&scanstate->ss.ps);
771  ExecAssignScanProjectionInfo(&scanstate->ss);
772 
773  /*
774  * initialize child expressions
775  */
776  scanstate->ss.ps.qual =
777  ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
778  scanstate->bitmapqualorig =
779  ExecInitQual(node->bitmapqualorig, (PlanState *) scanstate);
780 
781  /*
782  * Maximum number of prefetches for the tablespace if configured,
783  * otherwise the current value of the effective_io_concurrency GUC.
784  */
785  scanstate->prefetch_maximum =
786  get_tablespace_io_concurrency(currentRelation->rd_rel->reltablespace);
787 
788  scanstate->ss.ss_currentRelation = currentRelation;
789 
790  scanstate->ss.ss_currentScanDesc = table_beginscan_bm(currentRelation,
791  estate->es_snapshot,
792  0,
793  NULL);
794 
795  /*
796  * all done.
797  */
798  return scanstate;
799 }
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:214
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:142
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:271
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1812
void ExecInitResultTypeTL(PlanState *planstate)
Definition: execTuples.c:1756
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:488
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:702
#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:176
#define NIL
Definition: pg_list.h:68
#define outerPlan(node)
Definition: plannodes.h:183
#define RelationGetDescr(relation)
Definition: rel.h:530
#define IsMVCCSnapshot(snapshot)
Definition: snapmgr.h:62
int get_tablespace_io_concurrency(Oid spcid)
Definition: spccache.c:215
ExprState * bitmapqualorig
Definition: execnodes.h:1728
TBMIterateResult * tbmres
Definition: execnodes.h:1731
List * bitmapqualorig
Definition: plannodes.h:539
ExprState * qual
Definition: execnodes.h:1058
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1043
Form_pg_class rd_rel
Definition: rel.h:111
Relation ss_currentRelation
Definition: execnodes.h:1475
Index scanrelid
Definition: plannodes.h:387
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition: tableam.c:58
static TableScanDesc table_beginscan_bm(Relation rel, Snapshot snapshot, int nkeys, struct ScanKeyData *key)
Definition: tableam.h:946

References Assert(), BitmapHeapScanState::bitmapqualorig, BitmapHeapScan::bitmapqualorig, BitmapHeapScanState::can_skip_fetch, 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, NIL, outerPlan, outerPlanState, PlanState::plan, BitmapHeapScanState::prefetch_iterator, BitmapHeapScanState::prefetch_maximum, BitmapHeapScanState::prefetch_pages, BitmapHeapScanState::prefetch_target, ScanState::ps, BitmapHeapScanState::pscan_len, BitmapHeapScanState::pstate, BitmapHeapScanState::pvmbuffer, PlanState::qual, RelationData::rd_rel, RelationGetDescr, BitmapHeapScanState::return_empty_tuples, BitmapHeapScan::scan, Scan::scanrelid, BitmapHeapScanState::shared_prefetch_iterator, BitmapHeapScanState::shared_tbmiterator, BitmapHeapScanState::ss, ScanState::ss_currentRelation, ScanState::ss_currentScanDesc, PlanState::state, table_beginscan_bm(), table_slot_callbacks(), BitmapHeapScanState::tbm, BitmapHeapScanState::tbmiterator, BitmapHeapScanState::tbmres, and BitmapHeapScanState::vmbuffer.

Referenced by ExecInitNode().

◆ ExecReScanBitmapHeapScan()

void ExecReScanBitmapHeapScan ( BitmapHeapScanState node)

Definition at line 602 of file nodeBitmapHeapscan.c.

603 {
605 
606  /* rescan to release any page pin */
607  table_rescan(node->ss.ss_currentScanDesc, NULL);
608 
609  /* release bitmaps and buffers if any */
610  if (node->tbmiterator)
612  if (node->prefetch_iterator)
614  if (node->shared_tbmiterator)
616  if (node->shared_prefetch_iterator)
618  if (node->tbm)
619  tbm_free(node->tbm);
620  if (node->vmbuffer != InvalidBuffer)
621  ReleaseBuffer(node->vmbuffer);
622  if (node->pvmbuffer != InvalidBuffer)
623  ReleaseBuffer(node->pvmbuffer);
624  node->tbm = NULL;
625  node->tbmiterator = NULL;
626  node->tbmres = NULL;
627  node->prefetch_iterator = NULL;
628  node->initialized = false;
629  node->shared_tbmiterator = NULL;
630  node->shared_prefetch_iterator = NULL;
631  node->vmbuffer = InvalidBuffer;
632  node->pvmbuffer = InvalidBuffer;
633 
634  ExecScanReScan(&node->ss);
635 
636  /*
637  * if chgParam of subnode is not null then plan will be re-scanned by
638  * first ExecProcNode.
639  */
640  if (outerPlan->chgParam == NULL)
642 }
void ExecReScan(PlanState *node)
Definition: execAmi.c:78
void ExecScanReScan(ScanState *node)
Definition: execScan.c:298
static void table_rescan(TableScanDesc scan, struct ScanKeyData *key)
Definition: tableam.h:1018

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, BitmapHeapScanState::tbmres, and BitmapHeapScanState::vmbuffer.

Referenced by ExecReScan().