From 9b13ec088b6aef9d4633f14d99e6de9770272fc3 Mon Sep 17 00:00:00 2001 From: amit Date: Fri, 8 Feb 2019 15:06:25 +0900 Subject: [PATCH v22 1/6] Reduce code-duplication in set_append_rel_size The code to mark a child rel dummy is repeated for 3 cases: * child is pruned, * contradictory quals found in apply_child_quals, * child excluded due to constraints. This combines the three cases in one if statement. --- src/backend/optimizer/path/allpaths.c | 39 +++++++++++------------------------ 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c index 0debac75c6..72184b0cf9 100644 --- a/src/backend/optimizer/path/allpaths.c +++ b/src/backend/optimizer/path/allpaths.c @@ -1018,6 +1018,7 @@ set_append_rel_size(PlannerInfo *root, RelOptInfo *rel, RelOptInfo *childrel; ListCell *parentvars; ListCell *childvars; + bool childpruned; /* append_rel_list contains all append rels; ignore others */ if (appinfo->parent_relid != parentRTindex) @@ -1033,36 +1034,20 @@ set_append_rel_size(PlannerInfo *root, RelOptInfo *rel, childrel = find_base_rel(root, childRTindex); Assert(childrel->reloptkind == RELOPT_OTHER_MEMBER_REL); - if (did_pruning && !bms_is_member(appinfo->child_relid, live_children)) - { - /* This partition was pruned; skip it. */ - set_dummy_rel_pathlist(childrel); - continue; - } - + childpruned = (did_pruning && + !bms_is_member(appinfo->child_relid, live_children)); /* - * We have to copy the parent's targetlist and quals to the child, - * with appropriate substitution of variables. If any constant false - * or NULL clauses turn up, we can disregard the child right away. - * If not, we can apply constraint exclusion with just the - * baserestrictinfo quals. + * Unless the child is pruned, we have to copy the parent's targetlist + * and quals to the child, with appropriate substitution of variables. + * If any constant false or NULL clauses turn up, we can disregard the + * child right away. If not, we can apply constraint exclusion with + * just the baserestrictinfo quals. */ - if (!apply_child_basequals(root, rel, childrel, childRTE, appinfo)) + if (childpruned || + !apply_child_basequals(root, rel, childrel, childRTE, appinfo) || + relation_excluded_by_constraints(root, childrel, childRTE)) { - /* - * Some restriction clause reduced to constant FALSE or NULL after - * substitution, so this child need not be scanned. - */ - set_dummy_rel_pathlist(childrel); - continue; - } - - if (relation_excluded_by_constraints(root, childrel, childRTE)) - { - /* - * This child need not be scanned, so we can omit it from the - * appendrel. - */ + /* This child need not be scanned; skip it. */ set_dummy_rel_pathlist(childrel); continue; } -- 2.11.0