summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rowley2022-12-10 06:27:20 +0000
committerDavid Rowley2022-12-10 06:27:20 +0000
commit94985c21020aa4a40d0dda1a26ac3e35a57e4681 (patch)
treeeefc3785b863a9c05af0a9b21d04d05df1eab4e4
parent66dcb09246b49b2cd0421251221e07c388de9c4f (diff)
Add subquery pullup handling for WindowClause runCondition
9d9c02ccd added code to allow WindowAgg to take some shortcuts when a monotonic WindowFunc reached some value that it could never come back from due to the function's monotonic nature. That commit added a runCondition field to WindowClause to store the condition which, when it becomes false we can start taking shortcuts in nodeWindowAgg.c. Here we fix an issue where subquery pullups didn't properly update the runCondition to update the Vars to properly reference the new query level. Here we also add a missing call to preprocess_expression() for the WindowClause's runCondtion. The WindowFuncs in the targetlist will have had this process done, so we must also do it for the WindowFuncs in the runCondition so that they can be correctly found in the targetlist during setrefs.c Bug: #17709 Reported-by: Alexey Makhmutov Author: Richard Guo, David Rowley Discussion: https://postgr.es/m/[email protected] Backpatch-through: 15, where 9d9c02ccd was introduced
-rw-r--r--src/backend/optimizer/plan/planner.c3
-rw-r--r--src/backend/optimizer/prep/prepjointree.c9
2 files changed, 12 insertions, 0 deletions
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index 15aa9c5087..5dd4f92720 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -833,6 +833,9 @@ subquery_planner(PlannerGlobal *glob, Query *parse,
EXPRKIND_LIMIT);
wc->endOffset = preprocess_expression(root, wc->endOffset,
EXPRKIND_LIMIT);
+ wc->runCondition = (List *) preprocess_expression(root,
+ (Node *) wc->runCondition,
+ EXPRKIND_TARGET);
}
parse->limitOffset = preprocess_expression(root, parse->limitOffset,
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index 57fea35e44..c2239d18b4 100644
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -2120,6 +2120,15 @@ perform_pullup_replace_vars(PlannerInfo *root,
pullup_replace_vars((Node *) parse->targetList, rvcontext);
parse->returningList = (List *)
pullup_replace_vars((Node *) parse->returningList, rvcontext);
+
+ foreach(lc, parse->windowClause)
+ {
+ WindowClause *wc = lfirst_node(WindowClause, lc);
+
+ if (wc->runCondition != NIL)
+ wc->runCondition = (List *)
+ pullup_replace_vars((Node *) wc->runCondition, rvcontext);
+ }
if (parse->onConflict)
{
parse->onConflict->onConflictSet = (List *)