Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 3bf05e0

Browse files
committed
Add a new upper planner relation for partially-aggregated results.
Up until now, we've abused grouped_rel->partial_pathlist as a place to store partial paths that have been partially aggregate, but that's really not correct, because a partial path for a relation is supposed to be one which produces the correct results with the addition of only a Gather or Gather Merge node, and these paths also require a Finalize Aggregate step. Instead, add a new partially_group_rel which can hold either partial paths (which need to be gathered and then have aggregation finalized) or non-partial paths (which only need to have aggregation finalized). This allows us to reuse generate_gather_paths for partially_grouped_rel instead of writing new code, so that this patch actually basically no net new code while making things cleaner, simplifying things for pending patches for partition-wise aggregate. Robert Haas and Jeevan Chalke. The larger patch series of which this patch is a part was also reviewed and tested by Antonin Houska, Rajkumar Raghuwanshi, David Rowley, Dilip Kumar, Konstantin Knizhnik, Pascal Legrand, Rafia Sabih, and me. Discussion: http://postgr.es/m/CA+TgmobrzFYS3+U8a_BCy3-hOvh5UyJbC18rEcYehxhpw5=ETA@mail.gmail.com Discussion: http://postgr.es/m/CA+TgmoZyQEjdBNuoG9-wC5GQ5GrO4544Myo13dVptvx+uLg9uQ@mail.gmail.com
1 parent 5b570d7 commit 3bf05e0

File tree

6 files changed

+154
-153
lines changed

6 files changed

+154
-153
lines changed

src/backend/optimizer/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,7 @@ considered useful for each step. Currently, we may create these types of
998998
additional RelOptInfos during upper-level planning:
999999

10001000
UPPERREL_SETOP result of UNION/INTERSECT/EXCEPT, if any
1001+
UPPERREL_PARTIAL_GROUP_AGG result of partial grouping/aggregation, if any
10011002
UPPERREL_GROUP_AGG result of grouping/aggregation, if any
10021003
UPPERREL_WINDOW result of window functions, if any
10031004
UPPERREL_DISTINCT result of "SELECT DISTINCT", if any

src/backend/optimizer/geqo/geqo_eval.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ merge_clump(PlannerInfo *root, List *clumps, Clump *new_clump, bool force)
268268
generate_partitionwise_join_paths(root, joinrel);
269269

270270
/* Create GatherPaths for any useful partial paths for rel */
271-
generate_gather_paths(root, joinrel);
271+
generate_gather_paths(root, joinrel, false);
272272

273273
/* Find and save the cheapest paths for this joinrel */
274274
set_cheapest(joinrel);

src/backend/optimizer/path/allpaths.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ set_rel_pathlist(PlannerInfo *root, RelOptInfo *rel,
488488
* we'll consider gathering partial paths for the parent appendrel.)
489489
*/
490490
if (rel->reloptkind == RELOPT_BASEREL)
491-
generate_gather_paths(root, rel);
491+
generate_gather_paths(root, rel, false);
492492

493493
/*
494494
* Allow a plugin to editorialize on the set of Paths for this base
@@ -2444,27 +2444,42 @@ set_worktable_pathlist(PlannerInfo *root, RelOptInfo *rel, RangeTblEntry *rte)
24442444
* This must not be called until after we're done creating all partial paths
24452445
* for the specified relation. (Otherwise, add_partial_path might delete a
24462446
* path that some GatherPath or GatherMergePath has a reference to.)
2447+
*
2448+
* If we're generating paths for a scan or join relation, override_rows will
2449+
* be false, and we'll just use the relation's size estimate. When we're
2450+
* being called for a partially-grouped path, though, we need to override
2451+
* the rowcount estimate. (It's not clear that the particular value we're
2452+
* using here is actually best, but the underlying rel has no estimate so
2453+
* we must do something.)
24472454
*/
24482455
void
2449-
generate_gather_paths(PlannerInfo *root, RelOptInfo *rel)
2456+
generate_gather_paths(PlannerInfo *root, RelOptInfo *rel, bool override_rows)
24502457
{
24512458
Path *cheapest_partial_path;
24522459
Path *simple_gather_path;
24532460
ListCell *lc;
2461+
double rows;
2462+
double *rowsp = NULL;
24542463

24552464
/* If there are no partial paths, there's nothing to do here. */
24562465
if (rel->partial_pathlist == NIL)
24572466
return;
24582467

2468+
/* Should we override the rel's rowcount estimate? */
2469+
if (override_rows)
2470+
rowsp = &rows;
2471+
24592472
/*
24602473
* The output of Gather is always unsorted, so there's only one partial
24612474
* path of interest: the cheapest one. That will be the one at the front
24622475
* of partial_pathlist because of the way add_partial_path works.
24632476
*/
24642477
cheapest_partial_path = linitial(rel->partial_pathlist);
2478+
rows =
2479+
cheapest_partial_path->rows * cheapest_partial_path->parallel_workers;
24652480
simple_gather_path = (Path *)
24662481
create_gather_path(root, rel, cheapest_partial_path, rel->reltarget,
2467-
NULL, NULL);
2482+
NULL, rowsp);
24682483
add_path(rel, simple_gather_path);
24692484

24702485
/*
@@ -2479,8 +2494,9 @@ generate_gather_paths(PlannerInfo *root, RelOptInfo *rel)
24792494
if (subpath->pathkeys == NIL)
24802495
continue;
24812496

2497+
rows = subpath->rows * subpath->parallel_workers;
24822498
path = create_gather_merge_path(root, rel, subpath, rel->reltarget,
2483-
subpath->pathkeys, NULL, NULL);
2499+
subpath->pathkeys, NULL, rowsp);
24842500
add_path(rel, &path->path);
24852501
}
24862502
}
@@ -2653,7 +2669,7 @@ standard_join_search(PlannerInfo *root, int levels_needed, List *initial_rels)
26532669
generate_partitionwise_join_paths(root, rel);
26542670

26552671
/* Create GatherPaths for any useful partial paths for rel */
2656-
generate_gather_paths(root, rel);
2672+
generate_gather_paths(root, rel, false);
26572673

26582674
/* Find and save the cheapest paths for this rel */
26592675
set_cheapest(rel);

0 commit comments

Comments
 (0)