Re: array_agg(anyarray) silently produces corrupt results with parallel workers when inputs mix NULL and non-NULL array elements

From: Dmytro Astapov <dastapov(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: array_agg(anyarray) silently produces corrupt results with parallel workers when inputs mix NULL and non-NULL array elements
Date: 2026-04-06 12:04:18
Message-ID: CAFQUnFiK=j6AudmHLWsdFTazeUd3o3CgEKiqk97V-1kSibfaZA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Sat, Apr 4, 2026 at 5:41 PM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Dmytro Astapov <dastapov(at)gmail(dot)com> writes:
>

> The initial-setup path is confused about that too, allocating
> newnitems+1 which is pointless.
>

Yes, using newnitems directly is cleaner than my Max() approach, thank you.

>
> It also troubled me that there's no checks for integer overflow
> when calculating the new sizes.

Good catch, I hadn't considered that.

> So I end with the attached revised patch, where I also made one
> or two cosmetic adjustments like putting the type-comparison checks
> next to the dimension comparisons. Look good to you?
>

Looks good, thank you for improving it.

I built and tested your v2 patch on REL_17_9 and REL_18_3 (with minor
adaptation for the slightly different context lines, like bits8 vs uint8 on
17.x), using the same 10M-row synthetic reproduction from my original
report. They both pass (as expected).

I am attaching the amended patch files for REL_17_9 and REL_18_3 just in
case.

Thank you for the feedback and for the quick turnaround on this!

Best regards, Dmytro

Attachment Content-Type Size
v2-fix_array_agg_parallel_nullbitmap-REL_17_9.patch text/x-patch 3.2 KB
v2-fix_array_agg_parallel_nullbitmap-REL_18_3.patch text/x-patch 3.3 KB

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2026-04-06 17:16:31 Re: array_agg(anyarray) silently produces corrupt results with parallel workers when inputs mix NULL and non-NULL array elements
Previous Message Tom Lane 2026-04-06 03:07:58 Re: BUG #19450: Where is checksum_block.inc.c after master install?