pg.ddx.io pgsql-committers@postgresql.org mailing list archivehelp / color / mirror / Atom feed
pgsql: Fix mishandling of NaN counts in numeric_[avg_]combine. 6+ messages / 1 participants [nested] [flat]
* pgsql: Fix mishandling of NaN counts in numeric_[avg_]combine. @ 2020-06-11 21:39 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2020-06-11 21:39 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 ------ master Details ------- https://git.postgresql.org/pg/commitdiff/77a3be32f7c16538bc4e05edad85560d9f88369b Modified Files -------------- src/backend/utils/adt/numeric.c | 12 ++--- src/test/regress/expected/aggregates.out | 82 ++++++++++++++++++++++++++------ src/test/regress/sql/aggregates.sql | 30 ++++++++++-- 3 files changed, 101 insertions(+), 23 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix mishandling of NaN counts in numeric_[avg_]combine. @ 2020-06-11 21:39 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2020-06-11 21:39 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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_13_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/ee788ba99011c9d1e8f6f352acc0b0d19350fff6 Modified Files -------------- src/backend/utils/adt/numeric.c | 12 ++--- src/test/regress/expected/aggregates.out | 82 ++++++++++++++++++++++++++------ src/test/regress/sql/aggregates.sql | 30 ++++++++++-- 3 files changed, 101 insertions(+), 23 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix mishandling of NaN counts in numeric_[avg_]combine. @ 2020-06-11 21:39 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2020-06-11 21:39 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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_12_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/4284e1184692019da656a0f78748363fd2b40f47 Modified Files -------------- src/backend/utils/adt/numeric.c | 12 ++--- src/test/regress/expected/aggregates.out | 82 ++++++++++++++++++++++++++------ src/test/regress/sql/aggregates.sql | 30 ++++++++++-- 3 files changed, 101 insertions(+), 23 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix mishandling of NaN counts in numeric_[avg_]combine. @ 2020-06-11 21:39 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2020-06-11 21:39 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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_11_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/49e0a42dd584d665adc0182f1f0bb8eb848498d1 Modified Files -------------- src/backend/utils/adt/numeric.c | 12 ++--- src/test/regress/expected/aggregates.out | 82 ++++++++++++++++++++++++++------ src/test/regress/sql/aggregates.sql | 30 ++++++++++-- 3 files changed, 101 insertions(+), 23 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix mishandling of NaN counts in numeric_[avg_]combine. @ 2020-06-11 21:39 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2020-06-11 21:39 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
* pgsql: Fix mishandling of NaN counts in numeric_[avg_]combine. @ 2020-06-11 21:39 Tom Lane <tgl@sss.pgh.pa.us> 0 siblings, 0 replies; 6+ messages in thread From: Tom Lane @ 2020-06-11 21:39 UTC (permalink / raw) To: pgsql-committers@lists.postgresql.org 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 ------ REL9_6_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/36df06e25c4a6f5be6132d56047063052af5ea76 Modified Files -------------- src/backend/utils/adt/numeric.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) ^ permalink raw reply [nested|flat] 6+ messages in thread
end of thread, other threads:[~2020-06-11 21:39 UTC | newest] Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2020-06-11 21:39 pgsql: Fix mishandling of NaN counts in numeric_[avg_]combine. Tom Lane <tgl@sss.pgh.pa.us> 2020-06-11 21:39 pgsql: Fix mishandling of NaN counts in numeric_[avg_]combine. Tom Lane <tgl@sss.pgh.pa.us> 2020-06-11 21:39 pgsql: Fix mishandling of NaN counts in numeric_[avg_]combine. Tom Lane <tgl@sss.pgh.pa.us> 2020-06-11 21:39 pgsql: Fix mishandling of NaN counts in numeric_[avg_]combine. Tom Lane <tgl@sss.pgh.pa.us> 2020-06-11 21:39 pgsql: Fix mishandling of NaN counts in numeric_[avg_]combine. Tom Lane <tgl@sss.pgh.pa.us> 2020-06-11 21:39 pgsql: Fix mishandling of NaN counts in numeric_[avg_]combine. Tom Lane <tgl@sss.pgh.pa.us>
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