mirror of
https://github.com/postgres/postgres.git
synced 2025-07-12 21:01:52 +03:00
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.
This commit is contained in:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.114 2001/12/10 22:54:12 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.115 2002/03/12 00:51:47 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -99,7 +99,7 @@ planner(Query *parse)
|
||||
result_plan->nParamExec = length(PlannerParamVar);
|
||||
|
||||
/* final cleanup of the plan */
|
||||
set_plan_references(result_plan);
|
||||
set_plan_references(parse, result_plan);
|
||||
|
||||
/* restore state for outer planner, if any */
|
||||
PlannerQueryLevel = save_PlannerQueryLevel;
|
||||
@ -616,6 +616,9 @@ preprocess_jointree(Query *parse, Node *jtnode)
|
||||
static Node *
|
||||
preprocess_expression(Query *parse, Node *expr, int kind)
|
||||
{
|
||||
bool has_join_rtes;
|
||||
List *rt;
|
||||
|
||||
/*
|
||||
* Simplify constant expressions.
|
||||
*
|
||||
@ -651,6 +654,29 @@ preprocess_expression(Query *parse, Node *expr, int kind)
|
||||
if (PlannerQueryLevel > 1)
|
||||
expr = SS_replace_correlation_vars(expr);
|
||||
|
||||
/*
|
||||
* If the query has any join RTEs, try to replace join alias variables
|
||||
* with base-relation variables, to allow quals to be pushed down.
|
||||
* We must do this after sublink processing, since it does not recurse
|
||||
* into sublinks.
|
||||
*
|
||||
* The flattening pass is expensive enough that it seems worthwhile to
|
||||
* scan the rangetable to see if we can avoid it.
|
||||
*/
|
||||
has_join_rtes = false;
|
||||
foreach(rt, parse->rtable)
|
||||
{
|
||||
RangeTblEntry *rte = lfirst(rt);
|
||||
|
||||
if (rte->rtekind == RTE_JOIN)
|
||||
{
|
||||
has_join_rtes = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (has_join_rtes)
|
||||
expr = flatten_join_alias_vars(expr, parse, 0);
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user