Re: Re: sampling.c and potential divisions by 0 ang log(0) with tablesample and ANALYZE in 9.5

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Petr Jelinek <petr(at)2ndquadrant(dot)com>
Cc: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>, PostgreSQL mailing lists <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: Re: sampling.c and potential divisions by 0 ang log(0) with tablesample and ANALYZE in 9.5
Date: 2015-06-30 18:52:02
Message-ID: 31445.1435690322@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Petr Jelinek <petr(at)2ndquadrant(dot)com> writes:
> Right, very good point.

> So, we used to protect against this problem by using long value and doing:
> ((double) random() + 1) / ((double) MAX_RANDOM_VALUE + 2)

> Maybe best solution is to have pg_lrand48() variant which accepts seed
> as parameter same way pg_erand48() does and use the same logic we used
> to have before sampling was added.

I'm unimpressed with this coding because it presumes that MAX_RANDOM_VALUE
(which is defined as the maximum value returned by random()) has something
to do with the output range of pg_lrand48(). While that might
accidentally fail to fail on all known platforms, it's not good, because
those functions don't have the same provenance and so there's no good
reason to assume that they produce the same output range.

Rather than expanding the API of port.h still further, I continue to think
that the best answer is just to repeat if we get a zero from pg_erand48.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Petr Jelinek 2015-06-30 19:17:35 Re: Re: sampling.c and potential divisions by 0 ang log(0) with tablesample and ANALYZE in 9.5
Previous Message Petr Jelinek 2015-06-30 17:15:00 Re: Re: sampling.c and potential divisions by 0 ang log(0) with tablesample and ANALYZE in 9.5