From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Rowley <dgrowleyml@gmail.com>
Cc: Kaimeh <kkaimeh@gmail.com>
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: Error when using array_agg with filter where clause in pg16 and pg17
Date: Tue, 08 Apr 2025 20:25:54 -0400
Message-ID: <90177.1744158354@sss.pgh.pa.us> (raw)
In-Reply-To: <CAApHDvqb8BxPvh3wwVc1YXNWGVVw9nJ49mFsdOwzHjBji0qDPw@mail.gmail.com>
References: <CAK-+Jz9J=Q06-M7cDJoPNeYbz5EZDqkjQbJnmRyQyzkbRGsYkA@mail.gmail.com>
<4040920.1744126348@sss.pgh.pa.us>
<CAApHDvqb8BxPvh3wwVc1YXNWGVVw9nJ49mFsdOwzHjBji0qDPw@mail.gmail.com>
David Rowley <dgrowleyml@gmail.com> writes:
> On Wed, 9 Apr 2025 at 03:32, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> The simplest fix I can think of is to disable the presorted-agg
>> optimization if (1) there's a FILTER clause and (2) the proposed
>> sort key is anything more complex than a Var.
> Unfortunately, the situation is a little worse than what you
> highlighted, as I think I didn't consider FILTER at all, and this
> means I didn't consider the costing differences between filtering then
> sorting vs sorting then filtering.
Oooh. If the FILTER clause is selective, that could easily mean that
the "optimization" loses big from having to sort many more tuples.
I wonder if we should just not apply it when there's a FILTER,
full stop.
regards, tom lane
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, dgrowleyml@gmail.com, kkaimeh@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re: Error when using array_agg with filter where clause in pg16 and pg17
In-Reply-To: <90177.1744158354@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