diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c index 10ccf59b794..9c70cb7c174 100644 --- a/src/backend/executor/execMain.c +++ b/src/backend/executor/execMain.c @@ -1571,8 +1571,12 @@ ExecutePlan(EState *estate, */ if (TupIsNull(slot)) { - /* Allow nodes to release or shut down resources. */ - (void) ExecShutdownNode(planstate); + /* + * If we know we won't need to back up, we can release + * resources at this point. + */ + 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 4ff8982cd5b..9d78b827520 100644 --- a/src/backend/executor/nodeLimit.c +++ b/src/backend/executor/nodeLimit.c @@ -130,8 +130,14 @@ ExecLimit(LimitState *node) node->position - node->offset >= node->count) { node->lstate = LIMIT_WINDOWEND; - /* Allow nodes to release or shut down resources. */ - (void) ExecShutdownNode(outerPlan); + + /* + * 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; }