summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/plan/planmain.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2002-03-12 00:52:10 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2002-03-12 00:52:10 +0000
commit6eeb95f0f56bb5e8a0a9328aeec04c9e6de87272 (patch)
tree5f209c5926768472f9d4fd7210065c18831dbd9c /src/backend/optimizer/plan/planmain.c
parent66b6bf67a197db73a880d2a4d9dab05168cde8e0 (diff)
Restructure representation of join alias variables. An explicit JOIN
now has an RTE of its own, and references to its outputs now are Vars referencing the JOIN RTE, rather than CASE-expressions. This allows reverse-listing in ruleutils.c to use the correct alias easily, rather than painfully reverse-engineering the alias namespace as it used to do. Also, nested FULL JOINs work correctly, because the result of the inner joins are simple Vars that the planner can cope with. This fixes a bug reported a couple times now, notably by Tatsuo on 18-Nov-01. The alias Vars are expanded into COALESCE expressions where needed at the very end of planning, rather than during parsing. Also, beginnings of support for showing plan qualifier expressions in EXPLAIN. There are probably still cases that need work. initdb forced due to change of stored-rule representation.
Diffstat (limited to 'src/backend/optimizer/plan/planmain.c')
-rw-r--r--src/backend/optimizer/plan/planmain.c38
1 files changed, 11 insertions, 27 deletions
diff --git a/src/backend/optimizer/plan/planmain.c b/src/backend/optimizer/plan/planmain.c
index 57c9b963c73..ee1d1890712 100644
--- a/src/backend/optimizer/plan/planmain.c
+++ b/src/backend/optimizer/plan/planmain.c
@@ -14,7 +14,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planmain.c,v 1.67 2001/10/25 05:49:33 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planmain.c,v 1.68 2002/03/12 00:51:46 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -176,48 +176,32 @@ subplanner(Query *root,
List *flat_tlist,
double tuple_fraction)
{
- List *joined_rels;
- List *brel;
RelOptInfo *final_rel;
Plan *resultplan;
Path *cheapestpath;
Path *presortedpath;
- /*
- * Examine the targetlist and qualifications, adding entries to
- * base_rel_list as relation references are found (e.g., in the
- * qualification, the targetlist, etc.). Restrict and join clauses
- * are added to appropriate lists belonging to the mentioned
- * relations. We also build lists of equijoined keys for pathkey
- * construction.
- */
+ /* init lists to empty */
root->base_rel_list = NIL;
root->other_rel_list = NIL;
root->join_rel_list = NIL;
root->equi_key_list = NIL;
- build_base_rel_tlists(root, flat_tlist);
-
- (void) distribute_quals_to_rels(root, (Node *) root->jointree);
-
/*
- * Make sure we have RelOptInfo nodes for all relations to be joined.
+ * Construct RelOptInfo nodes for all base relations in query.
*/
- joined_rels = add_missing_rels_to_query(root, (Node *) root->jointree);
+ (void) add_base_rels_to_query(root, (Node *) root->jointree);
/*
- * Check that the join tree includes all the base relations used in
- * the query --- otherwise, the parser or rewriter messed up.
+ * 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 lists of equijoined keys for pathkey
+ * construction.
*/
- foreach(brel, root->base_rel_list)
- {
- RelOptInfo *baserel = (RelOptInfo *) lfirst(brel);
- int relid = lfirsti(baserel->relids);
+ build_base_rel_tlists(root, flat_tlist);
- if (!ptrMember(baserel, joined_rels))
- elog(ERROR, "Internal error: no jointree entry for rel %s (%d)",
- rt_fetch(relid, root->rtable)->eref->relname, relid);
- }
+ (void) distribute_quals_to_rels(root, (Node *) root->jointree);
/*
* Use the completed lists of equijoined keys to deduce any implied