Doc: improve user docs and code comments about EXISTS(SELECT * ...).

Point out that Postgres automatically optimizes away the target list
of an EXISTS' subquery, except in weird cases such as target lists
containing set-returning functions.  Thus, both common conventions
EXISTS(SELECT * FROM ...) and EXISTS(SELECT 1 FROM ...) are
overhead-free and there's little reason to prefer one over the other.

In the code comments, mention that the SQL spec says that
EXISTS(SELECT * FROM ...) should be interpreted as EXISTS(SELECT
some-literal FROM ...), but we don't choose to do it exactly that way.

Author: Peter Eisentraut <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Discussion: 
https://postgr.es/m/[email protected]

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/65a3ff8f1be0186a9c207821bcf0f543545a04d9

Modified Files
--------------
doc/src/sgml/func/func-subquery.sgml   | 10 ++++++++--
src/backend/optimizer/plan/subselect.c |  8 +++++++-
2 files changed, 15 insertions(+), 3 deletions(-)

Reply via email to