aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/backend/rewrite/rewriteHandler.c41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/backend/rewrite/rewriteHandler.c b/src/backend/rewrite/rewriteHandler.c
index a6e01a8b1c2..305b91202ad 100644
--- a/src/backend/rewrite/rewriteHandler.c
+++ b/src/backend/rewrite/rewriteHandler.c
@@ -7,7 +7,7 @@
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.179 2008/08/28 23:09:48 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.180 2008/09/24 16:52:46 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -347,6 +347,37 @@ rewriteRuleAction(Query *parsetree,
sub_action->rtable);
/*
+ * There could have been some SubLinks in parsetree's rtable, in which
+ * case we'd better mark the sub_action correctly.
+ */
+ if (parsetree->hasSubLinks && !sub_action->hasSubLinks)
+ {
+ ListCell *lc;
+
+ foreach(lc, parsetree->rtable)
+ {
+ RangeTblEntry *rte = (RangeTblEntry *) lfirst(lc);
+
+ switch (rte->rtekind)
+ {
+ case RTE_FUNCTION:
+ sub_action->hasSubLinks =
+ checkExprHasSubLink(rte->funcexpr);
+ break;
+ case RTE_VALUES:
+ sub_action->hasSubLinks =
+ checkExprHasSubLink((Node *) rte->values_lists);
+ break;
+ default:
+ /* other RTE types don't contain bare expressions */
+ break;
+ }
+ if (sub_action->hasSubLinks)
+ break; /* no need to keep scanning rtable */
+ }
+ }
+
+ /*
* Each rule action's jointree should be the main parsetree's jointree
* plus that rule's jointree, but usually *without* the original rtindex
* that we're replacing (if present, which it won't be for INSERT). Note
@@ -455,6 +486,14 @@ rewriteRuleAction(Query *parsetree,
rule_action->returningList,
CMD_SELECT,
0);
+
+ /*
+ * There could have been some SubLinks in parsetree's returningList,
+ * in which case we'd better mark the rule_action correctly.
+ */
+ if (parsetree->hasSubLinks && !rule_action->hasSubLinks)
+ rule_action->hasSubLinks =
+ checkExprHasSubLink((Node *) rule_action->returningList);
}
return rule_action;