aboutsummaryrefslogtreecommitdiff
path: root/src/backend
diff options
context:
space:
mode:
authorAndrew Gierth <rhodiumtoad@postgresql.org>2019-11-06 04:13:30 +0000
committerAndrew Gierth <rhodiumtoad@postgresql.org>2019-11-06 04:33:35 +0000
commitf57c63107007f3b9333d270473b9070225c23843 (patch)
treeda88b7a39a06e7ab91eb90571309f43e9293bef0 /src/backend
parent4d616b112704411ff059321c76f438691f0f2ae8 (diff)
downloadpostgresql-f57c63107007f3b9333d270473b9070225c23843.tar.gz
postgresql-f57c63107007f3b9333d270473b9070225c23843.zip
Request small targetlist for input to WindowAgg.
WindowAgg will potentially store large numbers of input rows into tuplestores to allow access to other rows in the frame. If the input is coming via an explicit Sort node, then unneeded columns will already have been discarded (since Sort requests a small tlist); but there are idioms like COUNT(*) OVER () that result in the input not being sorted at all, and cases where the input is being sorted by some means other than a Sort; if we don't request a small tlist, then WindowAgg's storage requirement is inflated by the unneeded columns. Backpatch back to 9.6, where the current tlist handling was added. (Prior to that, WindowAgg would always use a small tlist.) Discussion: https://postgr.es/m/87a7ator8n.fsf@news-spur.riddles.org.uk
Diffstat (limited to 'src/backend')
-rw-r--r--src/backend/optimizer/plan/createplan.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c
index 39458034c1a..83e8b34b1bc 100644
--- a/src/backend/optimizer/plan/createplan.c
+++ b/src/backend/optimizer/plan/createplan.c
@@ -2398,10 +2398,13 @@ create_windowagg_plan(PlannerInfo *root, WindowAggPath *best_path)
ListCell *lc;
/*
- * WindowAgg can project, so no need to be terribly picky about child
- * tlist, but we do need grouping columns to be available
+ * Choice of tlist here is motivated by the fact that WindowAgg will be
+ * storing the input rows of window frames in a tuplestore; it therefore
+ * behooves us to request a small tlist to avoid wasting space. We do of
+ * course need grouping columns to be available.
*/
- subplan = create_plan_recurse(root, best_path->subpath, CP_LABEL_TLIST);
+ subplan = create_plan_recurse(root, best_path->subpath,
+ CP_LABEL_TLIST | CP_SMALL_TLIST);
tlist = build_path_tlist(root, &best_path->path);