Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m3fuF-00088x-Es for pgsql-general@arkaria.postgresql.org; Wed, 14 Jul 2021 14:30:35 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1m3fuE-0003eM-5h for pgsql-general@arkaria.postgresql.org; Wed, 14 Jul 2021 14:30:34 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m3fuD-0003eD-Sv for pgsql-general@lists.postgresql.org; Wed, 14 Jul 2021 14:30:33 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1m3fuB-0005nQ-PB for pgsql-general@lists.postgresql.org; Wed, 14 Jul 2021 14:30:32 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 16EEUT0T3484553; Wed, 14 Jul 2021 10:30:29 -0400 From: Tom Lane To: Luca Ferrari cc: pgsql-general Subject: Re: statistic target and sample rate In-reply-to: References: Comments: In-reply-to Luca Ferrari message dated "Wed, 14 Jul 2021 10:26:31 +0200" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <3484551.1626273029.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 14 Jul 2021 10:30:29 -0400 Message-ID: <3484552.1626273029@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Luca Ferrari writes: > Therefore my question is about how the statistic collectore decides > about the number of tuples to be sampled. It's basically 300 times the largest statistics target: https://git.postgresql.org/gitweb/?p=3Dpostgresql.git;a=3Dblob;f=3Dsrc/bac= kend/commands/analyze.c;h=3D0c9591415e4b97dd5c5e693af1860294284a1575;hb=3D= HEAD#l1919 Per that comment, there is good math backing this choice for the task of making a histogram. It's a little shakier for other sorts of statistics --- notably, for n_distinct estimation, the error can still be really bad. regards, tom lane