Re: Re: sampling.c and potential divisions by 0 ang log(0) with tablesample and ANALYZE in 9.5 - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Re: sampling.c and potential divisions by 0 ang log(0) with tablesample and ANALYZE in 9.5
Date
Msg-id 6321.1435681035@sss.pgh.pa.us
Whole thread Raw
In response to Re: sampling.c and potential divisions by 0 ang log(0) with tablesample and ANALYZE in 9.5  (Petr Jelinek <petr@2ndquadrant.com>)
Responses Re: Re: sampling.c and potential divisions by 0 ang log(0) with tablesample and ANALYZE in 9.5  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: Re: sampling.c and potential divisions by 0 ang log(0) with tablesample and ANALYZE in 9.5  (Michael Paquier <michael.paquier@gmail.com>)
List pgsql-bugs
Petr Jelinek <petr@2ndquadrant.com> writes:
> On 2015-06-25 10:01, Michael Paquier wrote:
>> I think that we should change the returned double to be (0.0,1.0]

> Agreed.

I find this to be a pretty bad idea.  That definition is simply weird;
where else in the world will you find a random number generator that does
that?  What are the odds that any callers are actually designed for that
behavior?

Another problem is that we consider anl_random_fract() to be an exported
API, and the very longstanding definition of that is that the result is
in (0,1), excluding both endpoints.  Whatever we do with
sampler_random_fract(), we'd better make sure that anl_random_fract()
preserves that behavior, else we are likely to break third-party modules.

A simple fix would be to adjust sampler_random_fract to disallow 0
as result, say by repeating the pg_erand48 call if it produces 0.
I'm not sure if that would throw off any of the math in the new
tablesample-related callers.  If it would, I'm inclined to fix the
problem call-site-by-call-site, rather than inventing a definition
of sampler_random_fract() that fails to satisfy the POLA.

            regards, tom lane

pgsql-bugs by date:

Previous
From: vinothkumar.rajendran@tcs.com
Date:
Subject: BUG #13475: Access Denied
Next
From: Tom Lane
Date:
Subject: Re: Re: sampling.c and potential divisions by 0 ang log(0) with tablesample and ANALYZE in 9.5