1
0
mirror of https://github.com/postgres/postgres.git synced 2025-07-07 00:36:50 +03:00

Avoid generating bogus paths with partitionwise aggregate.

Previously, if some or all partitions had no partially aggregated path,
we would still try to generate a partially aggregated path for the
parent, leading to assertion failures or wrong answers.

Report by Rajkumar Raghuwanshi.  Patch by Jeevan Chalke, reviewed
by Ashutosh Bapat.  A few changes by me.

Discussion: http://postgr.es/m/CAKcux6=q4+Mw8gOOX16ef6ZMFp9Cve7KWFstUsrDa4GiFaXGUQ@mail.gmail.com
This commit is contained in:
Robert Haas
2018-06-22 09:14:34 -04:00
parent 2448adf29c
commit c6f28af5d7
3 changed files with 142 additions and 8 deletions

View File

@ -7012,6 +7012,7 @@ create_partitionwise_grouping_paths(PlannerInfo *root,
List *grouped_live_children = NIL;
List *partially_grouped_live_children = NIL;
PathTarget *target = grouped_rel->reltarget;
bool partial_grouping_valid = true;
Assert(patype != PARTITIONWISE_AGGREGATE_NONE);
Assert(patype != PARTITIONWISE_AGGREGATE_PARTIAL ||
@ -7091,6 +7092,8 @@ create_partitionwise_grouping_paths(PlannerInfo *root,
lappend(partially_grouped_live_children,
child_partially_grouped_rel);
}
else
partial_grouping_valid = false;
if (patype == PARTITIONWISE_AGGREGATE_FULL)
{
@ -7102,21 +7105,19 @@ create_partitionwise_grouping_paths(PlannerInfo *root,
pfree(appinfos);
}
/*
* All children can't be dummy at this point. If they are, then the parent
* too marked as dummy.
*/
Assert(grouped_live_children != NIL ||
partially_grouped_live_children != NIL);
/*
* Try to create append paths for partially grouped children. For full
* partitionwise aggregation, we might have paths in the partial_pathlist
* if parallel aggregation is possible. For partial partitionwise
* aggregation, we may have paths in both pathlist and partial_pathlist.
*
* NB: We must have a partially grouped path for every child in order to
* generate a partially grouped path for this relation.
*/
if (partially_grouped_rel)
if (partially_grouped_rel && partial_grouping_valid)
{
Assert(partially_grouped_live_children != NIL);
add_paths_to_append_rel(root, partially_grouped_rel,
partially_grouped_live_children);
@ -7130,7 +7131,11 @@ create_partitionwise_grouping_paths(PlannerInfo *root,
/* If possible, create append paths for fully grouped children. */
if (patype == PARTITIONWISE_AGGREGATE_FULL)
{
Assert(grouped_live_children != NIL);
add_paths_to_append_rel(root, grouped_rel, grouped_live_children);
}
}
/*