mirror of
https://github.com/postgres/postgres.git
synced 2025-07-03 20:02:46 +03:00
Second try at fixing join alias variables. Instead of attaching miscellaneous
lists to join RTEs, attach a list of Vars and COALESCE expressions that will replace the join's alias variables during planning. This simplifies flatten_join_alias_vars while still making it easy to fix up varno references when transforming the query tree. Add regression test cases for interactions of subqueries with outer joins.
This commit is contained in:
@ -10,7 +10,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.112 2002/03/12 00:51:45 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.113 2002/04/28 19:54:28 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -80,18 +80,18 @@ static TidScan *make_tidscan(List *qptlist, List *qpqual, Index scanrelid,
|
||||
static NestLoop *make_nestloop(List *tlist,
|
||||
List *joinclauses, List *otherclauses,
|
||||
Plan *lefttree, Plan *righttree,
|
||||
JoinType jointype, Index joinrti);
|
||||
JoinType jointype);
|
||||
static HashJoin *make_hashjoin(List *tlist,
|
||||
List *joinclauses, List *otherclauses,
|
||||
List *hashclauses,
|
||||
Plan *lefttree, Plan *righttree,
|
||||
JoinType jointype, Index joinrti);
|
||||
JoinType jointype);
|
||||
static Hash *make_hash(List *tlist, Node *hashkey, Plan *lefttree);
|
||||
static MergeJoin *make_mergejoin(List *tlist,
|
||||
List *joinclauses, List *otherclauses,
|
||||
List *mergeclauses,
|
||||
Plan *lefttree, Plan *righttree,
|
||||
JoinType jointype, Index joinrti);
|
||||
JoinType jointype);
|
||||
|
||||
/*
|
||||
* create_plan
|
||||
@ -591,7 +591,6 @@ create_nestloop_plan(Query *root,
|
||||
List *inner_tlist)
|
||||
{
|
||||
NestLoop *join_plan;
|
||||
Index joinrti = best_path->path.parent->joinrti;
|
||||
|
||||
if (IsA(inner_plan, IndexScan))
|
||||
{
|
||||
@ -639,22 +638,19 @@ create_nestloop_plan(Query *root,
|
||||
root,
|
||||
outer_tlist,
|
||||
NIL,
|
||||
innerrel,
|
||||
joinrti);
|
||||
innerrel);
|
||||
innerscan->indxqual = join_references(innerscan->indxqual,
|
||||
root,
|
||||
outer_tlist,
|
||||
NIL,
|
||||
innerrel,
|
||||
joinrti);
|
||||
innerrel);
|
||||
/* fix the inner qpqual too, if it has join clauses */
|
||||
if (NumRelids((Node *) inner_plan->qual) > 1)
|
||||
inner_plan->qual = join_references(inner_plan->qual,
|
||||
root,
|
||||
outer_tlist,
|
||||
NIL,
|
||||
innerrel,
|
||||
joinrti);
|
||||
innerrel);
|
||||
}
|
||||
}
|
||||
else if (IsA(inner_plan, TidScan))
|
||||
@ -665,8 +661,7 @@ create_nestloop_plan(Query *root,
|
||||
root,
|
||||
outer_tlist,
|
||||
inner_tlist,
|
||||
innerscan->scan.scanrelid,
|
||||
joinrti);
|
||||
innerscan->scan.scanrelid);
|
||||
}
|
||||
else if (IsA_Join(inner_plan))
|
||||
{
|
||||
@ -688,22 +683,19 @@ create_nestloop_plan(Query *root,
|
||||
root,
|
||||
outer_tlist,
|
||||
inner_tlist,
|
||||
(Index) 0,
|
||||
joinrti);
|
||||
(Index) 0);
|
||||
otherclauses = join_references(otherclauses,
|
||||
root,
|
||||
outer_tlist,
|
||||
inner_tlist,
|
||||
(Index) 0,
|
||||
joinrti);
|
||||
(Index) 0);
|
||||
|
||||
join_plan = make_nestloop(tlist,
|
||||
joinclauses,
|
||||
otherclauses,
|
||||
outer_plan,
|
||||
inner_plan,
|
||||
best_path->jointype,
|
||||
joinrti);
|
||||
best_path->jointype);
|
||||
|
||||
copy_path_costsize(&join_plan->join.plan, &best_path->path);
|
||||
|
||||
@ -723,7 +715,6 @@ create_mergejoin_plan(Query *root,
|
||||
{
|
||||
List *mergeclauses;
|
||||
MergeJoin *join_plan;
|
||||
Index joinrti = best_path->jpath.path.parent->joinrti;
|
||||
|
||||
mergeclauses = get_actual_clauses(best_path->path_mergeclauses);
|
||||
|
||||
@ -736,8 +727,7 @@ create_mergejoin_plan(Query *root,
|
||||
root,
|
||||
outer_tlist,
|
||||
inner_tlist,
|
||||
(Index) 0,
|
||||
joinrti);
|
||||
(Index) 0);
|
||||
|
||||
/*
|
||||
* Fix the additional qpquals too.
|
||||
@ -746,8 +736,7 @@ create_mergejoin_plan(Query *root,
|
||||
root,
|
||||
outer_tlist,
|
||||
inner_tlist,
|
||||
(Index) 0,
|
||||
joinrti);
|
||||
(Index) 0);
|
||||
|
||||
/*
|
||||
* Now set the references in the mergeclauses and rearrange them so
|
||||
@ -757,8 +746,7 @@ create_mergejoin_plan(Query *root,
|
||||
root,
|
||||
outer_tlist,
|
||||
inner_tlist,
|
||||
(Index) 0,
|
||||
joinrti));
|
||||
(Index) 0));
|
||||
|
||||
/*
|
||||
* Create explicit sort nodes for the outer and inner join paths if
|
||||
@ -824,8 +812,7 @@ create_mergejoin_plan(Query *root,
|
||||
mergeclauses,
|
||||
outer_plan,
|
||||
inner_plan,
|
||||
best_path->jpath.jointype,
|
||||
joinrti);
|
||||
best_path->jpath.jointype);
|
||||
|
||||
copy_path_costsize(&join_plan->join.plan, &best_path->jpath.path);
|
||||
|
||||
@ -847,7 +834,6 @@ create_hashjoin_plan(Query *root,
|
||||
HashJoin *join_plan;
|
||||
Hash *hash_plan;
|
||||
Node *innerhashkey;
|
||||
Index joinrti = best_path->jpath.path.parent->joinrti;
|
||||
|
||||
/*
|
||||
* NOTE: there will always be exactly one hashclause in the list
|
||||
@ -866,8 +852,7 @@ create_hashjoin_plan(Query *root,
|
||||
root,
|
||||
outer_tlist,
|
||||
inner_tlist,
|
||||
(Index) 0,
|
||||
joinrti);
|
||||
(Index) 0);
|
||||
|
||||
/*
|
||||
* Fix the additional qpquals too.
|
||||
@ -876,8 +861,7 @@ create_hashjoin_plan(Query *root,
|
||||
root,
|
||||
outer_tlist,
|
||||
inner_tlist,
|
||||
(Index) 0,
|
||||
joinrti);
|
||||
(Index) 0);
|
||||
|
||||
/*
|
||||
* Now set the references in the hashclauses and rearrange them so
|
||||
@ -887,8 +871,7 @@ create_hashjoin_plan(Query *root,
|
||||
root,
|
||||
outer_tlist,
|
||||
inner_tlist,
|
||||
(Index) 0,
|
||||
joinrti));
|
||||
(Index) 0));
|
||||
|
||||
/* Now the righthand op of the sole hashclause is the inner hash key. */
|
||||
innerhashkey = (Node *) get_rightop(lfirst(hashclauses));
|
||||
@ -903,8 +886,7 @@ create_hashjoin_plan(Query *root,
|
||||
hashclauses,
|
||||
outer_plan,
|
||||
(Plan *) hash_plan,
|
||||
best_path->jpath.jointype,
|
||||
joinrti);
|
||||
best_path->jpath.jointype);
|
||||
|
||||
copy_path_costsize(&join_plan->join.plan, &best_path->jpath.path);
|
||||
|
||||
@ -1363,8 +1345,7 @@ make_nestloop(List *tlist,
|
||||
List *otherclauses,
|
||||
Plan *lefttree,
|
||||
Plan *righttree,
|
||||
JoinType jointype,
|
||||
Index joinrti)
|
||||
JoinType jointype)
|
||||
{
|
||||
NestLoop *node = makeNode(NestLoop);
|
||||
Plan *plan = &node->join.plan;
|
||||
@ -1377,7 +1358,6 @@ make_nestloop(List *tlist,
|
||||
plan->righttree = righttree;
|
||||
node->join.jointype = jointype;
|
||||
node->join.joinqual = joinclauses;
|
||||
node->join.joinrti = joinrti;
|
||||
|
||||
return node;
|
||||
}
|
||||
@ -1389,8 +1369,7 @@ make_hashjoin(List *tlist,
|
||||
List *hashclauses,
|
||||
Plan *lefttree,
|
||||
Plan *righttree,
|
||||
JoinType jointype,
|
||||
Index joinrti)
|
||||
JoinType jointype)
|
||||
{
|
||||
HashJoin *node = makeNode(HashJoin);
|
||||
Plan *plan = &node->join.plan;
|
||||
@ -1404,7 +1383,6 @@ make_hashjoin(List *tlist,
|
||||
node->hashclauses = hashclauses;
|
||||
node->join.jointype = jointype;
|
||||
node->join.joinqual = joinclauses;
|
||||
node->join.joinrti = joinrti;
|
||||
|
||||
return node;
|
||||
}
|
||||
@ -1439,8 +1417,7 @@ make_mergejoin(List *tlist,
|
||||
List *mergeclauses,
|
||||
Plan *lefttree,
|
||||
Plan *righttree,
|
||||
JoinType jointype,
|
||||
Index joinrti)
|
||||
JoinType jointype)
|
||||
{
|
||||
MergeJoin *node = makeNode(MergeJoin);
|
||||
Plan *plan = &node->join.plan;
|
||||
@ -1454,7 +1431,6 @@ make_mergejoin(List *tlist,
|
||||
node->mergeclauses = mergeclauses;
|
||||
node->join.jointype = jointype;
|
||||
node->join.joinqual = joinclauses;
|
||||
node->join.joinrti = joinrti;
|
||||
|
||||
return node;
|
||||
}
|
||||
|
Reference in New Issue
Block a user