Definitional issue: stddev_pop (and related) for 1 input - Mailing list pgsql-hackers

From Tom Lane
Subject Definitional issue: stddev_pop (and related) for 1 input
Date
Msg-id 353062.1591898766@sss.pgh.pa.us
Whole thread Raw
Responses Re: Definitional issue: stddev_pop (and related) for 1 input  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Before v12, stddev_pop() had the following behavior with just a
single input value:

regression=# SELECT stddev_pop('42'::float8);
 stddev_pop 
------------
          0
(1 row)

regression=# SELECT stddev_pop('inf'::float8);
 stddev_pop 
------------
        NaN
(1 row)

regression=# SELECT stddev_pop('nan'::float8);
 stddev_pop 
------------
        NaN
(1 row)

As of v12, though, all three cases produce 0.  I am not sure what
to think about that with respect to an infinity input, but I'm
quite sure I don't like it for NaN input.

It looks like the culprit is the introduction of the "Youngs-Cramer"
algorithm in float8_accum: nothing is done to Sxx at the first iteration,
even if the input is inf or NaN.  I'd be inclined to force Sxx to NaN
when the first input is NaN, and perhaps also when it's Inf.
Alternatively we could clean up in the finalization routine by noting
that Sx is Inf/NaN, but that seems messier.  Thoughts?

(I came across this by noting that the results don't agree with
numeric accumulation, which isn't using Youngs-Cramer.)

            regards, tom lane



pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: hashagg slowdown due to spill changes
Next
From: Jeff Davis
Date:
Subject: Re: hashagg slowdown due to spill changes