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 ExecBitmapHeapInitializeWorker (BitmapHeapScanState *node, shm_toc *toc)
 

Function Documentation

void ExecBitmapHeapEstimate ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 958 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().

960 {
961  EState *estate = node->ss.ps.state;
962 
964  phs_snapshot_data),
966 
968  shm_toc_estimate_keys(&pcxt->estimator, 1);
969 }
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:1098
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:555
void ExecBitmapHeapInitializeDSM ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 978 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().

980 {
981  ParallelBitmapHeapState *pstate;
982  EState *estate = node->ss.ps.state;
983 
984  pstate = shm_toc_allocate(pcxt->toc, node->pscan_len);
985 
986  pstate->tbmiterator = 0;
987  pstate->prefetch_iterator = 0;
988 
989  /* Initialize the mutex */
990  SpinLockInit(&pstate->mutex);
991  pstate->prefetch_pages = 0;
992  pstate->prefetch_target = 0;
993  pstate->state = BM_INITIAL;
994 
995  ConditionVariableInit(&pstate->cv);
997 
998  shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pstate);
999  node->pstate = pstate;
1000 }
#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:1098
void ConditionVariableInit(ConditionVariable *cv)
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1359
void SerializeSnapshot(Snapshot snapshot, char *start_address)
Definition: snapmgr.c:2062
dsa_pointer tbmiterator
Definition: execnodes.h:1312
Plan * plan
Definition: execnodes.h:847
dsa_pointer prefetch_iterator
Definition: execnodes.h:1313
SharedBitmapState state
Definition: execnodes.h:1317
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
char phs_snapshot_data[FLEXIBLE_ARRAY_MEMBER]
Definition: execnodes.h:1319
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:171
ConditionVariable cv
Definition: execnodes.h:1318
shm_toc * toc
Definition: parallel.h:44
void ExecBitmapHeapInitializeWorker ( BitmapHeapScanState node,
shm_toc toc 
)

Definition at line 1009 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().

1010 {
1011  ParallelBitmapHeapState *pstate;
1012  Snapshot snapshot;
1013 
1014  pstate = shm_toc_lookup(toc, node->ss.ps.plan->plan_node_id, false);
1015  node->pstate = pstate;
1016 
1017  snapshot = RestoreSnapshot(pstate->phs_snapshot_data);
1018  heap_update_snapshot(node->ss.ss_currentScanDesc, snapshot);
1019 }
Snapshot RestoreSnapshot(char *start_address)
Definition: snapmgr.c:2121
void heap_update_snapshot(HeapScanDesc scan, Snapshot snapshot)
Definition: heapam.c:1776
int plan_node_id
Definition: plannodes.h:143
PlanState ps
Definition: execnodes.h:1098
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1359
Plan * plan
Definition: execnodes.h:847
char phs_snapshot_data[FLEXIBLE_ARRAY_MEMBER]
Definition: execnodes.h:1319
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1100
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232
void ExecEndBitmapHeapScan ( BitmapHeapScanState node)

Definition at line 740 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().

741 {
742  Relation relation;
743  HeapScanDesc scanDesc;
744 
745  /*
746  * extract information from the node
747  */
748  relation = node->ss.ss_currentRelation;
749  scanDesc = node->ss.ss_currentScanDesc;
750 
751  /*
752  * Free the exprcontext
753  */
754  ExecFreeExprContext(&node->ss.ps);
755 
756  /*
757  * clear out tuple table slots
758  */
761 
762  /*
763  * close down subplans
764  */
766 
767  /*
768  * release bitmap if any
769  */
770  if (node->tbmiterator)
772  if (node->prefetch_iterator)
774  if (node->tbm)
775  tbm_free(node->tbm);
776  if (node->shared_tbmiterator)
778  if (node->shared_prefetch_iterator)
780 
781  /*
782  * close heap scan
783  */
784  heap_endscan(scanDesc);
785 
786  /*
787  * close the heap relation.
788  */
789  ExecCloseScanRelation(relation);
790 }
void tbm_end_iterate(TBMIterator *iterator)
Definition: tidbitmap.c:1172
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1580
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:523
TIDBitmap * tbm
Definition: execnodes.h:1346
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1101
Relation ss_currentRelation
Definition: execnodes.h:1099
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:521
PlanState ps
Definition: execnodes.h:1098
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:880
#define outerPlanState(node)
Definition: execnodes.h:893
void tbm_free(TIDBitmap *tbm)
Definition: tidbitmap.c:348
void ExecCloseScanRelation(Relation scanrel)
Definition: execUtils.c:666
TBMSharedIterator * shared_tbmiterator
Definition: execnodes.h:1357
TBMIterator * tbmiterator
Definition: execnodes.h:1347
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1100
TBMIterator * prefetch_iterator
Definition: execnodes.h:1351
TBMSharedIterator * shared_prefetch_iterator
Definition: execnodes.h:1358
void tbm_end_shared_iterate(TBMSharedIterator *iterator)
Definition: tidbitmap.c:1184
BitmapHeapScanState* ExecInitBitmapHeapScan ( BitmapHeapScan node,
EState estate,
int  eflags 
)

Definition at line 799 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, NULL, 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().

800 {
801  BitmapHeapScanState *scanstate;
802  Relation currentRelation;
803  int io_concurrency;
804 
805  /* check for unsupported flags */
806  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
807 
808  /*
809  * Assert caller didn't ask for an unsafe snapshot --- see comments at
810  * head of file.
811  */
813 
814  /*
815  * create state structure
816  */
817  scanstate = makeNode(BitmapHeapScanState);
818  scanstate->ss.ps.plan = (Plan *) node;
819  scanstate->ss.ps.state = estate;
820  scanstate->ss.ps.ExecProcNode = ExecBitmapHeapScan;
821 
822  scanstate->tbm = NULL;
823  scanstate->tbmiterator = NULL;
824  scanstate->tbmres = NULL;
825  scanstate->exact_pages = 0;
826  scanstate->lossy_pages = 0;
827  scanstate->prefetch_iterator = NULL;
828  scanstate->prefetch_pages = 0;
829  scanstate->prefetch_target = 0;
830  /* may be updated below */
832  scanstate->pscan_len = 0;
833  scanstate->initialized = false;
834  scanstate->shared_tbmiterator = NULL;
835  scanstate->pstate = NULL;
836 
837  /*
838  * Miscellaneous initialization
839  *
840  * create expression context for node
841  */
842  ExecAssignExprContext(estate, &scanstate->ss.ps);
843 
844  /*
845  * initialize child expressions
846  */
847  scanstate->ss.ps.qual =
848  ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
849  scanstate->bitmapqualorig =
850  ExecInitQual(node->bitmapqualorig, (PlanState *) scanstate);
851 
852  /*
853  * tuple table initialization
854  */
855  ExecInitResultTupleSlot(estate, &scanstate->ss.ps);
856  ExecInitScanTupleSlot(estate, &scanstate->ss);
857 
858  /*
859  * open the base relation and acquire appropriate lock on it.
860  */
861  currentRelation = ExecOpenScanRelation(estate, node->scan.scanrelid, eflags);
862 
863  /*
864  * Determine the maximum for prefetch_target. If the tablespace has a
865  * specific IO concurrency set, use that to compute the corresponding
866  * maximum value; otherwise, we already initialized to the value computed
867  * by the GUC machinery.
868  */
869  io_concurrency =
870  get_tablespace_io_concurrency(currentRelation->rd_rel->reltablespace);
871  if (io_concurrency != effective_io_concurrency)
872  {
873  double maximum;
874 
875  if (ComputeIoConcurrency(io_concurrency, &maximum))
876  scanstate->prefetch_maximum = rint(maximum);
877  }
878 
879  scanstate->ss.ss_currentRelation = currentRelation;
880 
881  /*
882  * Even though we aren't going to do a conventional seqscan, it is useful
883  * to create a HeapScanDesc --- most of the fields in it are usable.
884  */
885  scanstate->ss.ss_currentScanDesc = heap_beginscan_bm(currentRelation,
886  estate->es_snapshot,
887  0,
888  NULL);
889 
890  /*
891  * get the scan type from the relation descriptor.
892  */
893  ExecAssignScanType(&scanstate->ss, RelationGetDescr(currentRelation));
894 
895  /*
896  * Initialize result tuple type and projection info.
897  */
898  ExecAssignResultTypeFromTL(&scanstate->ss.ps);
899  ExecAssignScanProjectionInfo(&scanstate->ss);
900 
901  /*
902  * initialize child nodes
903  *
904  * We do this last because the child nodes will open indexscans on our
905  * relation's indexes, and we want to be sure we have acquired a lock on
906  * the relation first.
907  */
908  outerPlanState(scanstate) = ExecInitNode(outerPlan(node), estate, eflags);
909 
910  /*
911  * all done.
912  */
913  return scanstate;
914 }
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:1345
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:1346
int get_tablespace_io_concurrency(Oid spcid)
Definition: spccache.c:215
Snapshot es_snapshot
Definition: execnodes.h:429
Relation ss_currentRelation
Definition: execnodes.h:1099
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:1098
static TupleTableSlot * ExecBitmapHeapScan(PlanState *pstate)
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:235
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1359
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:1348
#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:557
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:676
#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:1357
TBMIterator * tbmiterator
Definition: execnodes.h:1347
ExprState * qual
Definition: execnodes.h:865
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1100
TBMIterator * prefetch_iterator
Definition: execnodes.h:1351
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 BM_INITIAL, PlanState::chgParam, DsaPointerIsValid, EState::es_query_dsa, ExecReScan(), ExecScanReScan(), heap_rescan(), BitmapHeapScanState::initialized, InvalidDsaPointer, NULL, outerPlan, outerPlanState, ParallelBitmapHeapState::prefetch_iterator, BitmapHeapScanState::prefetch_iterator, ScanState::ps, BitmapHeapScanState::pstate, BitmapHeapScanState::shared_prefetch_iterator, BitmapHeapScanState::shared_tbmiterator, BitmapHeapScanState::ss, ScanState::ss_currentScanDesc, PlanState::state, ParallelBitmapHeapState::state, BitmapHeapScanState::tbm, tbm_end_iterate(), tbm_end_shared_iterate(), tbm_free(), tbm_free_shared_area(), ParallelBitmapHeapState::tbmiterator, BitmapHeapScanState::tbmiterator, and BitmapHeapScanState::tbmres.

Referenced by ExecReScan().

684 {
686 
687  /* rescan to release any page pin */
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;
707 
708  /* Reset parallel bitmap state, if present */
709  if (node->pstate)
710  {
711  dsa_area *dsa = node->ss.ps.state->es_query_dsa;
712 
713  node->pstate->state = BM_INITIAL;
714 
717 
720 
723  }
724 
725  ExecScanReScan(&node->ss);
726 
727  /*
728  * if chgParam of subnode is not null then plan will be re-scanned by
729  * first ExecProcNode.
730  */
731  if (outerPlan->chgParam == NULL)
732  ExecReScan(outerPlan);
733 }
struct dsa_area * es_query_dsa
Definition: execnodes.h:511
void tbm_end_iterate(TBMIterator *iterator)
Definition: tidbitmap.c:1172
#define InvalidDsaPointer
Definition: dsa.h:78
TIDBitmap * tbm
Definition: execnodes.h:1346
void ExecReScan(PlanState *node)
Definition: execAmi.c:76
EState * state
Definition: execnodes.h:849
PlanState ps
Definition: execnodes.h:1098
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1359
#define outerPlanState(node)
Definition: execnodes.h:893
void tbm_free(TIDBitmap *tbm)
Definition: tidbitmap.c:348
void heap_rescan(HeapScanDesc scan, ScanKey key)
Definition: heapam.c:1521
dsa_pointer tbmiterator
Definition: execnodes.h:1312
TBMIterateResult * tbmres
Definition: execnodes.h:1348
void tbm_free_shared_area(dsa_area *dsa, dsa_pointer dp)
Definition: tidbitmap.c:367
Bitmapset * chgParam
Definition: execnodes.h:875
#define outerPlan(node)
Definition: plannodes.h:174
dsa_pointer prefetch_iterator
Definition: execnodes.h:1313
#define NULL
Definition: c.h:229
SharedBitmapState state
Definition: execnodes.h:1317
TBMSharedIterator * shared_tbmiterator
Definition: execnodes.h:1357
TBMIterator * tbmiterator
Definition: execnodes.h:1347
#define DsaPointerIsValid(x)
Definition: dsa.h:81
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1100
Definition: dsa.c:354
TBMIterator * prefetch_iterator
Definition: execnodes.h:1351
void ExecScanReScan(ScanState *node)
Definition: execScan.c:327
TBMSharedIterator * shared_prefetch_iterator
Definition: execnodes.h:1358
void tbm_end_shared_iterate(TBMSharedIterator *iterator)
Definition: tidbitmap.c:1184