aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2008-09-24 16:53:07 +0000
committerTom Lane <tgl@sss.pgh.pa.us>2008-09-24 16:53:07 +0000
commitcd311af46ef08b52e03f633e617a346fa3176da0 (patch)
tree8ccd119365ec3ac2ca4008296f1f3d9e9369decd
parent00f3091e6082273160be8612c10ef0778af506cf (diff)
downloadpostgresql-cd311af46ef08b52e03f633e617a346fa3176da0.tar.gz
postgresql-cd311af46ef08b52e03f633e617a346fa3176da0.zip
Fix more problems with rewriter failing to set Query.hasSubLinks when inserting
a SubLink expression into a rule query. We missed cases where the original query contained a sub-SELECT in a function in FROM, a multi-row VALUES list, or a RETURNING list. Per bug #4434 from Dean Rasheed and subsequent investigation. Back-patch to 8.1; older releases don't have the issue because they didn't try to be smart about setting hasSubLinks only when needed.
-rw-r--r--src/backend/rewrite/rewriteHandler.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/backend/rewrite/rewriteHandler.c b/src/backend/rewrite/rewriteHandler.c
index bf244b7e63a..377dffaf435 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.158.2.3 2007/03/01 18:50:42 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/rewrite/rewriteHandler.c,v 1.158.2.4 2008/09/24 16:53:07 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -335,6 +335,33 @@ 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;
+ 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