pgsql: Make contain_volatile_functions/contain_mutable_functions look i

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Make contain_volatile_functions/contain_mutable_functions look i
Date: 2013-11-08 16:37:43
Message-ID: E1Vep43-0004ln-LG@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Make contain_volatile_functions/contain_mutable_functions look into SubLinks.

This change prevents us from doing inappropriate subquery flattening in
cases such as dangerous functions hidden inside a sub-SELECT in the
targetlist of another sub-SELECT. That could result in unexpected behavior
due to multiple evaluations of a volatile function, as in a recent
complaint from Etienne Dube. It's been questionable from the very
beginning whether these functions should look into subqueries (as noted in
their comments), and this case seems to provide proof that they should.

Because the new code only descends into SubLinks, not SubPlans or
InitPlans, the change only affects the planner's behavior during
prepjointree processing and not later on --- for example, you can still get
it to use a volatile function in an indexqual if you wrap the function in
(SELECT ...). That's a historical behavior, for sure, but it's reasonable
given that the executor's evaluation rules for subplans don't depend on
whether there are volatile functions inside them. In any case, we need to
constrain the behavioral change as narrowly as we can to make this
reasonable to back-patch.

Branch
------
REL9_3_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/9548bee2b19bee71e565a0a0aedd4d38ccb10a91

Modified Files
--------------
src/backend/optimizer/util/clauses.c | 33 +++++++++++++---
src/test/regress/expected/subselect.out | 64 +++++++++++++++++++++++++++++++
src/test/regress/sql/subselect.sql | 16 ++++++++
3 files changed, 107 insertions(+), 6 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2013-11-08 16:58:46 Re: pgsql: Fix blatantly broken record_image_cmp() logic for pass-by-value
Previous Message Kevin Grittner 2013-11-08 16:36:55 Re: pgsql: Fix blatantly broken record_image_cmp() logic for pass-by-value