Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZA13n-0004Vm-Gm for pgsql-bugs@arkaria.postgresql.org; Tue, 30 Jun 2015 19:19:11 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZA13l-0001Kq-89 for pgsql-bugs@arkaria.postgresql.org; Tue, 30 Jun 2015 19:19:09 +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 1ZA12O-0008L2-2v for pgsql-bugs@postgresql.org; Tue, 30 Jun 2015 19:17:44 +0000 Received: from mail-wg0-f49.google.com ([74.125.82.49]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84) (envelope-from ) id 1ZA12L-0007Ah-A5 for pgsql-bugs@postgresql.org; Tue, 30 Jun 2015 19:17:42 +0000 Received: by wguu7 with SMTP id u7so17947452wgu.3 for ; Tue, 30 Jun 2015 12:17:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:message-id:date:from:user-agent:mime-version:to :cc:subject:references:in-reply-to:content-type :content-transfer-encoding; bh=8JquLNOXyObv2SvTh89K/oCuJ3nhqN+utu7UM/yhGtE=; b=FHTciyWukqbx0QGDgNA96nxL2abFGYQK1ktZDTbsqjPibHgz/eFCfx/NVHK6+WOvUr q5KwWEezIFLTdXQ/scmgn8Sq8sZEcuD68D1O2deCcVF9nUx+Mzcz1/oKTZ+1kBR5390/ 73DcwIU90FngahVgOTx58zwymunKDgk4NHKBCZNCyAr5sQuxbMb71Uo27AViBAMxgVXN ZJCxR4JH2Hq5n1pPo0VuHoyEfs25W2bQN6gQp+OwYrkEX4kgV8H7ZEu2BaWc/RR0syBj giY0rLLr/2UPVj1SODbVPPqntcUiXkOg7eRr2TUdiLe3SIDLOvZncdtCDql1n6GlxykT xv6A== X-Gm-Message-State: ALoCoQmtD/HBswV6dOjhYrSiXeF8i4NbGJapVLGy+hkQpp5tkXEFB0mq8zevL9yn+VCCohX+FVRCP07ZqCuADwHqKrIcExRC18mS4ysWyWdEIgFngCIpbmFNDIt0NjvF2t25NKDWgel6khwZnY5TYOY8nIpy0BM8dxt0u9MuSW9ywRwSyztVLTTICkShmC7hsttmBAlMlmbp X-Received: by 10.180.210.234 with SMTP id mx10mr36733340wic.42.1435691859211; Tue, 30 Jun 2015 12:17:39 -0700 (PDT) Received: from ?IPv6:2a00:1028:9941:52fa:e839:df84:99ef:ce5d? (dynamic-2a00-1028-9941-52fa-e839-df84-99ef-ce5d.ipv6.broadband.iol.cz. [2a00:1028:9941:52fa:e839:df84:99ef:ce5d]) by mx.google.com with ESMTPSA id e2sm44854028wjw.12.2015.06.30.12.17.36 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 Jun 2015 12:17:37 -0700 (PDT) Message-ID: <5592EB4F.8010400@2ndquadrant.com> Date: Tue, 30 Jun 2015 21:17:35 +0200 From: Petr Jelinek User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0 MIME-Version: 1.0 To: Tom Lane 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 References: <558E09FB.6010909@2ndquadrant.com> <6321.1435681035@sss.pgh.pa.us> <6412.1435681288@sss.pgh.pa.us> <5592CE94.1000208@2ndquadrant.com> <31445.1435690322@sss.pgh.pa.us> In-Reply-To: <31445.1435690322@sss.pgh.pa.us> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) 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 On 2015-06-30 20:52, Tom Lane wrote: > 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. Well, by this logic all the other places which are using MAX_RANDOM_VALUE would be broken as well as our port version of random() just calls pg_lrand48(). Not to mention that we hardwire MAX_RANDOM_VALUE to be same as PG_INT32_MAX (which we could use in the code I proposed instead of MAX_RANDOM_VALUE to be safe). > > 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. > Looping over function call until you get value you like seems quite ugly to me tbh. -- Petr Jelinek http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs