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: arithmetics.zip>>

<<attachment: aggregates.zip>>

Reply via email to