X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 507CE11F6677 for ; Thu, 6 Apr 2006 05:50:44 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 89902-07 for ; Thu, 6 Apr 2006 05:50:40 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from mx1.ipf.is (benz.ipf.is [85.197.192.156]) by postgresql.org (Postfix) with ESMTP id DB56511F663E for ; Thu, 6 Apr 2006 05:50:41 -0300 (ADT) Received: (qmail 29492 invoked by uid 1010); 6 Apr 2006 08:49:43 +0000 Received: from 85.197.216.186 by benz (envelope-from , uid 1008) with qmail-scanner-1.25-st-qms (clamdscan: 0.88/1235. spamassassin: 3.1.1. perlscan: 1.25-st-qms. Clear:RC:1(85.197.216.186):SA:0(-4.2/4.5):. Processed in 0.327529 secs); 06 Apr 2006 08:49:43 -0000 X-Antivirus-IPF-Mail-From: gnari@hive.is via benz X-Antivirus-IPF: 1.25-st-qms (Clear:RC:1(85.197.216.186):SA:0(-4.2/4.5):. Processed in 0.327529 secs Process 29485) Received: from dsl-216-186.hive.is (HELO ?192.168.1.34?) (85.197.216.186) by mx1.ipf.is with SMTP; 6 Apr 2006 08:49:43 +0000 Subject: Re: Query planner is using wrong index. From: Ragnar To: Brian Herlihy Cc: pgsql-performance@postgresql.org In-Reply-To: <20060406023544.37250.qmail@web52305.mail.yahoo.com> References: <20060406023544.37250.qmail@web52305.mail.yahoo.com> Content-Type: text/plain Date: Thu, 06 Apr 2006 08:52:54 +0000 Message-Id: <1144313574.32289.78.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.4.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0 required=5 tests=[none] X-Spam-Score: 0 X-Spam-Level: X-Archive-Number: 200604/102 X-Sequence-Number: 18186 On fim, 2006-04-06 at 12:35 +1000, Brian Herlihy wrote: > I have a problem with the choice of index made by the query planner. > > My table looks like this: > > CREATE TABLE t > ( > p1 varchar not null, > p2 varchar not null, > p3 varchar not null, > i1 integer, > i2 integer, > i3 integer, > i4 integer, > i5 integer, > d1 date, > d2 date, > d3 date, > PRIMARY KEY (p1, p2, p3) > ); > > I have also created an index on (p2, p3), as some of my lookups are on these > only. > All the integers and dates are data values. > The table has around 9 million rows. > I am using postgresl 7.4.7 > > I have set statistics to 1000 on the p1, p2 and p3 columns, and run vacuum full > analyse. However, I still see > query plans like this: > ... > db=# explain select * from t where p2 = 'fairly_common' and p3 = > 'fairly_common'; > QUERY PLAN > ----------------------------------------------------------------------------------------------------------------------------------- > Index Scan using p2p3 on t (cost=0.00..6.01 rows=1 width=102) > Index Cond: (((p2)::text = 'fairly_common'::text) AND ((p3)::text = > 'fairly_common'::text)) > (3 rows) please show us an actual EXPLAIN ANALYZE this will show us more. > I would like the query planner to use the primary key for all of these lookups. > How can I enforce this? How would that help? have you tested to see if it would actualy be better? gnari