Skip to content

Commit 69de171

Browse files
author
Amit Kapila
committed
Prohibit shutting down resources if there is a possibility of back up.
Currently, we release the asynchronous resources as soon as it is evident that no more rows will be needed e.g. when a Limit is filled. This can be problematic especially for custom and foreign scans where we can scan backward. Fix that by disallowing the shutting down of resources in such cases. Reported-by: Robert Haas Analysed-by: Robert Haas and Amit Kapila Author: Amit Kapila Reviewed-by: Robert Haas Backpatch-through: 9.6 where this code was introduced Discussion: https://postgr.es/m/86137f17-1dfb-42f9-7421-82fd786b04a1@anayrat.info
1 parent 0d428b6 commit 69de171

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/backend/executor/execMain.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,8 +1571,12 @@ ExecutePlan(EState *estate,
15711571
*/
15721572
if (TupIsNull(slot))
15731573
{
1574-
/* Allow nodes to release or shut down resources. */
1575-
(void) ExecShutdownNode(planstate);
1574+
/*
1575+
* If we know we won't need to back up, we can release
1576+
* resources at this point.
1577+
*/
1578+
if (!(estate->es_top_eflags & EXEC_FLAG_BACKWARD))
1579+
(void) ExecShutdownNode(planstate);
15761580
break;
15771581
}
15781582

src/backend/executor/nodeLimit.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,14 @@ ExecLimit(LimitState *node)
130130
node->position - node->offset >= node->count)
131131
{
132132
node->lstate = LIMIT_WINDOWEND;
133-
/* Allow nodes to release or shut down resources. */
134-
(void) ExecShutdownNode(outerPlan);
133+
134+
/*
135+
* If we know we won't need to back up, we can release
136+
* resources at this point.
137+
*/
138+
if (!(node->ps.state->es_top_eflags & EXEC_FLAG_BACKWARD))
139+
(void) ExecShutdownNode(outerPlan);
140+
135141
return NULL;
136142
}
137143

0 commit comments

Comments
 (0)