Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Uq7NX-0007NQ-1D for pgsql-performance@arkaria.postgresql.org; Fri, 21 Jun 2013 19:52:15 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Uq7NW-000157-Hd for pgsql-performance@arkaria.postgresql.org; Fri, 21 Jun 2013 19:52:14 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Uq7NV-000151-MU for pgsql-performance@postgresql.org; Fri, 21 Jun 2013 19:52:13 +0000 Received: from smtp.01.com ([199.36.142.181]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Uq7NS-0000wa-PE for pgsql-performance@postgresql.org; Fri, 21 Jun 2013 19:52:12 +0000 Received: from localhost (localhost [127.0.0.1]) by smtp-out-2.01.com (Postfix) with ESMTP id 1192639012F for ; Fri, 21 Jun 2013 14:52:10 -0500 (CDT) X-Virus-Scanned: amavisd-new at smtp-out-2.01.com Received: from smtp.01.com ([127.0.0.1]) by localhost (smtp-out-2.01.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id hXaI-IZ4FNmo for ; Fri, 21 Jun 2013 14:52:09 -0500 (CDT) Received: from smtp.01.com (localhost [127.0.0.1]) by smtp-out-2.01.com (Postfix) with ESMTP id E3CCD390183 for ; Fri, 21 Jun 2013 14:52:09 -0500 (CDT) Received: from localhost (localhost [127.0.0.1]) by smtp-out-2.01.com (Postfix) with ESMTP id CE79E390182 for ; Fri, 21 Jun 2013 14:52:09 -0500 (CDT) X-Virus-Scanned: amavisd-new at smtp-out-2.01.com Received: from smtp.01.com ([127.0.0.1]) by localhost (smtp-out-2.01.com [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 97cRkvG6FruY for ; Fri, 21 Jun 2013 14:52:09 -0500 (CDT) Received: from [172.47.23.103] (70-36-143-10.dsl.dynamic.sonic.net [70.36.143.10]) by smtp-out-2.01.com (Postfix) with ESMTPSA id 6EBB639012F for ; Fri, 21 Jun 2013 14:52:08 -0500 (CDT) Message-ID: <51C4AEE5.8040704@agliodbs.com> Date: Fri, 21 Jun 2013 12:52:05 -0700 From: Josh Berkus Organization: PostgreSQL Experts Inc. User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130510 Thunderbird/17.0.6 MIME-Version: 1.0 To: "pgsql-performance@postgresql.org" Subject: Weird, bad 0.5% selectivity estimate for a column equal to itself X-Enigmail-Version: 1.5.1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 0.8 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Folks, I'm getting something really odd in 9.2.4, where the planner estimates that the selectivity of a column equal to itself is always exactly 0.5% (i.e. 0.005X). I can't figure out where this constant is coming from, or why it's being applied. Test case: create table esttest ( id int not null primary key, state1 int not null default 0, state2 int not null default 0, state3 int not null default 0 ); insert into esttest (id, state1, state2, state3) select i, (random()*3)::int, (random())::int, (random()*100)::int from generate_series (1, 20000) as gs(i); vacuum analyze esttest; explain analyze select * from esttest where state1 = state1; explain analyze select * from esttest where state2 = state2; explain analyze select * from esttest where state3 = state3; Results of test case: badestimate=# explain analyze badestimate-# select * from esttest badestimate-# where state1 = state1; QUERY PLAN ---------------------------------------------------------------------------------------------------------- Seq Scan on esttest (cost=0.00..359.00 rows=100 width=16) (actual time=0.009..4.145 rows=20000 loops=1) Filter: (state1 = state1) Total runtime: 5.572 ms (3 rows) badestimate=# badestimate=# explain analyze badestimate-# select * from esttest badestimate-# where state2 = state2; QUERY PLAN ---------------------------------------------------------------------------------------------------------- Seq Scan on esttest (cost=0.00..359.00 rows=100 width=16) (actual time=0.006..4.166 rows=20000 loops=1) Filter: (state2 = state2) Total runtime: 5.595 ms (3 rows) badestimate=# badestimate=# explain analyze badestimate-# select * from esttest badestimate-# where state3 = state3; QUERY PLAN ---------------------------------------------------------------------------------------------------------- Seq Scan on esttest (cost=0.00..359.00 rows=100 width=16) (actual time=0.005..4.298 rows=20000 loops=1) Filter: (state3 = state3) Total runtime: 5.716 ms (3 rows) -- Josh Berkus PostgreSQL Experts Inc. http://pgexperts.com -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance