| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Doc: improve user docs and code comments about EXISTS(SELECT * . |
| Date: | 2026-02-27 20:20:27 |
| Message-ID: | E1vw4K3-001S0r-0N@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
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 <peter(at)eisentraut(dot)org>
Reviewed-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/9b301c70-3909-4f0f-98ca-9e3c4d142f3e@eisentraut.org
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(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Peter Eisentraut | 2026-02-27 21:04:48 | pgsql: Fix some -Wcast-qual warnings |
| Previous Message | Tom Lane | 2026-02-27 17:54:11 | pgsql: Don't flatten join alias Vars that are stored within a GROUP RTE |