summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/geqo/geqo_eval.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2007-02-16 00:14:16 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2007-02-16 00:14:16 +0000
commit0990afb8e288c9107e4eac4cb7a3cc41da65b331 (patch)
treecf39f7a0f94111acd5c0ef1ca48d835073f7036b /src/backend/optimizer/geqo/geqo_eval.c
parente6aa62ec1428c33a9c997cf06351653c8ceea8d5 (diff)
Restructure code that is responsible for ensuring that clauseless joins are
considered when it is necessary to do so because of a join-order restriction (that is, an outer-join or IN-subselect construct). The former coding was a bit ad-hoc and inconsistent, and it missed some cases, as exposed by Mario Weilguni's recent bug report. His specific problem was that an IN could be turned into a "clauseless" join due to constant-propagation removing the IN's joinclause, and if the IN's subselect involved more than one relation and there was more than one such IN linking to the same upper relation, then the only valid join orders involve "bushy" plans but we would fail to consider the specific paths needed to get there. (See the example case added to the join regression test.) On examining the code I wonder if there weren't some other problem cases too; in particular it seems that GEQO was defending against a different set of corner cases than the main planner was. There was also an efficiency problem, in that when we did realize we needed a clauseless join because of an IN, we'd consider clauseless joins against every other relation whether this was sensible or not. It seems a better design is to use the outer-join and in-clause lists as a backup heuristic, just as the rule of joining only where there are joinclauses is a heuristic: we'll join two relations if they have a usable joinclause *or* this might be necessary to satisfy an outer-join or IN-clause join order restriction. I refactored the code to have just one place considering this instead of three, and made sure that it covered all the cases that any of them had been considering. Backpatch as far as 8.1 (which has only the IN-clause form of the disease). By rights 8.0 and 7.4 should have the bug too, but they accidentally fail to fail, because the joininfo structure used in those releases preserves some memory of there having once been a joinclause between the inner and outer sides of an IN, and so it leads the code in the right direction anyway. I'll be conservative and not touch them.
Diffstat (limited to 'src/backend/optimizer/geqo/geqo_eval.c')
-rw-r--r--src/backend/optimizer/geqo/geqo_eval.c24
1 files changed, 5 insertions, 19 deletions
diff --git a/src/backend/optimizer/geqo/geqo_eval.c b/src/backend/optimizer/geqo/geqo_eval.c
index 555ae296092..9b7fd2848bd 100644
--- a/src/backend/optimizer/geqo/geqo_eval.c
+++ b/src/backend/optimizer/geqo/geqo_eval.c
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2005, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_eval.c,v 1.77.2.1 2005/11/22 18:23:10 momjian Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/geqo/geqo_eval.c,v 1.77.2.2 2007/02/16 00:14:16 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -254,28 +254,14 @@ static bool
desirable_join(PlannerInfo *root,
RelOptInfo *outer_rel, RelOptInfo *inner_rel)
{
- ListCell *l;
-
/*
- * Join if there is an applicable join clause.
+ * Join if there is an applicable join clause, or if there is a join
+ * order restriction forcing these rels to be joined.
*/
- if (have_relevant_joinclause(outer_rel, inner_rel))
+ if (have_relevant_joinclause(outer_rel, inner_rel) ||
+ have_join_order_restriction(root, outer_rel, inner_rel))
return true;
- /*
- * Join if the rels are members of the same IN sub-select. This is needed
- * to improve the odds that we will find a valid solution in a case where
- * an IN sub-select has a clauseless join.
- */
- foreach(l, root->in_info_list)
- {
- InClauseInfo *ininfo = (InClauseInfo *) lfirst(l);
-
- if (bms_is_subset(outer_rel->relids, ininfo->righthand) &&
- bms_is_subset(inner_rel->relids, ininfo->righthand))
- return true;
- }
-
/* Otherwise postpone the join till later. */
return false;
}