diff options
Diffstat (limited to 'src/backend/executor/nodeBitmapIndexscan.c')
-rw-r--r-- | src/backend/executor/nodeBitmapIndexscan.c | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/src/backend/executor/nodeBitmapIndexscan.c b/src/backend/executor/nodeBitmapIndexscan.c index 0b32c3a022f..abbb033881a 100644 --- a/src/backend/executor/nodeBitmapIndexscan.c +++ b/src/backend/executor/nodeBitmapIndexscan.c @@ -184,6 +184,27 @@ ExecEndBitmapIndexScan(BitmapIndexScanState *node) indexScanDesc = node->biss_ScanDesc; /* + * When ending a parallel worker, copy the statistics gathered by the + * worker back into shared memory so that it can be picked up by the main + * process to report in EXPLAIN ANALYZE + */ + if (node->biss_SharedInfo != NULL && IsParallelWorker()) + { + IndexScanInstrumentation *winstrument; + + Assert(ParallelWorkerNumber <= node->biss_SharedInfo->num_workers); + winstrument = &node->biss_SharedInfo->winstrument[ParallelWorkerNumber]; + + /* + * We have to accumulate the stats rather than performing a memcpy. + * When a Gather/GatherMerge node finishes it will perform planner + * shutdown on the workers. On rescan it will spin up new workers + * which will have a new BitmapIndexScanState and zeroed stats. + */ + winstrument->nsearches += node->biss_Instrument.nsearches; + } + + /* * close the index relation (no-op if we didn't open it) */ if (indexScanDesc) @@ -302,6 +323,7 @@ ExecInitBitmapIndexScan(BitmapIndexScan *node, EState *estate, int eflags) indexstate->biss_ScanDesc = index_beginscan_bitmap(indexstate->biss_RelationDesc, estate->es_snapshot, + &indexstate->biss_Instrument, indexstate->biss_NumScanKeys); /* @@ -319,3 +341,97 @@ ExecInitBitmapIndexScan(BitmapIndexScan *node, EState *estate, int eflags) */ return indexstate; } + +/* ---------------------------------------------------------------- + * ExecBitmapIndexScanEstimate + * + * Compute the amount of space we'll need in the parallel + * query DSM, and inform pcxt->estimator about our needs. + * ---------------------------------------------------------------- + */ +void +ExecBitmapIndexScanEstimate(BitmapIndexScanState *node, ParallelContext *pcxt) +{ + Size size; + + /* + * Parallel bitmap index scans are not supported, but we still need to + * store the scan's instrumentation in DSM during parallel query + */ + if (!node->ss.ps.instrument || pcxt->nworkers == 0) + return; + + size = offsetof(SharedIndexScanInstrumentation, winstrument) + + pcxt->nworkers * sizeof(IndexScanInstrumentation); + shm_toc_estimate_chunk(&pcxt->estimator, size); + shm_toc_estimate_keys(&pcxt->estimator, 1); +} + +/* ---------------------------------------------------------------- + * ExecBitmapIndexScanInitializeDSM + * + * Set up bitmap index scan shared instrumentation. + * ---------------------------------------------------------------- + */ +void +ExecBitmapIndexScanInitializeDSM(BitmapIndexScanState *node, + ParallelContext *pcxt) +{ + Size size; + + /* don't need this if not instrumenting or no workers */ + if (!node->ss.ps.instrument || pcxt->nworkers == 0) + return; + + size = offsetof(SharedIndexScanInstrumentation, winstrument) + + pcxt->nworkers * sizeof(IndexScanInstrumentation); + node->biss_SharedInfo = + (SharedIndexScanInstrumentation *) shm_toc_allocate(pcxt->toc, + size); + shm_toc_insert(pcxt->toc, node->ss.ps.plan->plan_node_id, + node->biss_SharedInfo); + + /* Each per-worker area must start out as zeroes */ + memset(node->biss_SharedInfo, 0, size); + node->biss_SharedInfo->num_workers = pcxt->nworkers; +} + +/* ---------------------------------------------------------------- + * ExecBitmapIndexScanInitializeWorker + * + * Copy relevant information from TOC into planstate. + * ---------------------------------------------------------------- + */ +void +ExecBitmapIndexScanInitializeWorker(BitmapIndexScanState *node, + ParallelWorkerContext *pwcxt) +{ + /* don't need this if not instrumenting */ + if (!node->ss.ps.instrument) + return; + + node->biss_SharedInfo = (SharedIndexScanInstrumentation *) + shm_toc_lookup(pwcxt->toc, node->ss.ps.plan->plan_node_id, false); +} + +/* ---------------------------------------------------------------- + * ExecBitmapIndexScanRetrieveInstrumentation + * + * Transfer bitmap index scan statistics from DSM to private memory. + * ---------------------------------------------------------------- + */ +void +ExecBitmapIndexScanRetrieveInstrumentation(BitmapIndexScanState *node) +{ + SharedIndexScanInstrumentation *SharedInfo = node->biss_SharedInfo; + size_t size; + + if (SharedInfo == NULL) + return; + + /* Create a copy of SharedInfo in backend-local memory */ + size = offsetof(SharedIndexScanInstrumentation, winstrument) + + SharedInfo->num_workers * sizeof(IndexScanInstrumentation); + node->biss_SharedInfo = palloc(size); + memcpy(node->biss_SharedInfo, SharedInfo, size); +} |