diff options
Diffstat (limited to 'src/backend/optimizer/plan/planmain.c')
-rw-r--r-- | src/backend/optimizer/plan/planmain.c | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/backend/optimizer/plan/planmain.c b/src/backend/optimizer/plan/planmain.c index 3cedd01c98b..c36958de51a 100644 --- a/src/backend/optimizer/plan/planmain.c +++ b/src/backend/optimizer/plan/planmain.c @@ -159,15 +159,13 @@ query_planner(PlannerInfo *root, List *tlist, setup_append_rel_array(root); /* - * Construct RelOptInfo nodes for all base relations in query, and - * indirectly for all appendrel member relations ("other rels"). This - * will give us a RelOptInfo for every "simple" (non-join) rel involved in - * the query. + * Construct RelOptInfo nodes for all base relations used in the query. + * Appendrel member relations ("other rels") will be added later. * - * Note: the reason we find the rels by searching the jointree and - * appendrel list, rather than just scanning the rangetable, is that the - * rangetable may contain RTEs for rels not actively part of the query, - * for example views. We don't want to make RelOptInfos for them. + * Note: the reason we find the baserels by searching the jointree, rather + * than scanning the rangetable, is that the rangetable may contain RTEs + * for rels not actively part of the query, for example views. We don't + * want to make RelOptInfos for them. */ add_base_rels_to_query(root, (Node *) parse->jointree); @@ -260,6 +258,16 @@ query_planner(PlannerInfo *root, List *tlist, extract_restriction_or_clauses(root); /* + * Now expand appendrels by adding "otherrels" for their children. We + * delay this to the end so that we have as much information as possible + * available for each baserel, including all restriction clauses. That + * let us prune away partitions that don't satisfy a restriction clause. + * Also note that some information such as lateral_relids is propagated + * from baserels to otherrels here, so we must have computed it already. + */ + add_other_rels_to_query(root); + + /* * Ready to do the primary planning. */ final_rel = make_one_rel(root, joinlist); |