Group Key: ft1.c2
Filter: (avg((ft1.c1 * ((random() <= '1'::double precision))::integer)) > '100'::numeric)
-> Foreign Scan on public.ft1
- Output: c1, c2
+ Output: c2, c1
Remote SQL: SELECT "C 1", c2 FROM "S 1"."T 1"
(10 rows)
Output: sum(c1) FILTER (WHERE ((((c1 / c1))::double precision * random()) <= '1'::double precision)), c2
Group Key: ft1.c2
-> Foreign Scan on public.ft1
- Output: c1, c2
+ Output: c2, c1
Remote SQL: SELECT "C 1", c2 FROM "S 1"."T 1"
(9 rows)
Plan *subplan;
List *tlist;
List *quals;
+ int flags;
/*
* Agg can project, so no need to be terribly picky about child tlist, but
- * we do need grouping columns to be available
+ * we do need grouping columns to be available. We are a bit more careful
+ * with hash aggregate, where we explicitly request small tlist to minimize
+ * I/O needed for spilling (we can't be sure spilling won't be necessary,
+ * so we just do it every time).
*/
- subplan = create_plan_recurse(root, best_path->subpath, CP_LABEL_TLIST);
+ flags = CP_LABEL_TLIST;
+
+ /* ensure small tlist for hash aggregate */
+ if (best_path->aggstrategy == AGG_HASHED)
+ flags |= CP_SMALL_TLIST;
+
+ subplan = create_plan_recurse(root, best_path->subpath, flags);
tlist = build_path_tlist(root, &best_path->path);
int maxref;
List *chain;
ListCell *lc;
+ int flags;
/* Shouldn't get here without grouping sets */
Assert(root->parse->groupingSets);
/*
* Agg can project, so no need to be terribly picky about child tlist, but
- * we do need grouping columns to be available
+ * we do need grouping columns to be available. We are a bit more careful
+ * with hash aggregate, where we explicitly request small tlist to minimize
+ * I/O needed for spilling (we can't be sure spilling won't be necessary,
+ * so we just do it every time).
*/
- subplan = create_plan_recurse(root, best_path->subpath, CP_LABEL_TLIST);
+ flags = CP_LABEL_TLIST;
+
+ /* ensure small tlist for hash aggregate */
+ if (best_path->aggstrategy == AGG_HASHED)
+ flags |= CP_SMALL_TLIST;
+
+ subplan = create_plan_recurse(root, best_path->subpath, flags);
/*
* Compute the mapping from tleSortGroupRef to column index in the child's