pgsql: Disallow pushing volatile qual expressions down into DISTINCT su - Mailing list pgsql-committers

From Tom Lane
Subject pgsql: Disallow pushing volatile qual expressions down into DISTINCT su
Date
Msg-id E1X0aaA-0007OC-16@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Disallow pushing volatile qual expressions down into DISTINCT subqueries.

A WHERE clause applied to the output of a subquery with DISTINCT should
theoretically be applied only once per distinct row; but if we push it
into the subquery then it will be evaluated at each row before duplicate
elimination occurs.  If the qual is volatile this can give rise to
observably wrong results, so don't do that.

While at it, refactor a little bit to allow subquery_is_pushdown_safe
to report more than one kind of restrictive condition without indefinitely
expanding its argument list.

Although this is a bug fix, it seems unwise to back-patch it into released
branches, since it might de-optimize plans for queries that aren't giving
any trouble in practice.  So apply to 9.4 but not further back.

Branch
------
REL9_4_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/6327f25dddba0c359f8be8395e1b2d99dfe0d30c

Modified Files
--------------
src/backend/optimizer/path/allpaths.c   |  160 ++++++++++++++++++++-----------
src/test/regress/expected/subselect.out |   29 ++++++
src/test/regress/sql/subselect.sql      |   13 +++
3 files changed, 148 insertions(+), 54 deletions(-)


pgsql-committers by date:

Previous
From: Tom Lane
Date:
Subject: pgsql: Get rid of bogus separate pg_proc entries for json_extract_path
Next
From: Tom Lane
Date:
Subject: pgsql: Disallow pushing volatile qual expressions down into DISTINCT su