summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2001-03-27 18:02:19 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2001-03-27 18:02:19 +0000
commitf155cc82ec3f9e4e75cade7348bfe19493950e68 (patch)
tree0c3864c766563b4f62df0218f19b1d9ffe2a5efe /src
parentfa0f2c6577098112ea37bf445615250ec1162f4e (diff)
downloadpostgresql-f155cc82ec3f9e4e75cade7348bfe19493950e68.tar.gz
Quick hack to fix Oliver Elphick's problem with subselects in an
inheritance query: make duplicate copies of subplans in adjust_inherited_attrs. When we redesign querytrees we really gotta do something about this issue of whether querytrees are read-only and can share substructure or not.
Diffstat (limited to 'src')
-rw-r--r--src/backend/optimizer/prep/prepunion.c27
1 files changed, 25 insertions, 2 deletions
diff --git a/src/backend/optimizer/prep/prepunion.c b/src/backend/optimizer/prep/prepunion.c
index 968b9ded78..0b173466cf 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.61 2001/03/22 03:59:38 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/optimizer/prep/prepunion.c,v 1.62 2001/03/27 18:02:19 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -679,7 +679,7 @@ adjust_inherited_attrs_mutator(Node *node,
adjust_inherited_attrs_mutator((Node *) oldinfo->clause, context);
newinfo->subclauseindices = NIL;
- newinfo->eval_cost = -1;/* reset this too */
+ newinfo->eval_cost = -1; /* reset this too */
newinfo->left_pathkey = NIL; /* and these */
newinfo->right_pathkey = NIL;
newinfo->left_dispersion = -1;
@@ -692,6 +692,29 @@ 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.
*/
+
+ /*
+ * BUT: although we don't need to recurse into subplans, we do need to
+ * make sure that they are copied, not just referenced as
+ * expression_tree_mutator will do by default. Otherwise we'll have the
+ * same subplan node referenced from each arm of the inheritance APPEND
+ * plan, which will cause trouble in the executor. This is a kluge
+ * that should go away when we redesign querytrees.
+ */
+ if (is_subplan(node))
+ {
+ SubPlan *subplan;
+
+ /* Copy the node and process subplan args */
+ node = expression_tree_mutator(node, adjust_inherited_attrs_mutator,
+ (void *) context);
+ /* Make sure we have separate copies of subplan and its rtable */
+ subplan = (SubPlan *) ((Expr *) node)->oper;
+ subplan->plan = copyObject(subplan->plan);
+ subplan->rtable = copyObject(subplan->rtable);
+ return node;
+ }
+
return expression_tree_mutator(node, adjust_inherited_attrs_mutator,
(void *) context);
}