]> granicus.if.org Git - postgresql/commit
Disallow pushing volatile qual expressions down into DISTINCT subqueries.
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 27 Jun 2014 18:08:51 +0000 (11:08 -0700)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 27 Jun 2014 18:08:51 +0000 (11:08 -0700)
commit6327f25dddba0c359f8be8395e1b2d99dfe0d30c
tree579c187830953768a4aef240558187442d643edb
parentc3096d57c8faa24aa5ff4cc7e87d989ce42ad05d
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.
src/backend/optimizer/path/allpaths.c
src/test/regress/expected/subselect.out
src/test/regress/sql/subselect.sql