/* * index_parallelscan_initialize - initialize parallel scan * * We initialize both the ParallelIndexScanDesc proper and the AM-specific * information which follows it. * * This function calls access method specific initialization routine to * initialize am specific information. Call this just once in the leader * process; then, individual workers attach via index_beginscan_parallel. */ void index_parallelscan_initialize(Relation heapRelation, Relation indexRelation, Snapshot snapshot, ParallelIndexScanDesc target) { Size offset; RELATION_CHECKS; offset = add_size(offsetof(ParallelIndexScanDescData, ps_snapshot_data), EstimateSnapshotSpace(snapshot)); offset = MAXALIGN(offset); target->ps_relid = RelationGetRelid(heapRelation); target->ps_indexid = RelationGetRelid(indexRelation); target->ps_offset = offset; SerializeSnapshot(snapshot, target->ps_snapshot_data); /* aminitparallelscan is optional; assume no-op if not provided by AM */ if (indexRelation->rd_amroutine->aminitparallelscan != NULL) { void *amtarget; amtarget = OffsetToPointer(target, offset); indexRelation->rd_amroutine->aminitparallelscan(amtarget); } }
/* ---------------------------------------------------------------- * ExecBitmapHeapEstimate * * estimates the space required to serialize bitmap scan node. * ---------------------------------------------------------------- */ void ExecBitmapHeapEstimate(BitmapHeapScanState *node, ParallelContext *pcxt) { EState *estate = node->ss.ps.state; node->pscan_len = add_size(offsetof(ParallelBitmapHeapState, phs_snapshot_data), EstimateSnapshotSpace(estate->es_snapshot)); shm_toc_estimate_chunk(&pcxt->estimator, node->pscan_len); shm_toc_estimate_keys(&pcxt->estimator, 1); }
Size table_parallelscan_estimate(Relation rel, Snapshot snapshot) { Size sz = 0; if (IsMVCCSnapshot(snapshot)) sz = add_size(sz, EstimateSnapshotSpace(snapshot)); else Assert(snapshot == SnapshotAny); sz = add_size(sz, rel->rd_tableam->parallelscan_estimate(rel)); return sz; }
/* * index_parallelscan_estimate - estimate shared memory for parallel scan * * Currently, we don't pass any information to the AM-specific estimator, * so it can probably only return a constant. In the future, we might need * to pass more information. */ Size index_parallelscan_estimate(Relation indexRelation, Snapshot snapshot) { Size nbytes; RELATION_CHECKS; nbytes = offsetof(ParallelIndexScanDescData, ps_snapshot_data); nbytes = add_size(nbytes, EstimateSnapshotSpace(snapshot)); nbytes = MAXALIGN(nbytes); /* * If amestimateparallelscan is not provided, assume there is no * AM-specific data needed. (It's hard to believe that could work, but * it's easy enough to cater to it here.) */ if (indexRelation->rd_amroutine->amestimateparallelscan != NULL) nbytes = add_size(nbytes, indexRelation->rd_amroutine->amestimateparallelscan()); return nbytes; }