Re: Optimize mul_var() for var1ndigits >= 8
Joel Jacobson <joel@compiler.org>
From: "Joel Jacobson" <joel@compiler.org>
To: "Dean Rasheed" <dean.a.rasheed@gmail.com>
Cc: "Tom Lane" <tgl@sss.pgh.pa.us>,
pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2024-08-12T10:47:08Z
Lists: pgsql-hackers
Attachments
- numeric_mul_rscale.txt (text/plain)
- plausible_rscale_adjustments.csv (text/csv)
- test-mul_var-init.sql (application/octet-stream)
- test-mul_var-verify.sql (application/octet-stream)
On Sun, Aug 11, 2024, at 22:04, Joel Jacobson wrote:
>> Attachments:
>> * v4-0001-Extend-mul_var_short-to-5-and-6-digit-inputs.patch
>> * v4-0002-Optimise-numeric-multiplication-using-base-NBASE-.patch
>
> I've reviewed and tested both patches and think they are ready to be committed.
In addition, I've also tested reduced rscale specifically, due to what you wrote earlier:
> 2). Attempt to fix the formulae incorporating maxdigits mentioned
> above. This part really made my brain hurt, and I'm still not quite
> sure that I've got it right. In particular, it needs double-checking
> to ensure that it's not losing accuracy in the reduced-rscale case.
To test if there are any differences that actually matter in the result,
I patched mul_var to log what combinations that occur when running
the test suite:
```
if (rscale != var1->dscale + var2->dscale)
{
printf("NUMERIC_REDUCED_RSCALE %d,%d,%d,%d,%d\n", var1ndigits, var2ndigits, var1->dscale, var2->dscale, rscale - (var1->dscale + var2->dscale));
}
```
I also added a SQL-callable numeric_mul_rscale(var1, var2, rscale_adjustment) function,
to be able to check for differences for the reduced rscale combinations.
I then ran the test suite against my db and extracted the seen combinations:
```
make installcheck
grep -E "^NUMERIC_REDUCED_RSCALE \d+,\d+,\d+,\d+,-\d+$" logfile | sort -u | awk '{print $2}' > plausible_rscale_adjustments.csv
```
This test didn't produce any differences between HEAD and the two patches applied.
% psql -f test-mul_var-verify.sql
CREATE TABLE
COPY 1413
var1ndigits | var2ndigits | var1dscale | var2dscale | rscale_adjustment | var1 | var2 | expected | numeric_mul_rscale
-------------+-------------+------------+------------+-------------------+------+------+----------+--------------------
(0 rows)
Attaching patch as .txt to not confuse cfbot.
Regards,
Joel
Commits
-
Optimise numeric multiplication using base-NBASE^2 arithmetic.
- 8dc28d7eb868 18.0 landed
-
Extend mul_var_short() to 5 and 6-digit inputs.
- c4e44224cf61 18.0 landed