Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZA0dh-00030u-Jn for pgsql-bugs@arkaria.postgresql.org; Tue, 30 Jun 2015 18:52:13 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZA0dh-0001PS-4X for pgsql-bugs@arkaria.postgresql.org; Tue, 30 Jun 2015 18:52:13 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZA0df-0001Ow-UX for pgsql-bugs@postgresql.org; Tue, 30 Jun 2015 18:52:12 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZA0dd-0006gZ-Hh for pgsql-bugs@postgresql.org; Tue, 30 Jun 2015 18:52:10 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id t5UIq2B0031446; Tue, 30 Jun 2015 14:52:02 -0400 From: Tom Lane To: Petr Jelinek cc: Michael Paquier , PostgreSQL mailing lists Subject: Re: Re: sampling.c and potential divisions by 0 ang log(0) with tablesample and ANALYZE in 9.5 In-reply-to: <5592CE94.1000208@2ndquadrant.com> References: <558E09FB.6010909@2ndquadrant.com> <6321.1435681035@sss.pgh.pa.us> <6412.1435681288@sss.pgh.pa.us> <5592CE94.1000208@2ndquadrant.com> Comments: In-reply-to Petr Jelinek message dated "Tue, 30 Jun 2015 19:15:00 +0200" Date: Tue, 30 Jun 2015 14:52:02 -0400 Message-ID: <31445.1435690322@sss.pgh.pa.us> X-Pg-Spam-Score: -2.5 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Petr Jelinek 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 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs