mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Allow merge and hash joins to occur on arbitrary expressions (anything not
containing a volatile function), rather than only on 'Var = Var' clauses as before. This makes it practical to do flatten_join_alias_vars at the start of planning, which in turn eliminates a bunch of klugery inside the planner to deal with alias vars. As a free side effect, we now detect implied equality of non-Var expressions; for example in SELECT ... WHERE a.x = b.y and b.y = 42 we will deduce a.x = 42 and use that as a restriction qual on a. Also, we can remove the restriction introduced 12/5/02 to prevent pullup of subqueries whose targetlists contain sublinks. Still TODO: make statistical estimation routines in selfuncs.c and costsize.c smarter about expressions that are more complex than plain Vars. The need for this is considerably greater now that we have to be able to estimate the suitability of merge and hash join techniques on such expressions.
This commit is contained in:
@ -9,7 +9,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.88 2003/01/13 18:10:53 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/setrefs.c,v 1.89 2003/01/15 19:35:43 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -278,8 +278,7 @@ fix_expr_references_walker(Node *node, void *context)
|
||||
* Note: this same transformation has already been applied to the quals
|
||||
* of the join by createplan.c. It's a little odd to do it here for the
|
||||
* targetlist and there for the quals, but it's easier that way. (Look
|
||||
* at switch_outer() and the handling of nestloop inner indexscans to
|
||||
* see why.)
|
||||
* at the handling of nestloop inner indexscans to see why.)
|
||||
*
|
||||
* Because the quals are reference-adjusted sooner, we cannot do equal()
|
||||
* comparisons between qual and tlist var nodes during the time between
|
||||
@ -379,8 +378,7 @@ set_uppernode_references(Plan *plan, Index subvarno)
|
||||
* Creates a new set of targetlist entries or join qual clauses by
|
||||
* changing the varno/varattno values of variables in the clauses
|
||||
* to reference target list values from the outer and inner join
|
||||
* relation target lists. Also, any join alias variables in the
|
||||
* clauses are expanded into references to their component variables.
|
||||
* relation target lists.
|
||||
*
|
||||
* This is used in two different scenarios: a normal join clause, where
|
||||
* all the Vars in the clause *must* be replaced by OUTER or INNER references;
|
||||
@ -428,7 +426,6 @@ join_references_mutator(Node *node,
|
||||
{
|
||||
Var *var = (Var *) node;
|
||||
Resdom *resdom;
|
||||
Node *newnode;
|
||||
|
||||
/* First look for the var in the input tlists */
|
||||
resdom = tlist_member((Node *) var, context->outer_tlist);
|
||||
@ -454,20 +451,6 @@ join_references_mutator(Node *node,
|
||||
if (var->varno == context->acceptable_rel)
|
||||
return (Node *) copyObject(var);
|
||||
|
||||
/*
|
||||
* Perhaps it's a join alias that can be resolved to input vars?
|
||||
* We try this last since it's relatively slow.
|
||||
*/
|
||||
newnode = flatten_join_alias_vars((Node *) var,
|
||||
context->rtable,
|
||||
true);
|
||||
if (!equal(newnode, (Node *) var))
|
||||
{
|
||||
/* Must now resolve the input vars... */
|
||||
newnode = join_references_mutator(newnode, context);
|
||||
return newnode;
|
||||
}
|
||||
|
||||
/* No referent found for Var */
|
||||
elog(ERROR, "join_references: variable not in subplan target lists");
|
||||
}
|
||||
|
Reference in New Issue
Block a user