From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Make float8_regr_combine() handle edge cases like float8_regr_ac
Date: Thu, 12 Nov 2026 17:18:36 +0000
Message-ID: <E1xRYRY-00000000ScM-3JW1@gemulon.postgresql.org> (raw)
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@gmail.com>
Author: Venu Kummari <venu2805k@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/19826-4b769cb5342fdfe7@postgresql.org
Backpatch-through: 19
Branch
------
master
Details
-------
https://git.postgresql.org/pg/commitdiff/ef1b740441cbd88f8f4c68737235cce17bfac508
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(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: tgl@sss.pgh.pa.us
Subject: Re: pgsql: Make float8_regr_combine() handle edge cases like float8_regr_ac
In-Reply-To: <E1xRYRY-00000000ScM-3JW1@gemulon.postgresql.org>
References: <E1xRYRY-00000000ScM-3JW1@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox