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)
 
TupleTableSlotExecBitmapHeapScan (BitmapHeapScanState *node)
 
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 952 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().

954 {
955  EState *estate = node->ss.ps.state;
956 
958  phs_snapshot_data),
960 
962  shm_toc_estimate_keys(&pcxt->estimator, 1);
963 }
shm_toc_estimator estimator
Definition: parallel.h:41
Snapshot es_snapshot
Definition: execnodes.h:429
EState * state
Definition: execnodes.h:834
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:51
PlanState ps
Definition: execnodes.h:1075
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 972 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().

974 {
975  ParallelBitmapHeapState *pstate;
976  EState *estate = node->ss.ps.state;
977 
978  pstate = shm_toc_allocate(pcxt->toc, node->pscan_len);
979 
980  pstate->tbmiterator = 0;
981  pstate->prefetch_iterator = 0;
982 
983  /* Initialize the mutex */
984  SpinLockInit(&pstate->mutex);
985  pstate->prefetch_pages = 0;
986  pstate->prefetch_target = 0;
987  pstate->state = BM_INITIAL;
988 
989  ConditionVariableInit(&pstate->cv);
991 
992  shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pstate);
993  node->pstate = pstate;
994 }
#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:834
PlanState ps
Definition: execnodes.h:1075
void ConditionVariableInit(ConditionVariable *cv)
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1336
void SerializeSnapshot(Snapshot snapshot, char *start_address)
Definition: snapmgr.c:2062
dsa_pointer tbmiterator
Definition: execnodes.h:1289
Plan * plan
Definition: execnodes.h:832
dsa_pointer prefetch_iterator
Definition: execnodes.h:1290
SharedBitmapState state
Definition: execnodes.h:1294
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:83
char phs_snapshot_data[FLEXIBLE_ARRAY_MEMBER]
Definition: execnodes.h:1296
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:161
ConditionVariable cv
Definition: execnodes.h:1295
shm_toc * toc
Definition: parallel.h:44
void ExecBitmapHeapInitializeWorker ( BitmapHeapScanState node,
shm_toc toc 
)

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

1004 {
1005  ParallelBitmapHeapState *pstate;
1006  Snapshot snapshot;
1007 
1008  pstate = shm_toc_lookup(toc, node->ss.ps.plan->plan_node_id, false);
1009  node->pstate = pstate;
1010 
1011  snapshot = RestoreSnapshot(pstate->phs_snapshot_data);
1012  heap_update_snapshot(node->ss.ss_currentScanDesc, snapshot);
1013 }
Snapshot RestoreSnapshot(char *start_address)
Definition: snapmgr.c:2116
void heap_update_snapshot(HeapScanDesc scan, Snapshot snapshot)
Definition: heapam.c:1760
int plan_node_id
Definition: plannodes.h:143
PlanState ps
Definition: execnodes.h:1075
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1336
Plan * plan
Definition: execnodes.h:832
char phs_snapshot_data[FLEXIBLE_ARRAY_MEMBER]
Definition: execnodes.h:1296
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1077
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:222
TupleTableSlot* ExecBitmapHeapScan ( BitmapHeapScanState node)

Definition at line 666 of file nodeBitmapHeapscan.c.

References BitmapHeapNext(), BitmapHeapRecheck(), ExecScan(), and BitmapHeapScanState::ss.

Referenced by ExecProcNode().

667 {
668  return ExecScan(&node->ss,
671 }
TupleTableSlot * ExecScan(ScanState *node, ExecScanAccessMtd accessMtd, ExecScanRecheckMtd recheckMtd)
Definition: execScan.c:121
TupleTableSlot *(* ExecScanAccessMtd)(ScanState *node)
Definition: executor.h:389
bool(* ExecScanRecheckMtd)(ScanState *node, TupleTableSlot *slot)
Definition: executor.h:390
static TupleTableSlot * BitmapHeapNext(BitmapHeapScanState *node)
static bool BitmapHeapRecheck(BitmapHeapScanState *node, TupleTableSlot *slot)
void ExecEndBitmapHeapScan ( BitmapHeapScanState node)

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

736 {
737  Relation relation;
738  HeapScanDesc scanDesc;
739 
740  /*
741  * extract information from the node
742  */
743  relation = node->ss.ss_currentRelation;
744  scanDesc = node->ss.ss_currentScanDesc;
745 
746  /*
747  * Free the exprcontext
748  */
749  ExecFreeExprContext(&node->ss.ps);
750 
751  /*
752  * clear out tuple table slots
753  */
756 
757  /*
758  * close down subplans
759  */
761 
762  /*
763  * release bitmap if any
764  */
765  if (node->tbmiterator)
767  if (node->prefetch_iterator)
769  if (node->tbm)
770  tbm_free(node->tbm);
771  if (node->shared_tbmiterator)
773  if (node->shared_prefetch_iterator)
775 
776  /*
777  * close heap scan
778  */
779  heap_endscan(scanDesc);
780 
781  /*
782  * close the heap relation.
783  */
784  ExecCloseScanRelation(relation);
785 }
void tbm_end_iterate(TBMIterator *iterator)
Definition: tidbitmap.c:1172
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1578
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:654
TIDBitmap * tbm
Definition: execnodes.h:1323
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1078
Relation ss_currentRelation
Definition: execnodes.h:1076
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:516
PlanState ps
Definition: execnodes.h:1075
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:861
#define outerPlanState(node)
Definition: execnodes.h:874
void tbm_free(TIDBitmap *tbm)
Definition: tidbitmap.c:348
void ExecCloseScanRelation(Relation scanrel)
Definition: execUtils.c:661
TBMSharedIterator * shared_tbmiterator
Definition: execnodes.h:1334
TBMIterator * tbmiterator
Definition: execnodes.h:1324
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1077
TBMIterator * prefetch_iterator
Definition: execnodes.h:1328
TBMSharedIterator * shared_prefetch_iterator
Definition: execnodes.h:1335
void tbm_end_shared_iterate(TBMSharedIterator *iterator)
Definition: tidbitmap.c:1184
BitmapHeapScanState* ExecInitBitmapHeapScan ( BitmapHeapScan node,
EState estate,
int  eflags 
)

Definition at line 794 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(), ExecInitNode(), ExecInitQual(), ExecInitResultTupleSlot(), ExecInitScanTupleSlot(), ExecOpenScanRelation(), 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().

795 {
796  BitmapHeapScanState *scanstate;
797  Relation currentRelation;
798  int io_concurrency;
799 
800  /* check for unsupported flags */
801  Assert(!(eflags & (EXEC_FLAG_BACKWARD | EXEC_FLAG_MARK)));
802 
803  /*
804  * Assert caller didn't ask for an unsafe snapshot --- see comments at
805  * head of file.
806  */
808 
809  /*
810  * create state structure
811  */
812  scanstate = makeNode(BitmapHeapScanState);
813  scanstate->ss.ps.plan = (Plan *) node;
814  scanstate->ss.ps.state = estate;
815 
816  scanstate->tbm = NULL;
817  scanstate->tbmiterator = NULL;
818  scanstate->tbmres = NULL;
819  scanstate->exact_pages = 0;
820  scanstate->lossy_pages = 0;
821  scanstate->prefetch_iterator = NULL;
822  scanstate->prefetch_pages = 0;
823  scanstate->prefetch_target = 0;
824  /* may be updated below */
826  scanstate->pscan_len = 0;
827  scanstate->initialized = false;
828  scanstate->shared_tbmiterator = NULL;
829  scanstate->pstate = NULL;
830 
831  /*
832  * Miscellaneous initialization
833  *
834  * create expression context for node
835  */
836  ExecAssignExprContext(estate, &scanstate->ss.ps);
837 
838  /*
839  * initialize child expressions
840  */
841  scanstate->ss.ps.qual =
842  ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
843  scanstate->bitmapqualorig =
844  ExecInitQual(node->bitmapqualorig, (PlanState *) scanstate);
845 
846  /*
847  * tuple table initialization
848  */
849  ExecInitResultTupleSlot(estate, &scanstate->ss.ps);
850  ExecInitScanTupleSlot(estate, &scanstate->ss);
851 
852  /*
853  * open the base relation and acquire appropriate lock on it.
854  */
855  currentRelation = ExecOpenScanRelation(estate, node->scan.scanrelid, eflags);
856 
857  /*
858  * Determine the maximum for prefetch_target. If the tablespace has a
859  * specific IO concurrency set, use that to compute the corresponding
860  * maximum value; otherwise, we already initialized to the value computed
861  * by the GUC machinery.
862  */
863  io_concurrency =
864  get_tablespace_io_concurrency(currentRelation->rd_rel->reltablespace);
865  if (io_concurrency != effective_io_concurrency)
866  {
867  double maximum;
868 
869  if (ComputeIoConcurrency(io_concurrency, &maximum))
870  scanstate->prefetch_maximum = rint(maximum);
871  }
872 
873  scanstate->ss.ss_currentRelation = currentRelation;
874 
875  /*
876  * Even though we aren't going to do a conventional seqscan, it is useful
877  * to create a HeapScanDesc --- most of the fields in it are usable.
878  */
879  scanstate->ss.ss_currentScanDesc = heap_beginscan_bm(currentRelation,
880  estate->es_snapshot,
881  0,
882  NULL);
883 
884  /*
885  * get the scan type from the relation descriptor.
886  */
887  ExecAssignScanType(&scanstate->ss, RelationGetDescr(currentRelation));
888 
889  /*
890  * Initialize result tuple type and projection info.
891  */
892  ExecAssignResultTypeFromTL(&scanstate->ss.ps);
893  ExecAssignScanProjectionInfo(&scanstate->ss);
894 
895  /*
896  * initialize child nodes
897  *
898  * We do this last because the child nodes will open indexscans on our
899  * relation's indexes, and we want to be sure we have acquired a lock on
900  * the relation first.
901  */
902  outerPlanState(scanstate) = ExecInitNode(outerPlan(node), estate, eflags);
903 
904  /*
905  * all done.
906  */
907  return scanstate;
908 }
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:1322
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:1323
int get_tablespace_io_concurrency(Oid spcid)
Definition: spccache.c:215
Snapshot es_snapshot
Definition: execnodes.h:429
Relation ss_currentRelation
Definition: execnodes.h:1076
EState * state
Definition: execnodes.h:834
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:440
bool ComputeIoConcurrency(int io_concurrency, double *target)
Definition: bufmgr.c:467
PlanState ps
Definition: execnodes.h:1075
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:235
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1336
void ExecInitResultTupleSlot(EState *estate, PlanState *planstate)
Definition: execTuples.c:832
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:603
#define EXEC_FLAG_BACKWARD
Definition: executor.h:60
#define outerPlanState(node)
Definition: execnodes.h:874
double rint(double x)
Definition: rint.c:22
List * bitmapqualorig
Definition: plannodes.h:463
TBMIterateResult * tbmres
Definition: execnodes.h:1325
#define outerPlan(node)
Definition: plannodes.h:174
HeapScanDesc heap_beginscan_bm(Relation relation, Snapshot snapshot, int nkeys, ScanKey key)
Definition: heapam.c:1419
Plan * plan
Definition: execnodes.h:832
#define makeNode(_type_)
Definition: nodes.h:557
#define NULL
Definition: c.h:229
#define Assert(condition)
Definition: c.h:675
#define IsMVCCSnapshot(snapshot)
Definition: tqual.h:31
#define EXEC_FLAG_MARK
Definition: executor.h:61
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:418
TBMSharedIterator * shared_tbmiterator
Definition: execnodes.h:1334
TBMIterator * tbmiterator
Definition: execnodes.h:1324
ExprState * qual
Definition: execnodes.h:846
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1077
TBMIterator * prefetch_iterator
Definition: execnodes.h:1328
void ExecAssignScanType(ScanState *scanstate, TupleDesc tupDesc)
Definition: execUtils.c:540
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:140
void ExecReScanBitmapHeapScan ( BitmapHeapScanState node)

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

679 {
681 
682  /* rescan to release any page pin */
684 
685  if (node->tbmiterator)
687  if (node->prefetch_iterator)
689  if (node->shared_tbmiterator)
691  if (node->shared_prefetch_iterator)
693  if (node->tbm)
694  tbm_free(node->tbm);
695  node->tbm = NULL;
696  node->tbmiterator = NULL;
697  node->tbmres = NULL;
698  node->prefetch_iterator = NULL;
699  node->initialized = false;
700  node->shared_tbmiterator = NULL;
702 
703  /* Reset parallel bitmap state, if present */
704  if (node->pstate)
705  {
706  dsa_area *dsa = node->ss.ps.state->es_query_dsa;
707 
708  node->pstate->state = BM_INITIAL;
709 
712 
715 
718  }
719 
720  ExecScanReScan(&node->ss);
721 
722  /*
723  * if chgParam of subnode is not null then plan will be re-scanned by
724  * first ExecProcNode.
725  */
726  if (outerPlan->chgParam == NULL)
727  ExecReScan(outerPlan);
728 }
struct dsa_area * es_query_dsa
Definition: execnodes.h:508
void tbm_end_iterate(TBMIterator *iterator)
Definition: tidbitmap.c:1172
#define InvalidDsaPointer
Definition: dsa.h:78
TIDBitmap * tbm
Definition: execnodes.h:1323
void ExecReScan(PlanState *node)
Definition: execAmi.c:75
EState * state
Definition: execnodes.h:834
PlanState ps
Definition: execnodes.h:1075
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1336
#define outerPlanState(node)
Definition: execnodes.h:874
void tbm_free(TIDBitmap *tbm)
Definition: tidbitmap.c:348
void heap_rescan(HeapScanDesc scan, ScanKey key)
Definition: heapam.c:1515
dsa_pointer tbmiterator
Definition: execnodes.h:1289
TBMIterateResult * tbmres
Definition: execnodes.h:1325
void tbm_free_shared_area(dsa_area *dsa, dsa_pointer dp)
Definition: tidbitmap.c:367
Bitmapset * chgParam
Definition: execnodes.h:856
#define outerPlan(node)
Definition: plannodes.h:174
dsa_pointer prefetch_iterator
Definition: execnodes.h:1290
#define NULL
Definition: c.h:229
SharedBitmapState state
Definition: execnodes.h:1294
TBMSharedIterator * shared_tbmiterator
Definition: execnodes.h:1334
TBMIterator * tbmiterator
Definition: execnodes.h:1324
#define DsaPointerIsValid(x)
Definition: dsa.h:81
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1077
Definition: dsa.c:354
TBMIterator * prefetch_iterator
Definition: execnodes.h:1328
void ExecScanReScan(ScanState *node)
Definition: execScan.c:327
TBMSharedIterator * shared_prefetch_iterator
Definition: execnodes.h:1335
void tbm_end_shared_iterate(TBMSharedIterator *iterator)
Definition: tidbitmap.c:1184