prohibit_shutdown_backward_scans_v1.patch
application/octet-stream
Filename: prohibit_shutdown_backward_scans_v1.patch
Type: application/octet-stream
Part: 2
Patch
Format: unified
Series: patch v1
| File | + | − |
|---|---|---|
| src/backend/executor/execMain.c | 10 | 4 |
| src/backend/executor/nodeLimit.c | 10 | 2 |
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index 01e1a461804..480f3d71bf0 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -1726,8 +1726,11 @@ ExecutePlan(EState *estate,
*/
if (TupIsNull(slot))
{
- /* Allow nodes to release or shut down resources. */
- (void) ExecShutdownNode(planstate);
+ /*
+ * Allow nodes to release or shut down resources. See ExecLimit.
+ */
+ if (!(estate->es_top_eflags & EXEC_FLAG_BACKWARD))
+ (void) ExecShutdownNode(planstate);
break;
}
@@ -1773,8 +1776,11 @@ ExecutePlan(EState *estate,
current_tuple_count++;
if (numberTuples && numberTuples == current_tuple_count)
{
- /* Allow nodes to release or shut down resources. */
- (void) ExecShutdownNode(planstate);
+ /*
+ * Allow nodes to release or shut down resources. See ExecLimit.
+ */
+ if (!(estate->es_top_eflags & EXEC_FLAG_BACKWARD))
+ (void) ExecShutdownNode(planstate);
break;
}
}
diff --git a/src/backend/executor/nodeLimit.c b/src/backend/executor/nodeLimit.c
index 66ea6aa3c35..eb0ed83d19e 100644
--- a/src/backend/executor/nodeLimit.c
+++ b/src/backend/executor/nodeLimit.c
@@ -134,8 +134,16 @@ ExecLimit(PlanState *pstate)
node->position - node->offset >= node->count)
{
node->lstate = LIMIT_WINDOWEND;
- /* Allow nodes to release or shut down resources. */
- (void) ExecShutdownNode(outerPlan);
+
+ /*
+ * Allow nodes to release or shut down resources. We
+ * don't shut down resources if backward scans are
+ * possible as we might need those resources during such
+ * scans.
+ */
+ if (!(node->ps.state->es_top_eflags & EXEC_FLAG_BACKWARD))
+ (void) ExecShutdownNode(outerPlan);
+
return NULL;
}