diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2019-03-26 18:21:10 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2019-03-26 18:21:10 -0400 |
commit | 53bcf5e3dbeaed5baf9d09b124cf196d247c54ea (patch) | |
tree | 43e4de499207a59f6a557bce2638d5f4a2364ceb /src/backend/optimizer/plan/planmain.c | |
parent | 8994cc6ffc8828569a39139996a0b0b8348ca036 (diff) | |
download | postgresql-53bcf5e3dbeaed5baf9d09b124cf196d247c54ea.tar.gz |
Build "other rels" of appendrel baserels in a separate step.
Up to now, otherrel RelOptInfos were built at the same time as baserel
RelOptInfos, thanks to recursion in build_simple_rel(). However,
nothing in query_planner's preprocessing cares at all about otherrels,
only baserels, so we don't really need to build them until just before
we enter make_one_rel. This has two benefits:
* create_lateral_join_info did a lot of extra work to propagate
lateral-reference information from parents to the correct children.
But if we delay creation of the children till after that, it's
trivial (and much harder to break, too).
* Since we have all the restriction quals correctly assigned to
parent appendrels by this point, it'll be possible to do plan-time
pruning and never make child RelOptInfos at all for partitions that
can be pruned away. That's not done here, but will be later on.
Amit Langote, reviewed at various times by Dilip Kumar, Jesper Pedersen,
Yoshikazu Imai, and David Rowley
Discussion: https://postgr.es/m/9d7c5112-cb99-6a47-d3be-cf1ee6862a1d@lab.ntt.co.jp
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 3cedd01c98..c36958de51 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); |