mirror of
https://github.com/postgres/postgres.git
synced 2025-07-14 08:21:07 +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:
@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.138 2003/01/13 18:10:53 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/plan/planner.c,v 1.139 2003/01/15 19:35:40 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -559,20 +559,6 @@ is_simple_subquery(Query *subquery)
|
||||
if (expression_returns_set((Node *) subquery->targetList))
|
||||
return false;
|
||||
|
||||
/*
|
||||
* Don't pull up a subquery that has any sublinks in its targetlist,
|
||||
* either. As of PG 7.3 this creates problems because the pulled-up
|
||||
* expressions may go into join alias lists, and the sublinks would
|
||||
* not get fixed because we do flatten_join_alias_vars() too late.
|
||||
* Eventually we should do a complete flatten_join_alias_vars as the
|
||||
* first step of preprocess_expression, and then we could probably
|
||||
* support this. (BUT: it might be a bad idea anyway, due to possibly
|
||||
* causing multiple evaluations of an expensive sublink.)
|
||||
*/
|
||||
if (subquery->hasSubLinks &&
|
||||
contain_subplans((Node *) subquery->targetList))
|
||||
return false;
|
||||
|
||||
/*
|
||||
* Hack: don't try to pull up a subquery with an empty jointree.
|
||||
* query_planner() will correctly generate a Result plan for a
|
||||
@ -750,6 +736,14 @@ preprocess_jointree(Query *parse, Node *jtnode)
|
||||
static Node *
|
||||
preprocess_expression(Query *parse, Node *expr, int kind)
|
||||
{
|
||||
/*
|
||||
* If the query has any join RTEs, replace join alias variables with
|
||||
* base-relation variables. We must do this before sublink processing,
|
||||
* else sublinks expanded out from join aliases wouldn't get processed.
|
||||
*/
|
||||
if (parse->hasJoinRTEs)
|
||||
expr = flatten_join_alias_vars(expr, parse->rtable);
|
||||
|
||||
/*
|
||||
* Simplify constant expressions.
|
||||
*
|
||||
@ -783,15 +777,6 @@ 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.
|
||||
*/
|
||||
if (parse->hasJoinRTEs)
|
||||
expr = flatten_join_alias_vars(expr, parse->rtable, false);
|
||||
|
||||
return expr;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user