summaryrefslogtreecommitdiff
path: root/src/backend/nodes
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2017-08-30 09:29:55 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2017-08-30 09:29:55 -0400
commit7df2c1f8daeb361133ac8bdeaf59ceb0484e315a (patch)
tree8d58c67ad06882045893662c5125d17836cd1883 /src/backend/nodes
parent00f6d5c2c3ae2f6d198e41800e5edcf0150d485b (diff)
downloadpostgresql-7df2c1f8daeb361133ac8bdeaf59ceb0484e315a.tar.gz
Force rescanning of parallel-aware scan nodes below a Gather[Merge].
The ExecReScan machinery contains various optimizations for postponing or skipping rescans of plan subtrees; for example a HashAgg node may conclude that it can re-use the table it built before, instead of re-reading its input subtree. But that is wrong if the input contains a parallel-aware table scan node, since the portion of the table scanned by the leader process is likely to vary from one rescan to the next. This explains the timing-dependent buildfarm failures we saw after commit a2b70c89c. The established mechanism for showing that a plan node's output is potentially variable is to mark it as depending on some runtime Param. Hence, to fix this, invent a dummy Param (one that has a PARAM_EXEC parameter number, but carries no actual value) associated with each Gather or GatherMerge node, mark parallel-aware nodes below that node as dependent on that Param, and arrange for ExecReScanGather[Merge] to flag that Param as changed whenever the Gather[Merge] node is rescanned. This solution breaks an undocumented assumption made by the parallel executor logic, namely that all rescans of nodes below a Gather[Merge] will happen synchronously during the ReScan of the top node itself. But that's fundamentally contrary to the design of the ExecReScan code, and so was doomed to fail someday anyway (even if you want to argue that the bug being fixed here wasn't a failure of that assumption). A follow-on patch will address that issue. In the meantime, the worst that's expected to happen is that given very bad timing luck, the leader might have to do all the work during a rescan, because workers think they have nothing to do, if they are able to start up before the eventual ReScan of the leader's parallel-aware table scan node has reset the shared scan state. Although this problem exists in 9.6, there does not seem to be any way for it to manifest there. Without GatherMerge, it seems that a plan tree that has a rescan-short-circuiting node below Gather will always also have one above it that will short-circuit in the same cases, preventing the Gather from being rescanned. Hence we won't take the risk of back-patching this change into 9.6. But v10 needs it. Discussion: https://postgr.es/m/CAA4eK1JkByysFJNh9M349u_nNjqETuEnY_y1VUc_kJiU0bxtaQ@mail.gmail.com
Diffstat (limited to 'src/backend/nodes')
-rw-r--r--src/backend/nodes/copyfuncs.c2
-rw-r--r--src/backend/nodes/outfuncs.c2
-rw-r--r--src/backend/nodes/readfuncs.c2
3 files changed, 6 insertions, 0 deletions
diff --git a/src/backend/nodes/copyfuncs.c b/src/backend/nodes/copyfuncs.c
index 72041693df..f9ddf4ed76 100644
--- a/src/backend/nodes/copyfuncs.c
+++ b/src/backend/nodes/copyfuncs.c
@@ -361,6 +361,7 @@ _copyGather(const Gather *from)
* copy remainder of node
*/
COPY_SCALAR_FIELD(num_workers);
+ COPY_SCALAR_FIELD(rescan_param);
COPY_SCALAR_FIELD(single_copy);
COPY_SCALAR_FIELD(invisible);
@@ -384,6 +385,7 @@ _copyGatherMerge(const GatherMerge *from)
* copy remainder of node
*/
COPY_SCALAR_FIELD(num_workers);
+ COPY_SCALAR_FIELD(rescan_param);
COPY_SCALAR_FIELD(numCols);
COPY_POINTER_FIELD(sortColIdx, from->numCols * sizeof(AttrNumber));
COPY_POINTER_FIELD(sortOperators, from->numCols * sizeof(Oid));
diff --git a/src/backend/nodes/outfuncs.c b/src/backend/nodes/outfuncs.c
index 5ce3c7c599..9ee3e23761 100644
--- a/src/backend/nodes/outfuncs.c
+++ b/src/backend/nodes/outfuncs.c
@@ -479,6 +479,7 @@ _outGather(StringInfo str, const Gather *node)
_outPlanInfo(str, (const Plan *) node);
WRITE_INT_FIELD(num_workers);
+ WRITE_INT_FIELD(rescan_param);
WRITE_BOOL_FIELD(single_copy);
WRITE_BOOL_FIELD(invisible);
}
@@ -493,6 +494,7 @@ _outGatherMerge(StringInfo str, const GatherMerge *node)
_outPlanInfo(str, (const Plan *) node);
WRITE_INT_FIELD(num_workers);
+ WRITE_INT_FIELD(rescan_param);
WRITE_INT_FIELD(numCols);
appendStringInfoString(str, " :sortColIdx");
diff --git a/src/backend/nodes/readfuncs.c b/src/backend/nodes/readfuncs.c
index 86c811de49..67b9e19d29 100644
--- a/src/backend/nodes/readfuncs.c
+++ b/src/backend/nodes/readfuncs.c
@@ -2163,6 +2163,7 @@ _readGather(void)
ReadCommonPlan(&local_node->plan);
READ_INT_FIELD(num_workers);
+ READ_INT_FIELD(rescan_param);
READ_BOOL_FIELD(single_copy);
READ_BOOL_FIELD(invisible);
@@ -2180,6 +2181,7 @@ _readGatherMerge(void)
ReadCommonPlan(&local_node->plan);
READ_INT_FIELD(num_workers);
+ READ_INT_FIELD(rescan_param);
READ_INT_FIELD(numCols);
READ_ATTRNUMBER_ARRAY(sortColIdx, local_node->numCols);
READ_OID_ARRAY(sortOperators, local_node->numCols);