diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2010-09-28 12:08:56 -0400 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2010-09-28 14:18:22 -0400 |
| commit | 4ec15077b2eaa1f7713e4fff87e220a23c772688 (patch) | |
| tree | 68a194b48c7cb17407f74350fd92073ededbb3ce /src/backend/optimizer/plan/planmain.c | |
| parent | cd1454cdc357593f1d17fd33b9583511a9fe57b1 (diff) | |
Fix PlaceHolderVar mechanism's interaction with outer joins.
The point of a PlaceHolderVar is to allow a non-strict expression to be
evaluated below an outer join, after which its value bubbles up like a Var
and can be forced to NULL when the outer join's semantics require that.
However, there was a serious design oversight in that, namely that we
didn't ensure that there was actually a correct place in the plan tree
to evaluate the placeholder :-(. It may be necessary to delay evaluation
of an outer join to ensure that a placeholder that should be evaluated
below the join can be evaluated there. Per recent bug report from Kirill
Simonov.
Back-patch to 8.4 where the PlaceHolderVar mechanism was introduced.
Diffstat (limited to 'src/backend/optimizer/plan/planmain.c')
| -rw-r--r-- | src/backend/optimizer/plan/planmain.c | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/backend/optimizer/plan/planmain.c b/src/backend/optimizer/plan/planmain.c index ad6c6f58581..36dc4e7b80d 100644 --- a/src/backend/optimizer/plan/planmain.c +++ b/src/backend/optimizer/plan/planmain.c @@ -180,14 +180,19 @@ query_planner(PlannerInfo *root, List *tlist, add_base_rels_to_query(root, (Node *) parse->jointree); /* - * Examine the targetlist and qualifications, adding entries to baserel - * targetlists for all referenced Vars. Restrict and join clauses are - * added to appropriate lists belonging to the mentioned relations. We - * also build EquivalenceClasses for provably equivalent expressions, and - * form a target joinlist for make_one_rel() to work from. + * Examine the targetlist and join tree, adding entries to baserel + * targetlists for all referenced Vars, and generating PlaceHolderInfo + * entries for all referenced PlaceHolderVars. Restrict and join clauses + * are added to appropriate lists belonging to the mentioned relations. + * We also build EquivalenceClasses for provably equivalent expressions. + * The SpecialJoinInfo list is also built to hold information about join + * order restrictions. Finally, we form a target joinlist for + * make_one_rel() to work from. */ build_base_rel_tlists(root, tlist); + find_placeholders_in_jointree(root); + joinlist = deconstruct_jointree(root); /* @@ -218,10 +223,12 @@ query_planner(PlannerInfo *root, List *tlist, /* * Examine any "placeholder" expressions generated during subquery pullup. - * Make sure that we know what level to evaluate them at, and that the - * Vars they need are marked as needed. + * Make sure that the Vars they need are marked as needed at the relevant + * join level. This must be done before join removal because it might + * cause Vars or placeholders to be needed above a join when they weren't + * so marked before. */ - fix_placeholder_eval_levels(root); + fix_placeholder_input_needed_levels(root); /* * Remove any useless outer joins. Ideally this would be done during |
