diff options
author | Amit Kapila <akapila@postgresql.org> | 2018-08-13 08:22:18 +0530 |
---|---|---|
committer | Amit Kapila <akapila@postgresql.org> | 2018-08-13 08:22:18 +0530 |
commit | 2cd0acfdade82f3cab362fd9129d453f81cc2745 (patch) | |
tree | 828dfcf107e6f85ba016d0ea9ed5bd7f6d5ef311 /src/backend/executor/nodeLimit.c | |
parent | 07172d5aff8f43cd6ce09f57a0b56a535d7eaf45 (diff) | |
download | postgresql-2cd0acfdade82f3cab362fd9129d453f81cc2745.tar.gz postgresql-2cd0acfdade82f3cab362fd9129d453f81cc2745.zip |
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
Diffstat (limited to 'src/backend/executor/nodeLimit.c')
-rw-r--r-- | src/backend/executor/nodeLimit.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/backend/executor/nodeLimit.c b/src/backend/executor/nodeLimit.c index 66ea6aa3c35..bb28cf7d1db 100644 --- a/src/backend/executor/nodeLimit.c +++ b/src/backend/executor/nodeLimit.c @@ -134,8 +134,14 @@ ExecLimit(PlanState *pstate) 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; } |