pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: blamario@protonmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18525: Boolean aggregate functions like EVERY/BOOL_AND should shortcut
Date: Fri, 28 Jun 2024 15:04:02 -0400
Message-ID: <2001236.1719601442@sss.pgh.pa.us> (raw)
In-Reply-To: <18525-b36c2e34bde50082@postgresql.org>
References: <18525-b36c2e34bde50082@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> writes:
> I was hoping that the EVERY aggregate functions would
> _shortcut_ the aggregate as soon as a non-null value was encountered, and
> furthermore that the SELECT statement would stop searching once all results
> are established to be false.

Don't hold your breath.  That would require poking a lot of holes in
our abstract API for aggregate functions, and the potential return
seems rather, um, specialized.

You can get an efficient plan for what you want along the lines of

select
  exists(select * from large_table where field1 is not null),
  exists(select * from large_table where field2 is not null),
  ...

This will result in a scan per EXISTS() rather than just one scan,
but on the other hand the scans will be smart enough to use indexes
where helpful.  In any case they will stop at first match.

			regards, tom lane





view thread (2+ messages)

Message-ID: <2001236.1719601442@sss.pgh.pa.us>
Permalink:  ../2001236.1719601442@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2001236.1719601442@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, blamario@protonmail.com, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #18525: Boolean aggregate functions like EVERY/BOOL_AND should shortcut
  In-Reply-To: <2001236.1719601442@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox