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)
 
void ExecBitmapHeapRetrieveInstrumentation (BitmapHeapScanState *node)
 

Function Documentation

◆ ExecBitmapHeapEstimate()

void ExecBitmapHeapEstimate ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 814 of file nodeBitmapHeapscan.c.

816{
817 Size size;
818
820
821 /* account for instrumentation, if required */
822 if (node->ss.ps.instrument && pcxt->nworkers > 0)
823 {
824 size = add_size(size, offsetof(SharedBitmapHeapInstrumentation, sinstrument));
826 }
827
830}
#define MAXALIGN(LEN)
Definition: c.h:768
size_t Size
Definition: c.h:562
#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:488
Size mul_size(Size s1, Size s2)
Definition: shmem.c:505
static pg_noinline void Size size
Definition: slab.c:607
shm_toc_estimator estimator
Definition: parallel.h:41
Instrumentation * instrument
Definition: execnodes.h:1151
PlanState ps
Definition: execnodes.h:1588

References add_size(), ParallelContext::estimator, PlanState::instrument, MAXALIGN, mul_size(), ParallelContext::nworkers, ScanState::ps, shm_toc_estimate_chunk, shm_toc_estimate_keys, size, and BitmapHeapScanState::ss.

Referenced by ExecParallelEstimate().

◆ ExecBitmapHeapInitializeDSM()

void ExecBitmapHeapInitializeDSM ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 839 of file nodeBitmapHeapscan.c.

841{
843 SharedBitmapHeapInstrumentation *sinstrument = NULL;
844 dsa_area *dsa = node->ss.ps.state->es_query_dsa;
845 char *ptr;
846 Size size;
847
848 /* If there's no DSA, there are no workers; initialize nothing. */
849 if (dsa == NULL)
850 return;
851
853 if (node->ss.ps.instrument && pcxt->nworkers > 0)
854 {
855 size = add_size(size, offsetof(SharedBitmapHeapInstrumentation, sinstrument));
857 }
858
859 ptr = shm_toc_allocate(pcxt->toc, size);
860 pstate = (ParallelBitmapHeapState *) ptr;
861 ptr += MAXALIGN(sizeof(ParallelBitmapHeapState));
862 if (node->ss.ps.instrument && pcxt->nworkers > 0)
863 sinstrument = (SharedBitmapHeapInstrumentation *) ptr;
864
865 pstate->tbmiterator = 0;
866 pstate->prefetch_iterator = 0;
867
868 /* Initialize the mutex */
869 SpinLockInit(&pstate->mutex);
870 pstate->prefetch_pages = 0;
871 pstate->prefetch_target = -1;
872 pstate->state = BM_INITIAL;
873
874 ConditionVariableInit(&pstate->cv);
875
876 if (sinstrument)
877 {
878 sinstrument->num_workers = pcxt->nworkers;
879
880 /* ensure any unfilled slots will contain zeroes */
881 memset(sinstrument->sinstrument, 0,
883 }
884
885 shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, pstate);
886 node->pstate = pstate;
887 node->sinstrument = sinstrument;
888}
void ConditionVariableInit(ConditionVariable *cv)
@ BM_INITIAL
Definition: execnodes.h:1802
void * shm_toc_allocate(shm_toc *toc, Size nbytes)
Definition: shm_toc.c:88
void shm_toc_insert(shm_toc *toc, uint64 key, void *address)
Definition: shm_toc.c:171
#define SpinLockInit(lock)
Definition: spin.h:57
ParallelBitmapHeapState * pstate
Definition: execnodes.h:1875
SharedBitmapHeapInstrumentation * sinstrument
Definition: execnodes.h:1876
struct dsa_area * es_query_dsa
Definition: execnodes.h:733
SharedBitmapState state
Definition: execnodes.h:1826
dsa_pointer tbmiterator
Definition: execnodes.h:1821
ConditionVariable cv
Definition: execnodes.h:1827
dsa_pointer prefetch_iterator
Definition: execnodes.h:1822
shm_toc * toc
Definition: parallel.h:44
Plan * plan
Definition: execnodes.h:1141
EState * state
Definition: execnodes.h:1143
int plan_node_id
Definition: plannodes.h:152
BitmapHeapScanInstrumentation sinstrument[FLEXIBLE_ARRAY_MEMBER]
Definition: execnodes.h:1841
Definition: dsa.c:348

References add_size(), BM_INITIAL, ConditionVariableInit(), ParallelBitmapHeapState::cv, EState::es_query_dsa, PlanState::instrument, MAXALIGN, mul_size(), ParallelBitmapHeapState::mutex, SharedBitmapHeapInstrumentation::num_workers, ParallelContext::nworkers, PlanState::plan, Plan::plan_node_id, ParallelBitmapHeapState::prefetch_iterator, ParallelBitmapHeapState::prefetch_pages, ParallelBitmapHeapState::prefetch_target, ScanState::ps, BitmapHeapScanState::pstate, shm_toc_allocate(), shm_toc_insert(), SharedBitmapHeapInstrumentation::sinstrument, BitmapHeapScanState::sinstrument, size, 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 928 of file nodeBitmapHeapscan.c.

930{
931 char *ptr;
932
933 Assert(node->ss.ps.state->es_query_dsa != NULL);
934
935 ptr = shm_toc_lookup(pwcxt->toc, node->ss.ps.plan->plan_node_id, false);
936
937 node->pstate = (ParallelBitmapHeapState *) ptr;
938 ptr += MAXALIGN(sizeof(ParallelBitmapHeapState));
939
940 if (node->ss.ps.instrument)
942}
#define Assert(condition)
Definition: c.h:815
void * shm_toc_lookup(shm_toc *toc, uint64 key, bool noError)
Definition: shm_toc.c:232

References Assert, EState::es_query_dsa, PlanState::instrument, MAXALIGN, PlanState::plan, Plan::plan_node_id, ScanState::ps, BitmapHeapScanState::pstate, shm_toc_lookup(), BitmapHeapScanState::sinstrument, BitmapHeapScanState::ss, PlanState::state, and ParallelWorkerContext::toc.

Referenced by ExecParallelInitializeWorker().

◆ ExecBitmapHeapReInitializeDSM()

void ExecBitmapHeapReInitializeDSM ( BitmapHeapScanState node,
ParallelContext pcxt 
)

Definition at line 897 of file nodeBitmapHeapscan.c.

899{
900 ParallelBitmapHeapState *pstate = node->pstate;
901 dsa_area *dsa = node->ss.ps.state->es_query_dsa;
902
903 /* If there's no DSA, there are no workers; do nothing. */
904 if (dsa == NULL)
905 return;
906
907 pstate->state = BM_INITIAL;
908 pstate->prefetch_pages = 0;
909 pstate->prefetch_target = -1;
910
911 if (DsaPointerIsValid(pstate->tbmiterator))
912 tbm_free_shared_area(dsa, pstate->tbmiterator);
913
916
919}
#define InvalidDsaPointer
Definition: dsa.h:78
#define DsaPointerIsValid(x)
Definition: dsa.h:106
void tbm_free_shared_area(dsa_area *dsa, dsa_pointer dp)
Definition: tidbitmap.c:341

References BM_INITIAL, DsaPointerIsValid, EState::es_query_dsa, InvalidDsaPointer, ParallelBitmapHeapState::prefetch_iterator, ParallelBitmapHeapState::prefetch_pages, ParallelBitmapHeapState::prefetch_target, ScanState::ps, BitmapHeapScanState::pstate, BitmapHeapScanState::ss, PlanState::state, ParallelBitmapHeapState::state, tbm_free_shared_area(), and ParallelBitmapHeapState::tbmiterator.

Referenced by ExecParallelReInitializeDSM().

◆ ExecBitmapHeapRetrieveInstrumentation()

void ExecBitmapHeapRetrieveInstrumentation ( BitmapHeapScanState node)

Definition at line 951 of file nodeBitmapHeapscan.c.

952{
953 SharedBitmapHeapInstrumentation *sinstrument = node->sinstrument;
954 Size size;
955
956 if (sinstrument == NULL)
957 return;
958
959 size = offsetof(SharedBitmapHeapInstrumentation, sinstrument)
960 + sinstrument->num_workers * sizeof(BitmapHeapScanInstrumentation);
961
962 node->sinstrument = palloc(size);
963 memcpy(node->sinstrument, sinstrument, size);
964}
struct BitmapHeapScanInstrumentation BitmapHeapScanInstrumentation
void * palloc(Size size)
Definition: mcxt.c:1317

References SharedBitmapHeapInstrumentation::num_workers, palloc(), BitmapHeapScanState::sinstrument, and size.

Referenced by ExecParallelRetrieveInstrumentation().

◆ ExecEndBitmapHeapScan()

void ExecEndBitmapHeapScan ( BitmapHeapScanState node)

Definition at line 610 of file nodeBitmapHeapscan.c.

611{
612 TableScanDesc scanDesc;
613
614 /*
615 * When ending a parallel worker, copy the statistics gathered by the
616 * worker back into shared memory so that it can be picked up by the main
617 * process to report in EXPLAIN ANALYZE.
618 */
619 if (node->sinstrument != NULL && IsParallelWorker())
620 {
622
623 Assert(ParallelWorkerNumber <= node->sinstrument->num_workers);
625
626 /*
627 * Here we accumulate the stats rather than performing memcpy on
628 * node->stats into si. When a Gather/GatherMerge node finishes it
629 * will perform planner shutdown on the workers. On rescan it will
630 * spin up new workers which will have a new BitmapHeapScanState and
631 * zeroed stats.
632 */
633 si->exact_pages += node->stats.exact_pages;
634 si->lossy_pages += node->stats.lossy_pages;
635 }
636
637 /*
638 * extract information from the node
639 */
640 scanDesc = node->ss.ss_currentScanDesc;
641
642 /*
643 * close down subplans
644 */
646
647 if (scanDesc)
648 {
649 /*
650 * End iteration on iterators saved in scan descriptor if they have
651 * not already been cleaned up.
652 */
653 if (!tbm_exhausted(&scanDesc->st.rs_tbmiterator))
655
656 /*
657 * close table scan
658 */
659 table_endscan(scanDesc);
660 }
661
662 /* If we did not already clean up the prefetch iterator, do so now. */
663 if (!tbm_exhausted(&node->prefetch_iterator))
665
666 /*
667 * release bitmaps and buffers if any
668 */
669 if (node->tbm)
670 tbm_free(node->tbm);
671 if (node->pvmbuffer != InvalidBuffer)
673}
int ParallelWorkerNumber
Definition: parallel.c:114
#define InvalidBuffer
Definition: buf.h:25
void ReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:4866
void ExecEndNode(PlanState *node)
Definition: execProcnode.c:562
#define outerPlanState(node)
Definition: execnodes.h:1237
#define IsParallelWorker()
Definition: parallel.h:60
BitmapHeapScanInstrumentation stats
Definition: execnodes.h:1869
TIDBitmap * tbm
Definition: execnodes.h:1867
TBMIterator prefetch_iterator
Definition: execnodes.h:1870
struct TableScanDescData * ss_currentScanDesc
Definition: execnodes.h:1590
TBMIterator rs_tbmiterator
Definition: relscan.h:47
union TableScanDescData::@49 st
static void table_endscan(TableScanDesc scan)
Definition: tableam.h:1024
void tbm_free(TIDBitmap *tbm)
Definition: tidbitmap.c:322
void tbm_end_iterate(TBMIterator *iterator)
Definition: tidbitmap.c:1595
static bool tbm_exhausted(TBMIterator *iterator)
Definition: tidbitmap.h:96

References Assert, BitmapHeapScanInstrumentation::exact_pages, ExecEndNode(), InvalidBuffer, IsParallelWorker, BitmapHeapScanInstrumentation::lossy_pages, outerPlanState, ParallelWorkerNumber, BitmapHeapScanState::prefetch_iterator, BitmapHeapScanState::pvmbuffer, ReleaseBuffer(), TableScanDescData::rs_tbmiterator, SharedBitmapHeapInstrumentation::sinstrument, BitmapHeapScanState::sinstrument, BitmapHeapScanState::ss, ScanState::ss_currentScanDesc, TableScanDescData::st, BitmapHeapScanState::stats, table_endscan(), BitmapHeapScanState::tbm, tbm_end_iterate(), tbm_exhausted(), and tbm_free().

Referenced by ExecEndNode().

◆ ExecInitBitmapHeapScan()

BitmapHeapScanState * ExecInitBitmapHeapScan ( BitmapHeapScan node,
EState estate,
int  eflags 
)

Definition at line 682 of file nodeBitmapHeapscan.c.

683{
684 BitmapHeapScanState *scanstate;
685 Relation currentRelation;
686
687 /* check for unsupported flags */
689
690 /*
691 * Assert caller didn't ask for an unsafe snapshot --- see comments at
692 * head of file.
693 */
695
696 /*
697 * create state structure
698 */
699 scanstate = makeNode(BitmapHeapScanState);
700 scanstate->ss.ps.plan = (Plan *) node;
701 scanstate->ss.ps.state = estate;
703
704 scanstate->tbm = NULL;
705 scanstate->pvmbuffer = InvalidBuffer;
706
707 /* Zero the statistics counters */
708 memset(&scanstate->stats, 0, sizeof(BitmapHeapScanInstrumentation));
709
710 scanstate->prefetch_pages = 0;
711 scanstate->prefetch_target = -1;
712 scanstate->initialized = false;
713 scanstate->pstate = NULL;
714 scanstate->recheck = true;
715 scanstate->blockno = InvalidBlockNumber;
717
718 /*
719 * Miscellaneous initialization
720 *
721 * create expression context for node
722 */
723 ExecAssignExprContext(estate, &scanstate->ss.ps);
724
725 /*
726 * open the scan relation
727 */
728 currentRelation = ExecOpenScanRelation(estate, node->scan.scanrelid, eflags);
729
730 /*
731 * initialize child nodes
732 */
733 outerPlanState(scanstate) = ExecInitNode(outerPlan(node), estate, eflags);
734
735 /*
736 * get the scan type from the relation descriptor.
737 */
738 ExecInitScanTupleSlot(estate, &scanstate->ss,
739 RelationGetDescr(currentRelation),
740 table_slot_callbacks(currentRelation));
741
742 /*
743 * Initialize result type and projection.
744 */
745 ExecInitResultTypeTL(&scanstate->ss.ps);
746 ExecAssignScanProjectionInfo(&scanstate->ss);
747
748 /*
749 * initialize child expressions
750 */
751 scanstate->ss.ps.qual =
752 ExecInitQual(node->scan.plan.qual, (PlanState *) scanstate);
753 scanstate->bitmapqualorig =
754 ExecInitQual(node->bitmapqualorig, (PlanState *) scanstate);
755
756 /*
757 * Maximum number of prefetches for the tablespace if configured,
758 * otherwise the current value of the effective_io_concurrency GUC.
759 */
760 scanstate->prefetch_maximum =
761 get_tablespace_io_concurrency(currentRelation->rd_rel->reltablespace);
762
763 scanstate->ss.ss_currentRelation = currentRelation;
764
765 /*
766 * all done.
767 */
768 return scanstate;
769}
#define InvalidBlockNumber
Definition: block.h:33
ExprState * ExecInitQual(List *qual, PlanState *parent)
Definition: execExpr.c:229
PlanState * ExecInitNode(Plan *node, EState *estate, int eflags)
Definition: execProcnode.c:142
void ExecAssignScanProjectionInfo(ScanState *node)
Definition: execScan.c:81
void ExecInitScanTupleSlot(EState *estate, ScanState *scanstate, TupleDesc tupledesc, const TupleTableSlotOps *tts_ops)
Definition: execTuples.c:1998
void ExecInitResultTypeTL(PlanState *planstate)
Definition: execTuples.c:1942
void ExecAssignExprContext(EState *estate, PlanState *planstate)
Definition: execUtils.c:485
Relation ExecOpenScanRelation(EState *estate, Index scanrelid, int eflags)
Definition: execUtils.c:742
#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:155
#define outerPlan(node)
Definition: plannodes.h:183
#define RelationGetDescr(relation)
Definition: rel.h:531
#define IsMVCCSnapshot(snapshot)
Definition: snapmgr.h:55
int get_tablespace_io_concurrency(Oid spcid)
Definition: spccache.c:215
ExprState * bitmapqualorig
Definition: execnodes.h:1866
BlockNumber prefetch_blockno
Definition: execnodes.h:1879
BlockNumber blockno
Definition: execnodes.h:1878
List * bitmapqualorig
Definition: plannodes.h:544
Snapshot es_snapshot
Definition: execnodes.h:648
ExprState * qual
Definition: execnodes.h:1162
ExecProcNodeMtd ExecProcNode
Definition: execnodes.h:1147
Form_pg_class rd_rel
Definition: rel.h:111
Relation ss_currentRelation
Definition: execnodes.h:1589
Index scanrelid
Definition: plannodes.h:392
const TupleTableSlotOps * table_slot_callbacks(Relation relation)
Definition: tableam.c:58

References Assert, BitmapHeapScanState::bitmapqualorig, BitmapHeapScan::bitmapqualorig, BitmapHeapScanState::blockno, EState::es_snapshot, EXEC_FLAG_BACKWARD, EXEC_FLAG_MARK, ExecAssignExprContext(), ExecAssignScanProjectionInfo(), ExecBitmapHeapScan(), ExecInitNode(), ExecInitQual(), ExecInitResultTypeTL(), ExecInitScanTupleSlot(), ExecOpenScanRelation(), PlanState::ExecProcNode, get_tablespace_io_concurrency(), BitmapHeapScanState::initialized, InvalidBlockNumber, InvalidBuffer, IsMVCCSnapshot, makeNode, outerPlan, outerPlanState, PlanState::plan, BitmapHeapScanState::prefetch_blockno, BitmapHeapScanState::prefetch_maximum, BitmapHeapScanState::prefetch_pages, BitmapHeapScanState::prefetch_target, ScanState::ps, BitmapHeapScanState::pstate, BitmapHeapScanState::pvmbuffer, PlanState::qual, RelationData::rd_rel, BitmapHeapScanState::recheck, RelationGetDescr, BitmapHeapScan::scan, Scan::scanrelid, BitmapHeapScanState::ss, ScanState::ss_currentRelation, PlanState::state, BitmapHeapScanState::stats, table_slot_callbacks(), and BitmapHeapScanState::tbm.

Referenced by ExecInitNode().

◆ ExecReScanBitmapHeapScan()

void ExecReScanBitmapHeapScan ( BitmapHeapScanState node)

Definition at line 557 of file nodeBitmapHeapscan.c.

558{
560
562
563 if (scan)
564 {
565 /*
566 * End iteration on iterators saved in scan descriptor if they have
567 * not already been cleaned up.
568 */
569 if (!tbm_exhausted(&scan->st.rs_tbmiterator))
571
572 /* rescan to release any page pin */
574 }
575
576 /* If we did not already clean up the prefetch iterator, do so now. */
577 if (!tbm_exhausted(&node->prefetch_iterator))
579
580 /* release bitmaps and buffers if any */
581 if (node->tbm)
582 tbm_free(node->tbm);
583 if (node->pvmbuffer != InvalidBuffer)
585 node->tbm = NULL;
586 node->initialized = false;
587 node->pvmbuffer = InvalidBuffer;
588 node->recheck = true;
589 /* Only used for serial BHS */
592 node->prefetch_pages = 0;
593 node->prefetch_target = -1;
594
595 ExecScanReScan(&node->ss);
596
597 /*
598 * if chgParam of subnode is not null then plan will be re-scanned by
599 * first ExecProcNode.
600 */
601 if (outerPlan->chgParam == NULL)
603}
void ExecReScan(PlanState *node)
Definition: execAmi.c:76
void ExecScanReScan(ScanState *node)
Definition: execScan.c:108
static void table_rescan(TableScanDesc scan, struct ScanKeyData *key)
Definition: tableam.h:1033

References BitmapHeapScanState::blockno, ExecReScan(), ExecScanReScan(), BitmapHeapScanState::initialized, InvalidBlockNumber, InvalidBuffer, outerPlan, outerPlanState, BitmapHeapScanState::prefetch_blockno, BitmapHeapScanState::prefetch_iterator, BitmapHeapScanState::prefetch_pages, BitmapHeapScanState::prefetch_target, BitmapHeapScanState::pvmbuffer, BitmapHeapScanState::recheck, ReleaseBuffer(), TableScanDescData::rs_tbmiterator, BitmapHeapScanState::ss, ScanState::ss_currentScanDesc, TableScanDescData::st, table_rescan(), BitmapHeapScanState::tbm, tbm_end_iterate(), tbm_exhausted(), and tbm_free().

Referenced by ExecReScan().