aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/nodeLimit.c
diff options
context:
space:
mode:
authorAmit Kapila <akapila@postgresql.org>2019-11-18 14:17:41 +0530
committerAmit Kapila <akapila@postgresql.org>2019-11-26 08:30:24 +0530
commit080313f8296fb0bcc74bd70fc8e15cd64f45945e (patch)
tree8336eb44d12702d83cf9ec76bfd17e841f2b62c8 /src/backend/executor/nodeLimit.c
parent0d3c3aae3366891f1c3d6bac326070660be36f76 (diff)
downloadpostgresql-080313f8296fb0bcc74bd70fc8e15cd64f45945e.tar.gz
postgresql-080313f8296fb0bcc74bd70fc8e15cd64f45945e.zip
Don't shut down Gather[Merge] early under Limit.
Revert part of commit 19df1702f5. Early shutdown was added by that commit so that we could collect statistics from workers, but unfortunately, it interacted badly with rescans. The problem is that we ended up destroying the parallel context which is required for rescans. This leads to rescans of a Limit node over a Gather node to produce unpredictable results as it tries to access destroyed parallel context. By reverting the early shutdown code, we might lose statistics in some cases of Limit over Gather [Merge], but that will require further study to fix. Reported-by: Jerry Sievers Diagnosed-by: Thomas Munro Author: Amit Kapila, testcase by Vignesh C Backpatch-through: 9.6 Discussion: https://postgr.es/m/87ims2amh6.fsf@jsievers.enova.com
Diffstat (limited to 'src/backend/executor/nodeLimit.c')
-rw-r--r--src/backend/executor/nodeLimit.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/backend/executor/nodeLimit.c b/src/backend/executor/nodeLimit.c
index baa669abe84..5e4d02ce4a6 100644
--- a/src/backend/executor/nodeLimit.c
+++ b/src/backend/executor/nodeLimit.c
@@ -129,19 +129,17 @@ ExecLimit(PlanState *pstate)
* we are at the end of the window, return NULL without
* advancing the subplan or the position variable; but change
* the state machine state to record having done so.
+ *
+ * Once at the end, ideally, we can shut down parallel
+ * resources but that would destroy the parallel context which
+ * would be required for rescans. To do that, we need to find
+ * a way to pass down more information about whether rescans
+ * are possible.
*/
if (!node->noCount &&
node->position - node->offset >= node->count)
{
node->lstate = LIMIT_WINDOWEND;
-
- /*
- * If we know we won't need to back up, we can release
- * resources at this point.
- */
- if (!(node->ps.state->es_top_eflags & EXEC_FLAG_BACKWARD))
- (void) ExecShutdownNode(outerPlan);
-
return NULL;
}