Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id 33D582E003B for ; Wed, 30 Apr 2008 02:19:57 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 40420-05 for ; Wed, 30 Apr 2008 02:19:52 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by developer.postgresql.org (Postfix) with ESMTP id 079732E0033 for ; Wed, 30 Apr 2008 02:19:53 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id m3U5JpMG014252; Wed, 30 Apr 2008 01:19:51 -0400 (EDT) To: len@cs.pdx.edu cc: pgsql-performance@postgresql.org Subject: Re: Understanding histograms In-reply-to: <4817FC00.50609@cs.pdx.edu> References: <4817FC00.50609@cs.pdx.edu> Comments: In-reply-to Len Shapiro message dated "Tue, 29 Apr 2008 21:56:32 -0700" Date: Wed, 30 Apr 2008 01:19:51 -0400 Message-ID: <14251.1209532791@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200804/454 X-Sequence-Number: 29947 Len Shapiro writes: > 1. Why does Postgres come up with a negative n_distinct? It's a fractional representation. Per the docs: > stadistinct float4 The number of distinct nonnull data values in the column. A value greater than zero is the actual number of distinct values. A value less than zero is the negative of a fraction of the number of rows in the table (for example, a column in which values appear about twice on the average could be represented by stadistinct = -0.5). A zero value means the number of distinct values is unknown > The "rows=2" estimate makes sense when const = 1 or 5, but it makes no > sense to me for other values of const not in the MVC list. > For example, if I run the query > EXPLAIN SELECT * from sailors where rank = -1000; > Postgres still gives an estimate of "row=2". I'm not sure what estimate you'd expect instead? The code has a built in assumption that no value not present in the MCV list can be more frequent than the last member of the MCV list, so it's definitely not gonna guess *more* than 2. regards, tom lane