summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/planner.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2005-07-02 23:00:42 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2005-07-02 23:00:42 +0000
commitcc5e80b8d1c4bf86aa99b54c938e9048e10bf93a (patch)
tree6288e2b3bf66c8b1d30ee6db9b7846251d5ad95a /src/backend/optimizer/plan/planner.c
parentea1e2b948d2dcbd40fb9053e74ae2da27cfd425e (diff)
Teach planner about some cases where a restriction clause can be
propagated inside an outer join. In particular, given LEFT JOIN ON (A = B) WHERE A = constant, we cannot conclude that B = constant at the top level (B might be null instead), but we can nonetheless put a restriction B = constant into the quals for B's relation, since no inner-side rows not meeting that condition can contribute to the final result. Similarly, given FULL JOIN USING (J) WHERE J = constant, we can't directly conclude that either input J variable = constant, but it's OK to push such quals into each input rel. Per recent gripe from Kim Bisgaard. Along the way, remove 'valid_everywhere' flag from RestrictInfo, as on closer analysis it was not being used for anything, and was defined backwards anyway.
Diffstat (limited to 'src/backend/optimizer/plan/planner.c')
-rw-r--r--src/backend/optimizer/plan/planner.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/backend/optimizer/plan/planner.c b/src/backend/optimizer/plan/planner.c
index df8d0556b42..334f8504dff 100644
--- a/src/backend/optimizer/plan/planner.c
+++ b/src/backend/optimizer/plan/planner.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.189 2005/06/10 02:21:04 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.190 2005/07/02 23:00:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -194,7 +194,6 @@ subquery_planner(Query *parse, double tuple_fraction,
int saved_planid = PlannerPlanId;
PlannerInfo *root;
Plan *plan;
- bool hasOuterJoins;
List *newHaving;
List *lst;
ListCell *l;
@@ -228,12 +227,16 @@ subquery_planner(Query *parse, double tuple_fraction,
/*
* Detect whether any rangetable entries are RTE_JOIN kind; if not, we
* can avoid the expense of doing flatten_join_alias_vars(). Also
- * check for outer joins --- if none, we can skip
- * reduce_outer_joins(). This must be done after we have done
+ * check for outer joins --- if none, we can skip reduce_outer_joins()
+ * and some other processing. This must be done after we have done
* pull_up_subqueries, of course.
+ *
+ * Note: if reduce_outer_joins manages to eliminate all outer joins,
+ * root->hasOuterJoins is not reset currently. This is OK since its
+ * purpose is merely to suppress unnecessary processing in simple cases.
*/
root->hasJoinRTEs = false;
- hasOuterJoins = false;
+ root->hasOuterJoins = false;
foreach(l, parse->rtable)
{
RangeTblEntry *rte = (RangeTblEntry *) lfirst(l);
@@ -243,7 +246,7 @@ subquery_planner(Query *parse, double tuple_fraction,
root->hasJoinRTEs = true;
if (IS_OUTER_JOIN(rte->jointype))
{
- hasOuterJoins = true;
+ root->hasOuterJoins = true;
/* Can quit scanning once we find an outer join */
break;
}
@@ -347,7 +350,7 @@ subquery_planner(Query *parse, double tuple_fraction,
* joins. This step is most easily done after we've done expression
* preprocessing.
*/
- if (hasOuterJoins)
+ if (root->hasOuterJoins)
reduce_outer_joins(root);
/*