mirror of
https://github.com/postgres/postgres.git
synced 2025-07-12 21:01:52 +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:
@ -14,7 +14,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.85 2003/01/12 22:35:29 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.86 2003/01/15 19:35:44 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -837,9 +837,7 @@ adjust_inherited_attrs_mutator(Node *node,
|
||||
}
|
||||
|
||||
/*
|
||||
* We have to process RestrictInfo nodes specially: we do NOT want to
|
||||
* copy the original subclauseindices list, since the new rel may have
|
||||
* different indices. The list will be rebuilt during later planning.
|
||||
* We have to process RestrictInfo nodes specially.
|
||||
*/
|
||||
if (IsA(node, RestrictInfo))
|
||||
{
|
||||
@ -849,10 +847,41 @@ adjust_inherited_attrs_mutator(Node *node,
|
||||
/* Copy all flat-copiable fields */
|
||||
memcpy(newinfo, oldinfo, sizeof(RestrictInfo));
|
||||
|
||||
/* Recursively fix the clause itself */
|
||||
newinfo->clause = (Expr *)
|
||||
adjust_inherited_attrs_mutator((Node *) oldinfo->clause, context);
|
||||
|
||||
/*
|
||||
* We do NOT want to copy the original subclauseindices list, since
|
||||
* the new rel will have different indices. The list will be rebuilt
|
||||
* when needed during later planning.
|
||||
*/
|
||||
newinfo->subclauseindices = NIL;
|
||||
|
||||
/*
|
||||
* Adjust left/right relids lists too.
|
||||
*/
|
||||
if (intMember(context->old_rt_index, oldinfo->left_relids))
|
||||
{
|
||||
newinfo->left_relids = listCopy(oldinfo->left_relids);
|
||||
newinfo->left_relids = lremovei(context->old_rt_index,
|
||||
newinfo->left_relids);
|
||||
newinfo->left_relids = lconsi(context->new_rt_index,
|
||||
newinfo->left_relids);
|
||||
}
|
||||
else
|
||||
newinfo->left_relids = oldinfo->left_relids;
|
||||
if (intMember(context->old_rt_index, oldinfo->right_relids))
|
||||
{
|
||||
newinfo->right_relids = listCopy(oldinfo->right_relids);
|
||||
newinfo->right_relids = lremovei(context->old_rt_index,
|
||||
newinfo->right_relids);
|
||||
newinfo->right_relids = lconsi(context->new_rt_index,
|
||||
newinfo->right_relids);
|
||||
}
|
||||
else
|
||||
newinfo->right_relids = oldinfo->right_relids;
|
||||
|
||||
newinfo->eval_cost.startup = -1; /* reset these too */
|
||||
newinfo->this_selec = -1;
|
||||
newinfo->left_pathkey = NIL; /* and these */
|
||||
@ -869,6 +898,7 @@ adjust_inherited_attrs_mutator(Node *node,
|
||||
* NOTE: we do not need to recurse into sublinks, because they should
|
||||
* already have been converted to subplans before we see them.
|
||||
*/
|
||||
Assert(!IsA(node, SubLink));
|
||||
|
||||
/*
|
||||
* BUT: although we don't need to recurse into subplans, we do need to
|
||||
|
Reference in New Issue
Block a user