Re: Optimize SELECT * in EXISTS

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Optimize SELECT * in EXISTS
Date: 2026-02-24 20:04:50
Message-ID: 88a5b7c5-ae5e-4dd7-aec9-a87b7f5f0e88@eisentraut.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 23.02.26 09:41, David Rowley wrote:
> On Mon, 23 Feb 2026 at 21:21, Peter Eisentraut <peter(at)eisentraut(dot)org> wrote:
>> I read in the SQL standard that SELECT * in EXISTS is not supposed to be
>> expanded to all columns, but only to an arbitrary literal. This
>> corresponds to the recommendation in the PostgreSQL documentation to
>> write EXISTS (SELECT 1 ...) instead. But not even our own tests and
>> example code use that latter convention consistently, so I think many
>> users don't know it or observe it either. So implementing that little
>> optimization for SELECT * seems reasonable.
>
>> Thoughts?
>
> Don't we already do this in simplify_EXISTS_query()?

It appears so, but then I think we should update the documentation along
the lines I showed, because I found it misleading about this. New
docs-only patch attached.

Attachment Content-Type Size
v2-0001-doc-Document-SELECT-in-EXISTS-optimizations.patch text/plain 3.0 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Zsolt Parragi 2026-02-24 20:09:35 Re: pg_dumpall --roles-only interact with other options
Previous Message Tom Lane 2026-02-24 19:59:47 Re: centralize CPU feature detection