From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | pgsql-committers(at)postgresql(dot)org |
Subject: | pgsql: Disallow pushing volatile qual expressions down into DISTINCT su |
Date: | 2014-06-27 18:09:06 |
Message-ID: | E1X0aaA-0007OC-16@gemulon.postgresql.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(-)
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2014-06-27 18:46:45 | pgsql: Fix broken Assert() introduced by 8e9a16ab8f7f0e58 |
Previous Message | Tom Lane | 2014-06-26 23:22:29 | pgsql: Get rid of bogus separate pg_proc entries for json_extract_path |