Separate reinitialization of shared parallel-scan state from ExecReScan

Enterprise / PostgreSQL - Tom Lane [sss.pgh.pa.us] - 30 August 2017 13:18 EDT

Previously, the parallel executor logic did reinitialization of shared state within the ExecReScan code for parallel-aware scan nodes. This is problematic, because it means that the ExecReScan call has to occur synchronously (ie, during the parent Gather node's ReScan call). That is swimming very much against the tide so far as the ExecReScan machinery is concerned; the fact that it works at all today depends on a lot of fragile assumptions, such as that no plan node between Gather and a parallel-aware scan node is parameterized. Another objection is that because ExecReScan might be called in workers as well as the leader, hacky extra tests are needed in some places to prevent unwanted shared-state resets.

Hence, let's separate this code into two functions, a ReInitializeDSM call and the ReScan call proper. ReInitializeDSM is called only in the leader and is guaranteed to run before we start new workers. ReScan is returned to its traditional function of resetting only local state, which means that ExecReScan's usual habits of delaying or eliminating child rescan calls are safe again.

As with the preceding commit 7df2c1f8d, it doesn't seem to be necessary to make these changes in 9.6, which is a good thing because the FDW and CustomScan APIs are impacted.

Discussion: https://postgr.es/m/CAA4eK1JkByysFJNh9M349u_nNjqETuEnY_y1VUc_kJiU0bxtaQ@mail.gmail.com

41b0dd9 Separate reinitialization of shared parallel-scan state from ExecReScan.
doc/src/sgml/custom-scan.sgml | 29 +++++++--
doc/src/sgml/fdwhandler.sgml | 43 +++++++++----
src/backend/access/heap/heapam.c | 28 ++++-----
src/backend/executor/execParallel.c | 101 +++++++++++++++++++++++++-----
src/backend/executor/nodeBitmapHeapscan.c | 42 ++++++++-----
src/backend/executor/nodeCustom.c | 15 +++++
src/backend/executor/nodeForeignscan.c | 23 ++++++-
src/backend/executor/nodeGather.c | 29 ++++-----
src/backend/executor/nodeGatherMerge.c | 29 ++++-----
src/backend/executor/nodeIndexonlyscan.c | 29 +++++----
src/backend/executor/nodeIndexscan.c | 38 +++++------
src/backend/executor/nodeSeqscan.c | 16 +++++
src/backend/executor/nodeSort.c | 17 +++++
src/include/access/heapam.h | 1 +
src/include/executor/execParallel.h | 3 +-
src/include/executor/nodeBitmapHeapscan.h | 2 +
src/include/executor/nodeCustom.h | 2 +
src/include/executor/nodeForeignscan.h | 2 +
src/include/executor/nodeIndexonlyscan.h | 2 +
src/include/executor/nodeIndexscan.h | 1 +
src/include/executor/nodeSeqscan.h | 1 +
src/include/executor/nodeSort.h | 1 +
src/include/foreign/fdwapi.h | 4 ++
src/include/nodes/extensible.h | 3 +
24 files changed, 328 insertions(+), 133 deletions(-)

Upstream: git.postgresql.org


  • Share