summaryrefslogtreecommitdiff
path: root/src/backend/optimizer/prep/prepunion.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2003-01-15 19:35:48 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2003-01-15 19:35:48 +0000
commitde97072e3c88e104a55b0d5c67477f1b0097c003 (patch)
treeb4b0a243ce6d38ae6aa5cde1e3ef140e229a1615 /src/backend/optimizer/prep/prepunion.c
parent0eed62f34d95d5c7ae7e0931cfe632f4c8373ec0 (diff)
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.
Diffstat (limited to 'src/backend/optimizer/prep/prepunion.c')
-rw-r--r--src/backend/optimizer/prep/prepunion.c38
1 files changed, 34 insertions, 4 deletions
diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.c
index 5177e210d3d..4af395b860c 100644
--- a/src/backend/optimizer/prep/prepunion.c
+++ b/src/backend/optimizer/prep/prepunion.c
@@ -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