| From: | Jeevan Chalke <jeevan(dot)chalke(at)enterprisedb(dot)com> |
|---|---|
| To: | Vaibhav Dalvi <vaibhav(dot)dalvi(at)enterprisedb(dot)com> |
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>, Dean Rasheed <dean(dot)a(dot)rasheed(at)gmail(dot)com>, Jim Jones <jim(dot)jones(at)uni-muenster(dot)de> |
| Subject: | Re: Add PRODUCT() aggregate function |
| Date: | 2026-11-23 12:53:37 |
| Message-ID: | CAM2+6=VppSxqZ2e0KnRpXB+b58Qehx2y6tBLsqwxR5SeP9ZA6g@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
v4 attached.
Rebased on latest HEAD. The rebase surfaced a duplicate OID (4551) in the
catalog data, so I renumbered the OIDs assigned to the new product()
entries. There are no functional changes relative to v3. make check-world
passes.
As before, the patch does not bump CATALOG_VERSION_NO, to avoid conflicts
with concurrent commits.
Thanks,
On Fri, Sep 25, 2026 at 7:38 PM Vaibhav Dalvi <
vaibhav(dot)dalvi(at)enterprisedb(dot)com> wrote:
> Hi Jeevan,
>
> Patch looks good to me.
> No more comments.
>
> Regards,
> Vaibhav
>
> On Thu, Sep 24, 2026 at 1:09 PM Jeevan Chalke <
> jeevan(dot)chalke(at)enterprisedb(dot)com> wrote:
>
>>
>>
>> On Tue, Sep 22, 2026 at 7:48 PM Jeevan Chalke <
>> jeevan(dot)chalke(at)enterprisedb(dot)com> wrote:
>>
>>> Hello,
>>>
>>> On Sun, Sep 13, 2026 at 12:23 PM Vaibhav Dalvi <
>>> vaibhav(dot)dalvi(at)enterprisedb(dot)com> wrote:
>>>
>>>> Hi Jeevan,
>>>>
>>>> Thanks for the explanation and the pro() example, it is convincing.
>>>> I hadn't considered this properly earlier. for SUM the overflow
>>>> depends only on number of rows, but for PRODUCT it depends on the
>>>> values itself, so it will overflow in very few steps whenever values
>>>> are more than 1. So native fast path will help only for columns
>>>> having mostly 0, 1 or -1, not for large tables in general. I also
>>>> checked int128.h and you are right, there is no existing function
>>>> for overflow-checked "int128 *= int64" type of multiply, so this
>>>> needs new code, not reuse of the SUM(int8) pattern. So agree, fine to
>>>> take this up later as a follow-up, no need to block on it.
>>>>
>>>> About your question on float8 vs numeric for float variants - I
>>>> would prefer float8. sum(float4)/sum(float8) already return
>>>> float4/float8, not numeric, so PRODUCT() staying same for float
>>>> types will be more consistent. It also avoids the overflow-primitive
>>>> problem for floats, since float just becomes Infinity instead of
>>>> erroring out. For int2/int4/int8 numeric is fine as it is.
>>>>
>>>>
>>> Thanks Vaibhav (and Dean, Jim, back in June) for pushing on this --
>>> agreed,
>>> we'll switch product(float4)/product(float8) to return float8 natively
>>> rather
>>> than numeric, consistent with sum(float4)/sum(float8).
>>>
>>> Will post v3 with this change (float4/float8 -> float8) soon.
>>>
>>
>> v3 attached.
>>
>> product(float4)/product(float8) now return double precision natively (no
>> longer numeric), matching sum(float4)/sum(float8).
>>
>> Note: Like sum(), a finite product that would overflow double precision
>> raises an error rather than silently becoming Infinity -- Infinity only
>> results when it's already present in the input. Added a regression test
>> covering this.
>>
>> Thanks,
>>
>> --
>> *Jeevan Chalke*
>> *Senior Principal Engineer, Engineering Manager*
>> *Product Development*
>>
>> enterprisedb.com <https://www.enterprisedb.com>
>>
>
--
*Jeevan Chalke*
*Senior Principal Engineer, Engineering Manager*
*Product Development*
| Attachment | Content-Type | Size |
|---|---|---|
| v4-0001-Add-PRODUCT-aggregate-function.patch | application/octet-stream | 48.0 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Abraham Pérez | 2026-11-23 13:20:55 | Re: JSON_SERIALIZE for JSONB returns parts of the internal JSONB representation |
| Previous Message | Maxim Orlov | 2026-11-23 12:44:29 | Re: [PATCH] Add support for INSERT ... SET syntax |