From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix mishandling of NaN counts in numeric_[avg_]combine.
Date: Thu, 11 Jun 2020 21:39:30 +0000
Message-ID: <E1jjUv4-0002op-6W@gemulon.postgresql.org> (raw)
Fix mishandling of NaN counts in numeric_[avg_]combine.
When merging two NumericAggStates, the code missed adding the new
state's NaNcount unless its N was also nonzero; since those counts
are independent, this is wrong.
This would only have visible effect if some partial aggregate scans
found only NaNs while earlier ones found only non-NaNs; then we could
end up falsely deciding that there were no NaNs and fail to return a
NaN final result as expected. That's pretty improbable, so it's no
surprise this hasn't been reported from the field. Still, it's a bug.
I didn't try to produce a regression test that would show the bug,
but I did notice that these functions weren't being reached at all
in our regression tests, so I improved the tests to at least
exercise them. With these additions, I see pretty complete code
coverage on the aggregation-related functions in numeric.c.
Back-patch to 9.6 where this code was introduced. (I only added
the improved test case as far back as v10, though, since the
relevant part of aggregates.sql isn't there at all in 9.6.)
Branch
------
REL_10_STABLE
Details
-------
https://git.postgresql.org/pg/commitdiff/411a4626e48576a74414d2a24e950f37909134f1
Modified Files
--------------
src/backend/utils/adt/numeric.c | 12 ++---
src/test/regress/expected/aggregates.out | 80 +++++++++++++++++++++++++++-----
src/test/regress/sql/aggregates.sql | 32 +++++++++++--
3 files changed, 103 insertions(+), 21 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: Fix mishandling of NaN counts in numeric_[avg_]combine.
In-Reply-To: <E1jjUv4-0002op-6W@gemulon.postgresql.org>
References: <E1jjUv4-0002op-6W@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