git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 9bf760f)
Suppress subquery pullup/pushdown when a subquery contains volatile
2006年8月19日 02:48:53 +0000 (02:48 +0000)
2006年8月19日 02:48:53 +0000 (02:48 +0000)
functions in its targetlist, to avoid introducing multiple evaluations
of volatile functions that textually appear only once. This is a
slightly tighter version of Jaime Casanova's recent patch.


diff --git a/src/backend/optimizer/path/allpaths.c b/src/backend/optimizer/path/allpaths.c
index fc618f72d1cc0878fafc8bff66a113c718de9391..794c14fbbabc2b05f1e468daa607e87a0d5734b2 100644 (file)
--- a/src/backend/optimizer/path/allpaths.c
+++ b/src/backend/optimizer/path/allpaths.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.151 2006年08月10日 02:36:28 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/path/allpaths.c,v 1.152 2006年08月19日 02:48:53 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -871,6 +871,10 @@ compare_tlist_datatypes(List *tlist, List *colTypes,
* 5. We must not push down any quals that refer to subselect outputs that
* return sets, else we'd introduce functions-returning-sets into the
* subquery's WHERE/HAVING quals.
+ *
+ * 6. We must not push down any quals that refer to subselect outputs that
+ * contain volatile functions, for fear of introducing strange results due
+ * to multiple evaluation of a volatile function.
*/
static bool
qual_is_pushdown_safe(Query *subquery, Index rti, Node *qual,
@@ -940,6 +944,13 @@ qual_is_pushdown_safe(Query *subquery, Index rti, Node *qual,
safe = false;
break;
}
+
+ /* Refuse volatile functions (point 6) */
+ if (contain_volatile_functions((Node *) tle->expr))
+ {
+ safe = false;
+ break;
+ }
}
list_free(vars);
diff --git a/src/backend/optimizer/prep/prepjointree.c b/src/backend/optimizer/prep/prepjointree.c
index ef92d9d3c9f33cb54e013f583dfa6d4849f90001..bea7c03a739e3ad01b89a1abb2b5a08d682ea945 100644 (file)
--- a/src/backend/optimizer/prep/prepjointree.c
+++ b/src/backend/optimizer/prep/prepjointree.c
@@ -15,7 +15,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.42 2006年08月12日 20:05:55 tgl Exp $
+ * $PostgreSQL: pgsql/src/backend/optimizer/prep/prepjointree.c,v 1.43 2006年08月19日 02:48:53 tgl Exp $
*
*-------------------------------------------------------------------------
*/
@@ -656,6 +656,15 @@ is_simple_subquery(Query *subquery)
if (expression_returns_set((Node *) subquery->targetList))
return false;
+ /*
+ * Don't pull up a subquery that has any volatile functions in its
+ * targetlist. Otherwise we might introduce multiple evaluations of
+ * these functions, if they get copied to multiple places in the upper
+ * query, leading to surprising results.
+ */
+ if (contain_volatile_functions((Node *) subquery->targetList))
+ return false;
+
/*
* Hack: don't try to pull up a subquery with an empty jointree.
* query_planner() will correctly generate a Result plan for a jointree
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /