Re: Use local buffer for packed numerics

From: Andrei Lepikhov <lepihov(at)gmail(dot)com>
To: Josh Hurst <joshhurst77(at)gmail(dot)com>
Cc: geidav(dot)pg(at)gmail(dot)com, pgsql-hackers(at)lists(dot)postgresql(dot)org, "andreas(at)proxel(dot)se" <andreas(at)proxel(dot)se>
Subject: Re: Use local buffer for packed numerics
Date: 2026-11-28 14:07:59
Message-ID: a3ed87e5-6d93-4694-ab57-76094b600938@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 28/11/2026 02:08, Josh Hurst wrote:
> Would the arithmetic be worth pursuing separately?
Yes, by the way, I have the 'fast arithmetic' and 'fast aggregate' parts of this
numeric speedup series of improvements too. Our arithmetic part looks pretty
similar, but aggregates are optimised a little differently. In the attachment,
both optimisations.
In my version, code is tuned by Claude to gain as much benefit as possible,
because it is designed to speed up a production ERP. Here is the performance
gain of the 'fast arithmetic' patchset:

Change in execution time vs. master. gcc 14.2 -O2, 2M-row table, average of
three attempts for each query.

Query Intel AMD Arm
------------------------------------- ------ ------ ------
count(v * q) -37% -28% -20%
count(v + q) -45% -35% -30%
count(*) WHERE v + q > v * 1.1 -52% -34% -29%
sum(price * (1 - disc) * (1 + tax)) -39% -22% -27%
TPC-H Q1 (data generated) -37% -22% -22%
sum(v * q), 500k groups -14% -9% -8%

The aggregate part basically shows less interesting numbers in terms of
execution time, but it provides a nice reduction in memory consumption for Hash
Aggregate:

Query master patched change
----------------------------------------- ------- ------- -------
sum(v), 500k groups 192 MB 80 MB -58%
sum(w), 500k groups 240 MB 80 MB -67%
sum(x), 500k groups 240 MB 208 MB -13%
sum(v), 2M groups 744 MB 288 MB -61%

v: numeric(12,2), q: numeric(8,3), w: numeric(30,6), x: 45 digits.

It would be nice to continue work on these improvements. For now, no one in the
community has said these improvements are worth the code changes required. So,
feel free to begin two new threads and use my version of the code, if it makes
sense.

--
regards, Andrei Lepikhov,
pgEdge

Attachment Content-Type Size
arithmetics.zip application/zip 13.7 KB
aggregates.zip application/zip 25.1 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Xuneng Zhou 2026-11-28 14:15:13 Re: Set 1s WaitLatch timeout if standby limit has expired in ResolveRecoveryConflictWithBufferPin
Previous Message Zhijie Hou 2026-11-28 14:05:14 Fix unrecognized scankey subtype error with SP-GiST exclusion constraints