PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
nodeBitmapHeapscan.h File Reference
#include "nodes/execnodes.h"
#include "access/parallel.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, shm_toc *toc)
 

Function Documentation

void ExecBitmapHeapEstimate ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 941 of file nodeBitmapHeapscan.c.

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

Referenced by ExecParallelEstimate().

943 {
944  EState *estate = node->ss.ps.state;
945 
947  phs_snapshot_data),
949 
951  shm_toc_estimate_keys(&pcxt->estimator, 1);
952 }
shm_toc_estimator estimator
Definition: parallel.h:41
Snapshot es_snapshot
Definition: execnodes.h:429
EState * state
Definition: execnodes.h:849
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
PlanState ps
Definition: execnodes.h:1101
Size EstimateSnapshotSpace(Snapshot snap)
Definition: snapmgr.c:2038
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:53
#define offsetof(type, field)
Definition: c.h:549
void ExecBitmapHeapInitializeDSM ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 961 of file nodeBitmapHeapscan.c.

References BM_INITIAL, ConditionVariableInit(), ParallelBitmapHeapState::cv, 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().

963 {
964  ParallelBitmapHeapState *pstate;
965  EState *estate = node->ss.ps.state;
966 
967  pstate = shm_toc_allocate(pcxt->toc, node->pscan_len);
968 
969  pstate->tbmiterator = 0;
970  pstate->prefetch_iterator = 0;
971 
972  /* Initialize the mutex */
973  SpinLockInit(&pstate->mutex);
974  pstate->prefetch_pages = 0;
975  pstate->prefetch_target = 0;
976  pstate->state = BM_INITIAL;
977 
978  ConditionVariableInit(&pstate->cv);
980 
981  shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pstate);
982  node->pstate = pstate;
983 }
#define SpinLockInit(lock)
Definition: spin.h:60
int plan_node_id
Definition: plannodes.h:143
Snapshot es_snapshot
Definition: execnodes.h:429
EState * state
Definition: execnodes.h:849
PlanState ps
Definition: execnodes.h:1101
void ConditionVariableInit(ConditionVariable *cv)
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1362
void SerializeSnapshot(Snapshot snapshot, char *start_address)
Definition: snapmgr.c:2062
dsa_pointer tbmiterator
Definition: execnodes.h:1315
Plan * plan
Definition: execnodes.h:847
dsa_pointer prefetch_iterator
Definition: execnodes.h:1316
SharedBitmapState state
Definition: execnodes.h:1320
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
char phs_snapshot_data[FLEXIBLE_ARRAY_MEMBER]
Definition: execnodes.h:1322
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:171
ConditionVariable cv
Definition: execnodes.h:1321
shm_toc * toc
Definition: parallel.h:44
void ExecBitmapHeapInitializeWorker ( BitmapHeapScanState node,
shm_toc toc 
)

Definition at line 1017 of file nodeBitmapHeapscan.c.

References heap_update_snapshot(), ParallelBitmapHeapState::phs_snapshot_data, PlanState::plan, Plan::plan_node_id, ScanState::ps, BitmapHeapScanState::pstate, RestoreSnapshot(), shm_toc_lookup(), BitmapHeapScanState::ss, and ScanState::ss_currentScanDesc.

Referenced by ExecParallelInitializeWorker().

1018 {
1019  ParallelBitmapHeapState *pstate;
1020  Snapshot snapshot;
1021 
1022  pstate = shm_toc_lookup(toc, node->ss.ps.plan->plan_node_id, false);
1023  node->pstate = pstate;
1024 
1025  snapshot = RestoreSnapshot(pstate->phs_snapshot_data);
1026  heap_update_snapshot(node->ss.ss_currentScanDesc, snapshot);
1027 }
Snapshot RestoreSnapshot(char *start_address)
Definition: snapmgr.c:2121
void heap_update_snapshot(HeapScanDesc scan, Snapshot snapshot)
Definition: heapam.c:1774
int plan_node_id
Definition: plannodes.h:143
PlanState ps
Definition: execnodes.h:1101
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1362
Plan * plan
Definition: execnodes.h:847
char phs_snapshot_data[FLEXIBLE_ARRAY_MEMBER]
Definition: execnodes.h:1322
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1103
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232
void ExecBitmapHeapReInitializeDSM ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 992 of file nodeBitmapHeapscan.c.

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

994 {
995  ParallelBitmapHeapState *pstate = node->pstate;
996  dsa_area *dsa = node->ss.ps.state->es_query_dsa;
997 
998  pstate->state = BM_INITIAL;
999 
1000  if (DsaPointerIsValid(pstate->tbmiterator))
1001  tbm_free_shared_area(dsa, pstate->tbmiterator);
1002 
1003  if (DsaPointerIsValid(pstate->prefetch_iterator))
1005 
1006  pstate->tbmiterator = InvalidDsaPointer;
1008 }
struct dsa_area * es_query_dsa
Definition: execnodes.h:511
#define InvalidDsaPointer
Definition: dsa.h:78
EState * state
Definition: execnodes.h:849
PlanState ps
Definition: execnodes.h:1101
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1362
dsa_pointer tbmiterator
Definition: execnodes.h:1315
void tbm_free_shared_area(dsa_area *dsa, dsa_pointer dp)
Definition: tidbitmap.c:351
dsa_pointer prefetch_iterator
Definition: execnodes.h:1316
SharedBitmapState state
Definition: execnodes.h:1320
#define DsaPointerIsValid(x)
Definition: dsa.h:81
Definition: dsa.c:354
void ExecEndBitmapHeapScan ( BitmapHeapScanState node)

Definition at line 723 of file nodeBitmapHeapscan.c.

References ExecClearTuple(), ExecCloseScanRelation(), ExecEndNode(), ExecFreeExprContext(), heap_endscan(), outerPlanState, BitmapHeapScanState::prefetch_iterator, ScanState::ps, PlanState::ps_ResultTupleSlot, BitmapHeapScanState::shared_prefetch_iterator, BitmapHeapScanState::shared_tbmiterator, BitmapHeapScanState::ss, ScanState::ss_currentRelation, ScanState::ss_currentScanDesc, ScanState::ss_ScanTupleSlot, BitmapHeapScanState::tbm, tbm_end_iterate(), tbm_end_shared_iterate(), tbm_free(), and BitmapHeapScanState::tbmiterator.

Referenced by ExecEndNode().

724 {
725  Relation relation;
726  HeapScanDesc scanDesc;
727 
728  /*
729  * extract information from the node
730  */
731  relation = node->ss.ss_currentRelation;
732  scanDesc = node->ss.ss_currentScanDesc;
733 
734  /*
735  * Free the exprcontext
736  */
737  ExecFreeExprContext(&node->ss.ps);
738 
739  /*
740  * clear out tuple table slots
741  */
744 
745  /*
746  * close down subplans
747  */
749 
750  /*
751  * release bitmap if any
752  */
753  if (node->tbmiterator)
755  if (node->prefetch_iterator)
757  if (node->tbm)
758  tbm_free(node->tbm);
759  if (node->shared_tbmiterator)
761  if (node->shared_prefetch_iterator)
763 
764  /*
765  * close heap scan
766  */
767  heap_endscan(scanDesc);
768 
769  /*
770  * close the heap relation.
771  */
772  ExecCloseScanRelation(relation);
773 }
void tbm_end_iterate(TBMIterator *iterator)
Definition: tidbitmap.c:1156
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1565
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:523
TIDBitmap * tbm
Definition: execnodes.h:1349
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1104
Relation ss_currentRelation
Definition: execnodes.h:1102
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:521
PlanState ps
Definition: execnodes.h:1101
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:880
#define outerPlanState(node)
Definition: execnodes.h:893
void tbm_free(TIDBitmap *tbm)
Definition: tidbitmap.c:332
void ExecCloseScanRelation(Relation scanrel)
Definition: execUtils.c:666
TBMSharedIterator * shared_tbmiterator
Definition: execnodes.h:1360
TBMIterator * tbmiterator
Definition: execnodes.h:1350
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1103
TBMIterator * prefetch_iterator
Definition: execnodes.h:1354
TBMSharedIterator * shared_prefetch_iterator
Definition: execnodes.h:1361
void tbm_end_shared_iterate(TBMSharedIterator *iterator)
Definition: tidbitmap.c:1168
BitmapHeapScanState* ExecInitBitmapHeapScan ( BitmapHeapScan node,
EState estate,
int  eflags 
)

Definition at line 782 of file nodeBitmapHeapscan.c.

References Assert, BitmapHeapScan::bitmapqualorig, BitmapHeapScanState::bitmapqualorig, ComputeIoConcurrency(), effective_io_concurrency, EState::es_snapshot, BitmapHeapScanState::exact_pages, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecAssignResultTypeFromTL(), ExecAssignScanProjectionInfo(), ExecAssignScanType(), ExecBitmapHeapScan(), ExecInitNode(), ExecInitQual(), ExecInitResultTupleSlot(), ExecInitScanTupleSlot(), ExecOpenScanRelation(), PlanState::ExecProcNode, get_tablespace_io_concurrency(), heap_beginscan_bm(), BitmapHeapScanState::initialized, IsMVCCSnapshot, BitmapHeapScanState::lossy_pages, makeNode, outerPlan, outerPlanState, Scan::plan, PlanState::plan, BitmapHeapScanState::prefetch_iterator, BitmapHeapScanState::prefetch_maximum, BitmapHeapScanState::prefetch_pages, BitmapHeapScanState::prefetch_target, ScanState::ps, BitmapHeapScanState::pscan_len, BitmapHeapScanState::pstate, Plan::qual, PlanState::qual, RelationData::rd_rel, RelationGetDescr, rint(), BitmapHeapScan::scan, Scan::scanrelid, BitmapHeapScanState::shared_tbmiterator, BitmapHeapScanState::ss, ScanState::ss_currentRelation, ScanState::ss_currentScanDesc, PlanState::state, target_prefetch_pages, BitmapHeapScanState::tbm, BitmapHeapScanState::tbmiterator, and BitmapHeapScanState::tbmres.

Referenced by ExecInitNode().

783 {
784  BitmapHeapScanState *scanstate;
785  Relation currentRelation;
786  int io_concurrency;
787 
788  /* check for unsupported flags */
789  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
790 
791  /*
792  * Assert caller didn't ask for an unsafe snapshot --- see comments at
793  * head of file.
794  */
796 
797  /*
798  * create state structure
799  */
800  scanstate = makeNode(BitmapHeapScanState);
801  scanstate->ss.ps.plan = (Plan *) node;
802  scanstate->ss.ps.state = estate;
803  scanstate->ss.ps.ExecProcNode = ExecBitmapHeapScan;
804 
805  scanstate->tbm = NULL;
806  scanstate->tbmiterator = NULL;
807  scanstate->tbmres = NULL;
808  scanstate->exact_pages = 0;
809  scanstate->lossy_pages = 0;
810  scanstate->prefetch_iterator = NULL;
811  scanstate->prefetch_pages = 0;
812  scanstate->prefetch_target = 0;
813  /* may be updated below */
815  scanstate->pscan_len = 0;
816  scanstate->initialized = false;
817  scanstate->shared_tbmiterator = NULL;
818  scanstate->pstate = NULL;
819 
820  /*
821  * Miscellaneous initialization
822  *
823  * create expression context for node
824  */
825  ExecAssignExprContext(estate, &scanstate->ss.ps);
826 
827  /*
828  * initialize child expressions
829  */
830  scanstate->ss.ps.qual =
831  ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
832  scanstate->bitmapqualorig =
833  ExecInitQual(node->bitmapqualorig, (PlanState *) scanstate);
834 
835  /*
836  * tuple table initialization
837  */
838  ExecInitResultTupleSlot(estate, &scanstate->ss.ps);
839  ExecInitScanTupleSlot(estate, &scanstate->ss);
840 
841  /*
842  * open the base relation and acquire appropriate lock on it.
843  */
844  currentRelation = ExecOpenScanRelation(estate, node->scan.scanrelid, eflags);
845 
846  /*
847  * Determine the maximum for prefetch_target. If the tablespace has a
848  * specific IO concurrency set, use that to compute the corresponding
849  * maximum value; otherwise, we already initialized to the value computed
850  * by the GUC machinery.
851  */
852  io_concurrency =
853  get_tablespace_io_concurrency(currentRelation->rd_rel->reltablespace);
854  if (io_concurrency != effective_io_concurrency)
855  {
856  double maximum;
857 
858  if (ComputeIoConcurrency(io_concurrency, &maximum))
859  scanstate->prefetch_maximum = rint(maximum);
860  }
861 
862  scanstate->ss.ss_currentRelation = currentRelation;
863 
864  /*
865  * Even though we aren't going to do a conventional seqscan, it is useful
866  * to create a HeapScanDesc --- most of the fields in it are usable.
867  */
868  scanstate->ss.ss_currentScanDesc = heap_beginscan_bm(currentRelation,
869  estate->es_snapshot,
870  0,
871  NULL);
872 
873  /*
874  * get the scan type from the relation descriptor.
875  */
876  ExecAssignScanType(&scanstate->ss, RelationGetDescr(currentRelation));
877 
878  /*
879  * Initialize result tuple type and projection info.
880  */
881  ExecAssignResultTypeFromTL(&scanstate->ss.ps);
882  ExecAssignScanProjectionInfo(&scanstate->ss);
883 
884  /*
885  * initialize child nodes
886  *
887  * We do this last because the child nodes will open indexscans on our
888  * relation's indexes, and we want to be sure we have acquired a lock on
889  * the relation first.
890  */
891  outerPlanState(scanstate) = ExecInitNode(outerPlan(node), estate, eflags);
892 
893  /*
894  * all done.
895  */
896  return scanstate;
897 }
List * qual
Definition: plannodes.h:145
int target_prefetch_pages
Definition: bufmgr.c:129
Plan plan
Definition: plannodes.h:328
ExprState * bitmapqualorig
Definition: execnodes.h:1348
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate)
Definition: execTuples.c:842
Index scanrelid
Definition: plannodes.h:329
#define RelationGetDescr(relation)
Definition: rel.h:428
TIDBitmap * tbm
Definition: execnodes.h:1349
int get_tablespace_io_concurrency(Oid spcid)
Definition: spccache.c:215
Snapshot es_snapshot
Definition: execnodes.h:429
Relation ss_currentRelation
Definition: execnodes.h:1102
EState * state
Definition: execnodes.h:849
Form_pg_class rd_rel
Definition: rel.h:114
int effective_io_concurrency
Definition: bufmgr.c:112
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:160
void ExecAssignResultTypeFromTL(PlanState *planstate)
Definition: execUtils.c:445
bool ComputeIoConcurrency(int io_concurrency, double *target)
Definition: bufmgr.c:467
PlanState ps
Definition: execnodes.h:1101
static TupleTableSlot * ExecBitmapHeapScan(PlanState *pstate)
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:237
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1362
void ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
Definition: execTuples.c:832
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:608
#define EXEC_FLAG_BACKWARD
Definition: executor.h:60
#define outerPlanState(node)
Definition: execnodes.h:893
double rint(double x)
Definition: rint.c:22
List * bitmapqualorig
Definition: plannodes.h:463
TBMIterateResult * tbmres
Definition: execnodes.h:1351
#define outerPlan(node)
Definition: plannodes.h:174
HeapScanDesc heap_beginscan_bm(Relation relation, Snapshot snapshot, int nkeys, ScanKey key)
Definition: heapam.c:1425
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:853
Plan * plan
Definition: execnodes.h:847
#define makeNode(_type_)
Definition: nodes.h:558
#define Assert(condition)
Definition: c.h:681
#define IsMVCCSnapshot(snapshot)
Definition: tqual.h:31
#define EXEC_FLAG_MARK
Definition: executor.h:61
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:423
TBMSharedIterator * shared_tbmiterator
Definition: execnodes.h:1360
TBMIterator * tbmiterator
Definition: execnodes.h:1350
ExprState * qual
Definition: execnodes.h:865
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1103
TBMIterator * prefetch_iterator
Definition: execnodes.h:1354
void ExecAssignScanType(ScanState *scanstate, TupleDesc tupDesc)
Definition: execUtils.c:545
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:139
void ExecReScanBitmapHeapScan ( BitmapHeapScanState node)

Definition at line 683 of file nodeBitmapHeapscan.c.

References PlanState::chgParam, ExecReScan(), ExecScanReScan(), heap_rescan(), BitmapHeapScanState::initialized, outerPlan, outerPlanState, BitmapHeapScanState::prefetch_iterator, BitmapHeapScanState::shared_prefetch_iterator, BitmapHeapScanState::shared_tbmiterator, BitmapHeapScanState::ss, ScanState::ss_currentScanDesc, BitmapHeapScanState::tbm, tbm_end_iterate(), tbm_end_shared_iterate(), tbm_free(), BitmapHeapScanState::tbmiterator, and BitmapHeapScanState::tbmres.

Referenced by ExecReScan().

684 {
686 
687  /* rescan to release any page pin */
688  heap_rescan(node->ss.ss_currentScanDesc, NULL);
689 
690  if (node->tbmiterator)
692  if (node->prefetch_iterator)
694  if (node->shared_tbmiterator)
696  if (node->shared_prefetch_iterator)
698  if (node->tbm)
699  tbm_free(node->tbm);
700  node->tbm = NULL;
701  node->tbmiterator = NULL;
702  node->tbmres = NULL;
703  node->prefetch_iterator = NULL;
704  node->initialized = false;
705  node->shared_tbmiterator = NULL;
706  node->shared_prefetch_iterator = NULL;
707 
708  ExecScanReScan(&node->ss);
709 
710  /*
711  * if chgParam of subnode is not null then plan will be re-scanned by
712  * first ExecProcNode.
713  */
714  if (outerPlan->chgParam == NULL)
715  ExecReScan(outerPlan);
716 }
void tbm_end_iterate(TBMIterator *iterator)
Definition: tidbitmap.c:1156
TIDBitmap * tbm
Definition: execnodes.h:1349
void ExecReScan(PlanState *node)
Definition: execAmi.c:76
#define outerPlanState(node)
Definition: execnodes.h:893
void tbm_free(TIDBitmap *tbm)
Definition: tidbitmap.c:332
void heap_rescan(HeapScanDesc scan, ScanKey key)
Definition: heapam.c:1521
TBMIterateResult * tbmres
Definition: execnodes.h:1351
Bitmapset * chgParam
Definition: execnodes.h:875
#define outerPlan(node)
Definition: plannodes.h:174
TBMSharedIterator * shared_tbmiterator
Definition: execnodes.h:1360
TBMIterator * tbmiterator
Definition: execnodes.h:1350
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1103
TBMIterator * prefetch_iterator
Definition: execnodes.h:1354
void ExecScanReScan(ScanState *node)
Definition: execScan.c:329
TBMSharedIterator * shared_prefetch_iterator
Definition: execnodes.h:1361
void tbm_end_shared_iterate(TBMSharedIterator *iterator)
Definition: tidbitmap.c:1168