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

958 {
959  EState *estate = node->ss.ps.state;
960 
962  phs_snapshot_data),
964 
966  shm_toc_estimate_keys(&pcxt->estimator, 1);
967 }
shm_toc_estimator estimator
Definition: parallel.h:42
Snapshot es_snapshot
Definition: execnodes.h:372
EState * state
Definition: execnodes.h:1051
#define shm_toc_estimate_chunk(e, sz)
Definition: shm_toc.h:49
PlanState ps
Definition: execnodes.h:1290
Size EstimateSnapshotSpace(Snapshot snap)
Definition: snapmgr.c:1992
Size add_size(Size s1, Size s2)
Definition: shmem.c:475
#define shm_toc_estimate_keys(e, cnt)
Definition: shm_toc.h:52
#define offsetof(type, field)
Definition: c.h:555
void ExecBitmapHeapInitializeDSM ( BitmapHeapScanState node,
ParallelContext pcxt 
)

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

978 {
979  ParallelBitmapHeapState *pstate;
980  EState *estate = node->ss.ps.state;
981 
982  pstate = shm_toc_allocate(pcxt->toc, node->pscan_len);
983 
984  pstate->tbmiterator = 0;
985  pstate->prefetch_iterator = 0;
986 
987  /* Initialize the mutex */
988  SpinLockInit(&pstate->mutex);
989  pstate->prefetch_pages = 0;
990  pstate->prefetch_target = 0;
991  pstate->state = BM_INITIAL;
992 
993  ConditionVariableInit(&pstate->cv);
995 
996  shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pstate);
997  node->pstate = pstate;
998 }
#define SpinLockInit(lock)
Definition: spin.h:60
int plan_node_id
Definition: plannodes.h:131
Snapshot es_snapshot
Definition: execnodes.h:372
EState * state
Definition: execnodes.h:1051
PlanState ps
Definition: execnodes.h:1290
void ConditionVariableInit(ConditionVariable *cv)
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1551
void SerializeSnapshot(Snapshot snapshot, char *start_address)
Definition: snapmgr.c:2016
dsa_pointer tbmiterator
Definition: execnodes.h:1504
Plan * plan
Definition: execnodes.h:1049
dsa_pointer prefetch_iterator
Definition: execnodes.h:1505
SharedBitmapState state
Definition: execnodes.h:1509
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:83
char phs_snapshot_data[FLEXIBLE_ARRAY_MEMBER]
Definition: execnodes.h:1511
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:161
ConditionVariable cv
Definition: execnodes.h:1510
shm_toc * toc
Definition: parallel.h:45
void ExecBitmapHeapInitializeWorker ( BitmapHeapScanState node,
shm_toc toc 
)

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

1008 {
1009  ParallelBitmapHeapState *pstate;
1010  Snapshot snapshot;
1011 
1012  pstate = shm_toc_lookup(toc, node->ss.ps.plan->plan_node_id);
1013  node->pstate = pstate;
1014 
1015  snapshot = RestoreSnapshot(pstate->phs_snapshot_data);
1016  heap_update_snapshot(node->ss.ss_currentScanDesc, snapshot);
1017 }
Snapshot RestoreSnapshot(char *start_address)
Definition: snapmgr.c:2075
void heap_update_snapshot(HeapScanDesc scan, Snapshot snapshot)
Definition: heapam.c:1763
int plan_node_id
Definition: plannodes.h:131
PlanState ps
Definition: execnodes.h:1290
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1551
void * shm_toc_lookup(shm_toc *toc, uint64 key)
Definition: shm_toc.c:218
Plan * plan
Definition: execnodes.h:1049
char phs_snapshot_data[FLEXIBLE_ARRAY_MEMBER]
Definition: execnodes.h:1511
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1292
TupleTableSlot* ExecBitmapHeapScan ( BitmapHeapScanState node)

Definition at line 665 of file nodeBitmapHeapscan.c.

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

Referenced by ExecProcNode().

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

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

735 {
736  Relation relation;
737  HeapScanDesc scanDesc;
738 
739  /*
740  * extract information from the node
741  */
742  relation = node->ss.ss_currentRelation;
743  scanDesc = node->ss.ss_currentScanDesc;
744 
745  /*
746  * Free the exprcontext
747  */
748  ExecFreeExprContext(&node->ss.ps);
749 
750  /*
751  * clear out tuple table slots
752  */
755 
756  /*
757  * close down subplans
758  */
760 
761  /*
762  * release bitmap if any
763  */
764  if (node->tbmiterator)
766  if (node->prefetch_iterator)
768  if (node->tbm)
769  tbm_free(node->tbm);
770  if (node->shared_tbmiterator)
772  if (node->shared_prefetch_iterator)
774 
775  /*
776  * close heap scan
777  */
778  heap_endscan(scanDesc);
779 
780  /*
781  * close the heap relation.
782  */
783  ExecCloseScanRelation(relation);
784 }
void tbm_end_iterate(TBMIterator *iterator)
Definition: tidbitmap.c:1170
void heap_endscan(HeapScanDesc scan)
Definition: heapam.c:1581
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:644
TIDBitmap * tbm
Definition: execnodes.h:1538
TupleTableSlot * ExecClearTuple(TupleTableSlot *slot)
Definition: execTuples.c:439
TupleTableSlot * ss_ScanTupleSlot
Definition: execnodes.h:1293
Relation ss_currentRelation
Definition: execnodes.h:1291
void ExecFreeExprContext(PlanState *planstate)
Definition: execUtils.c:686
PlanState ps
Definition: execnodes.h:1290
TupleTableSlot * ps_ResultTupleSlot
Definition: execnodes.h:1079
#define outerPlanState(node)
Definition: execnodes.h:1092
void tbm_free(TIDBitmap *tbm)
Definition: tidbitmap.c:348
void ExecCloseScanRelation(Relation scanrel)
Definition: execUtils.c:831
TBMSharedIterator * shared_tbmiterator
Definition: execnodes.h:1549
TBMIterator * tbmiterator
Definition: execnodes.h:1539
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1292
TBMIterator * prefetch_iterator
Definition: execnodes.h:1543
TBMSharedIterator * shared_prefetch_iterator
Definition: execnodes.h:1550
void tbm_end_shared_iterate(TBMSharedIterator *iterator)
Definition: tidbitmap.c:1182
BitmapHeapScanState* ExecInitBitmapHeapScan ( BitmapHeapScan node,
EState estate,
int  eflags 
)

Definition at line 793 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(), ExecInitExpr(), ExecInitNode(), 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, Plan::targetlist, PlanState::targetlist, BitmapHeapScanState::tbm, BitmapHeapScanState::tbmiterator, and BitmapHeapScanState::tbmres.

Referenced by ExecInitNode().

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

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

678 {
680 
681  /* rescan to release any page pin */
683 
684  if (node->tbmiterator)
686  if (node->prefetch_iterator)
688  if (node->shared_tbmiterator)
690  if (node->shared_prefetch_iterator)
692  if (node->tbm)
693  tbm_free(node->tbm);
694  node->tbm = NULL;
695  node->tbmiterator = NULL;
696  node->tbmres = NULL;
697  node->prefetch_iterator = NULL;
698  node->initialized = false;
699  node->shared_tbmiterator = NULL;
701 
702  /* Reset parallel bitmap state, if present */
703  if (node->pstate)
704  {
705  dsa_area *dsa = node->ss.ps.state->es_query_dsa;
706 
707  node->pstate->state = BM_INITIAL;
708 
711 
714 
717  }
718 
719  ExecScanReScan(&node->ss);
720 
721  /*
722  * if chgParam of subnode is not null then plan will be re-scanned by
723  * first ExecProcNode.
724  */
725  if (outerPlan->chgParam == NULL)
726  ExecReScan(outerPlan);
727 }
struct dsa_area * es_query_dsa
Definition: execnodes.h:439
void tbm_end_iterate(TBMIterator *iterator)
Definition: tidbitmap.c:1170
#define InvalidDsaPointer
Definition: dsa.h:78
TIDBitmap * tbm
Definition: execnodes.h:1538
void ExecReScan(PlanState *node)
Definition: execAmi.c:74
EState * state
Definition: execnodes.h:1051
PlanState ps
Definition: execnodes.h:1290
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1551
#define outerPlanState(node)
Definition: execnodes.h:1092
void tbm_free(TIDBitmap *tbm)
Definition: tidbitmap.c:348
void heap_rescan(HeapScanDesc scan, ScanKey key)
Definition: heapam.c:1518
dsa_pointer tbmiterator
Definition: execnodes.h:1504
TBMIterateResult * tbmres
Definition: execnodes.h:1540
void tbm_free_shared_area(dsa_area *dsa, dsa_pointer dp)
Definition: tidbitmap.c:367
Bitmapset * chgParam
Definition: execnodes.h:1074
#define outerPlan(node)
Definition: plannodes.h:162
dsa_pointer prefetch_iterator
Definition: execnodes.h:1505
#define NULL
Definition: c.h:229
SharedBitmapState state
Definition: execnodes.h:1509
TBMSharedIterator * shared_tbmiterator
Definition: execnodes.h:1549
TBMIterator * tbmiterator
Definition: execnodes.h:1539
#define DsaPointerIsValid(x)
Definition: dsa.h:81
HeapScanDesc ss_currentScanDesc
Definition: execnodes.h:1292
Definition: dsa.c:354
TBMIterator * prefetch_iterator
Definition: execnodes.h:1543
void ExecScanReScan(ScanState *node)
Definition: execScan.c:327
TBMSharedIterator * shared_prefetch_iterator
Definition: execnodes.h:1550
void tbm_end_shared_iterate(TBMSharedIterator *iterator)
Definition: tidbitmap.c:1182