| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | pgsql-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgsql: Make float8_regr_combine() handle edge cases like float8_regr_ac |
| Date: | 2026-11-12 17:18:36 |
| Message-ID: | E1xRYRY-00000000ScO-3PHC@gemulon.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-committers |
Make float8_regr_combine() handle edge cases like float8_regr_accum().
Commit 649828769 taught float8_regr_accum() to keep Sxx, Syy and Sxy
exactly zero while all the inputs for X (or Y) are the same, so that
corr() and the regr_*() functions return NULL for a constant input.
Then 7774249d0 made it force Sxy to NaN when one input is constant
and the other is Inf or NaN. float8_regr_combine() got neither
change: it still added the correction terms computed from the rounded
sums Sx1 and Sx2, which are usually slightly nonzero even when both
states saw the same single value. Thus, the edge cases those commits
intended to fix occurred anyway under parallel aggregation.
To fix, skip each correction term when the corresponding input(s)
have a common value, and force Sxy to NaN when the Sxy correction
is skipped and the other input has seen an Inf or NaN.
Also, make the overflow handling in float8_regr_combine() look more
like float8_regr_accum(). It might have worked out the same in terms
of when we throw error or don't, but even if that's true, proving it
and then keeping it true in the future requires brain cells readers
shouldn't have to expend.
In the existing direct test of float8_regr_combine(), the two states
are those of the regr_test rows with x IN (10,20,30) and x IN (80,100),
but their commonX/commonY entries didn't match that data. Set them
to NaN, so that the test exercises the correction terms and its result
again agrees with the aggregates over the whole table. Also test that
overflow is reported and that an infinite input is not an overflow.
Bug: #19826
Reported-by: Venu Kummari <venu2805k(at)gmail(dot)com>
Author: Venu Kummari <venu2805k(at)gmail(dot)com>
Reviewed-by: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Discussion: https://postgr.es/m/19826-4b769cb5342fdfe7@postgresql.org
Backpatch-through: 19
Branch
------
REL_19_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/30e70fa76faf4b1d6b27bd744cdc49cff8466011
Modified Files
--------------
src/backend/utils/adt/float.c | 73 ++++++++++++++++++++++-----
src/test/regress/expected/aggregates.out | 87 ++++++++++++++++++++++++++++++--
src/test/regress/sql/aggregates.sql | 38 +++++++++++++-
3 files changed, 178 insertions(+), 20 deletions(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2026-11-12 19:53:25 | pgsql: Fix assorted confusion about parameter names. |
| Previous Message | Tom Lane | 2026-11-12 16:48:13 | pgsql: plpython: share the SD dictionary across cache entries of a func |