Re: Block various aggregate component functions from being called directly

From: Zsolt Parragi <zsolt(dot)parragi(at)percona(dot)com>
To: David Rowley <dgrowleyml(at)gmail(dot)com>
Cc: pgsql-hackers(at)lists(dot)postgresql(dot)org
Subject: Re: Block various aggregate component functions from being called directly
Date: 2026-11-19 22:04:13
Message-ID: CAN4CZFNkUxx83N8-pLkW6BRABYHrNfHGbgDMdDijPhCwdoBy4w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Thu, 19 Nov 2026, David Rowley <dgrowleyml(at)gmail(dot)com> wrote:
> We're getting bug reports (e.g., [1][2]) complaining about various
> aggregate component functions that don't do the right thing in some
> weird cases. E.g., no overflow error from:
>
> SELECT int2_avg_accum_inv('{1,9223372036854775807}'::int8[], -1::int2);
>
> But who would do that?!

I agree with the part that these report make little sense. While in an
ideal world there would be no bugs, even nitpick ones like this, the
reality is that there are far more important things to fix.

My approach to dealing with these generally is to try to keep new code
as correct as possible, including fixing even unlikely corner case
bugs when working on a specific area of the code, but otherwise leave
existing code as-is unless there is another good reason for editing
it, at which point I might as well fix that too. This of course only
helps with llm self-reviews, and doesn't make outside bug reports less
likely, other than the part where it slowly makes the codebase better.

> But you can still use these in CREATE AGGREGATE, and I suppose CREATE
> OPERATOR too, and even CREATE FUNCTION if you want to bypass it.
>
> ...
>
> The attached is a proof-of-concept patch for discussion. Is it worth
> me continuing with this?

That part is the problem, for example Claude still happily points out
that even with the patch:

CREATE AGGREGATE my_inv(int2) (sfunc = int2_avg_accum_inv, stype = int8[],
initcond = '{1,9223372036854775807}');
SELECT my_inv(-1::int2);
my_inv
--------------------------
{0,-9223372036854775808}

So I don't think this change would prevent from these reports, they
will just find different reproducers. It might have the opposite
effect, where because of the chance more agents start to look into
this area, and send even more bug reports.

> It seems like the new reality that people are using LLMs or fuzz
> testing, and the robots are classifying these as bugs, and we're
> getting reports complaining about it.

Also, you don't even need fuzzing for this, LLMs quite often find
these type of issues simply by code reading and reasoning. My setups
have very detailed instructions about what to classify as bugs and how
to triage their seriousness, but even with that they sometimes do
report issues like this as critical. Even if we manage to completely
hide these cases from the SQL interface (and I'm not sure if that is
possible), they could still find and report it.

In response to

Browse pgsql-hackers by date

  From Date Subject
Previous Message Nathan Bossart 2026-11-19 21:58:54 pg_dump: remove restore.sql from tar format