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-0007OB-11@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
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/1147035203a47a424b2399fc74829d097b7061e4

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: Disallow pushing volatile qual expressions down into DISTINCT su
Next
From: Alvaro Herrera
Date:
Subject: pgsql: Don't allow relminmxid to go backwards during VACUUM FULL