Re: BUG #18525: Boolean aggregate functions like EVERY/BOOL_AND should shortcut

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: blamario(at)protonmail(dot)com
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18525: Boolean aggregate functions like EVERY/BOOL_AND should shortcut
Date: 2024-06-28 19:04:02
Message-ID: 2001236.1719601442@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)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

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2024-06-28 19:13:53 Re: BUG #18526: 'UPDATE' inconsistency using index scan with 'NOT EXIST' after upgrading to PostgreSQL 16
Previous Message Christophe Pettus 2024-06-28 17:57:43 Re: BUG #18526: 'UPDATE' inconsistency using index scan with 'NOT EXIST' after upgrading to PostgreSQL 16