X-Original-To: pgsql-admin-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 1813CD1C9E3 for ; Tue, 23 Sep 2003 17:37:33 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 25910-02 for ; Tue, 23 Sep 2003 14:37:23 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id 07379D1BB36 for ; Tue, 23 Sep 2003 14:37:22 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.10/8.12.10) with ESMTP id h8NHbGiP020331; Tue, 23 Sep 2003 13:37:16 -0400 (EDT) To: nickf@ontko.com Cc: "pgsql-admin" Subject: Re: Problem with n_distinct being consistently inaccurate. In-reply-to: References: Comments: In-reply-to "Nick Fankhauser" message dated "Tue, 23 Sep 2003 11:38:47 -0500" Date: Tue, 23 Sep 2003 13:37:16 -0400 Message-ID: <20330.1064338636@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/361 X-Sequence-Number: 10449 "Nick Fankhauser" writes: > So the question is- how can I get a better estimate of n_distinct from > analyze? > If I alter the stats target as high as it will go, I get closer, but it > still shows the index to be about 1/2 as selective as it actually is: AFAIK, estimating number of distinct values from a small sample is inherently an ill-conditioned problem. You should probably be happy it can get within a factor of 2 ;-). You could try sticking the correct n_distinct into pg_statistic by hand just to see if it really does change the plan, but I'd like to think that getting within a factor of 2 is good enough. If it's not, then we probably ought to look for ways to avoid using number-of-distinct-values statistics altogether, because we'll seldom have a hard value for it. regards, tom lane