From cf978fcadc1985c27783c114b8a367fe795efe9e Mon Sep 17 00:00:00 2001 From: Ashutosh Bapat Date: Fri, 3 Feb 2017 14:45:37 +0530 Subject: [PATCH 01/11] Refactor set_append_rel_pathlist. set_append_rel_pathlist() creates paths for each child relation and then creates append paths for the "append" relation. Right now only a base relation can have children, but with partition-wise join and aggregation a join or an upper relation can have children as well. While the code to add paths to the child relations differs for base, join and upper child relations, the code to create append paths can be shared by all the three relations. Hence separating it into a new function add_paths_to_append_rel() so that it can be re-used for all kinds of relations. --- src/backend/optimizer/path/allpaths.c | 51 ++++++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index 5c18987..d797d6a 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -127,6 +127,8 @@ static void recurse_push_qual(Node *setOp, Query *topquery, RangeTblEntry *rte, Index rti, Node *qual); static void remove_unused_subquery_outputs(Query *subquery, RelOptInfo *rel); static int compute_parallel_worker(RelOptInfo *rel, BlockNumber pages); +static void add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel, + List *live_childrels); /* @@ -1169,19 +1171,11 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, { int parentRTindex = rti; List *live_childrels = NIL; - List *subpaths = NIL; - bool subpaths_valid = true; - List *partial_subpaths = NIL; - bool partial_subpaths_valid = true; - List *all_child_pathkeys = NIL; - List *all_child_outers = NIL; ListCell *l; /* * Generate access paths for each member relation, and remember the - * cheapest path for each one. Also, identify all pathkeys (orderings) - * and parameterizations (required_outer sets) available for the member - * relations. + * non-dummy children. */ foreach(l, root->append_rel_list) { @@ -1189,7 +1183,6 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, int childRTindex; RangeTblEntry *childRTE; RelOptInfo *childrel; - ListCell *lcp; /* append_rel_list contains all append rels; ignore others */ if (appinfo->parent_relid != parentRTindex) @@ -1224,6 +1217,44 @@ set_append_rel_pathlist(PlannerInfo *root, RelOptInfo *rel, * Child is live, so add it to the live_childrels list for use below. */ live_childrels = lappend(live_childrels, childrel); + } + + /* Add Append/MergeAppend paths to the "append" relation. */ + add_paths_to_append_rel(root, rel, live_childrels); +} + + +/* + * add_paths_to_append_rel + * Generate Append/MergeAppend paths for given "append" relation. + * + * The function collects all parameterizations and orderings supported by the + * non-dummy children. For every such parameterization or ordering, it creates + * an append path collecting one path from each non-dummy child with given + * parameterization or ordering. Similarly it collects partial paths from + * non-dummy children to create partial append paths. + */ +static void +add_paths_to_append_rel(PlannerInfo *root, RelOptInfo *rel, + List *live_childrels) +{ + List *subpaths = NIL; + bool subpaths_valid = true; + List *partial_subpaths = NIL; + bool partial_subpaths_valid = true; + List *all_child_pathkeys = NIL; + List *all_child_outers = NIL; + ListCell *l; + + /* + * For every non-dummy child, remember the cheapest path. Also, identify + * all pathkeys (orderings) and parameterizations (required_outer sets) + * available for the non-dummy member relations. + */ + foreach (l, live_childrels) + { + RelOptInfo *childrel = lfirst(l); + ListCell *lcp; /* * If child has an unparameterized cheapest-total path, add that to -- 1.7.9.5