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

From Dmytro Astapov
Subject Re: array_agg(anyarray) silently produces corrupt results with parallel workers when inputs mix NULL and non-NULL array elements
Date
Msg-id CAFQUnFiK=j6AudmHLWsdFTazeUd3o3CgEKiqk97V-1kSibfaZA@mail.gmail.com
Whole thread
In response to Re: array_agg(anyarray) silently produces corrupt results with parallel workers when inputs mix NULL and non-NULL array elements  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: array_agg(anyarray) silently produces corrupt results with parallel workers when inputs mix NULL and non-NULL array elements
List pgsql-bugs


On Sat, Apr 4, 2026 at 5:41 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
Dmytro Astapov <dastapov@gmail.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

pgsql-bugs by date:

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