aboutsummaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/createplan.c
diff options
context:
space:
mode:
authorDavid Rowley <drowley@postgresql.org>2023-07-03 12:49:43 +1200
committerDavid Rowley <drowley@postgresql.org>2023-07-03 12:49:43 +1200
commitc65102006b686ea26194fb539d7a416a089300e0 (patch)
tree494a8ac701ea4ac6b158136140fd15e254deadc7 /src/backend/optimizer/plan/createplan.c
parent4637a6ac0b40fef701ab850de1be547b927c3013 (diff)
downloadpostgresql-c65102006b686ea26194fb539d7a416a089300e0.tar.gz
postgresql-c65102006b686ea26194fb539d7a416a089300e0.zip
Remove redundant PARTITION BY columns from WindowClauses
Here we adjust the query planner to have it remove items from a window clause's PARTITION BY clause in cases where the pathkey for a column in the PARTITION BY clause is redundant. Doing this allows the optimization added in 9d9c02ccd to stop window aggregation early rather than going into "pass-through" mode to find tuples belonging to the next partition. Also, when we manage to remove all PARTITION BY columns, we now no longer needlessly check that the current tuple belongs to the same partition as the last tuple in nodeWindowAgg.c. If the pathkey was redundant then all tuples must contain the same value for the given redundant column, so there's no point in checking that during execution. Author: David Rowley Reviewed-by: Richard Guo Discussion: https://postgr.es/m/CAApHDvo2ji+hdxrxfXtRtsfSVw3to2o1nCO20qimw0dUGK8hcQ@mail.gmail.com
Diffstat (limited to 'src/backend/optimizer/plan/createplan.c')
-rw-r--r--src/backend/optimizer/plan/createplan.c7
1 files changed, 1 insertions, 6 deletions
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 4bb38160b33..ec73789bc21 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -2623,12 +2623,7 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
/*
* Convert SortGroupClause lists into arrays of attr indexes and equality
- * operators, as wanted by executor. (Note: in principle, it's possible
- * to drop some of the sort columns, if they were proved redundant by
- * pathkey logic. However, it doesn't seem worth going out of our way to
- * optimize such cases. In any case, we must *not* remove the ordering
- * column for RANGE OFFSET cases, as the executor needs that for in_range
- * tests even if it's known to be equal to some partitioning column.)
+ * operators, as wanted by executor.
*/
partColIdx = (AttrNumber *) palloc(sizeof(AttrNumber) * numPart);
partOperators = (Oid *) palloc(sizeof(Oid) * numPart);