Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id ED63B475EBE for ; Wed, 22 May 2002 11:47:55 -0400 (EDT) Received: from smtp.comcast.net (smtp.comcast.net [24.153.64.2]) by postgresql.org (Postfix) with ESMTP id 3B98847664A for ; Wed, 22 May 2002 11:40:59 -0400 (EDT) Received: from stllnx1.stlassoc.com (pcp01376419pcs.selrsv01.pa.comcast.net [68.80.68.209]) by mtaout03.icomcast.net (iPlanet Messaging Server 5.1 HotFix 0.8 (built May 13 2002)) with ESMTP id <0GWI005SZRK9PH@mtaout03.icomcast.net> for pgsql-admin@postgresql.org; Wed, 22 May 2002 11:40:57 -0400 (EDT) Received: from tlowery by stllnx1.stlassoc.com with local (MasqMail 0.1.8c) id 17AYET-75z-00 for pgsql-admin@postgresql.org; Wed, 22 May 2002 11:40:57 -0400 Date: Wed, 22 May 2002 11:40:56 -0400 From: "Thomas A. Lowery" Subject: Re: Performance Problem Index Ignored, but why In-reply-to: <"from tgl"@sss.pgh.pa.us> To: pgsql-admin Message-id: <20020522114056.A27057@stllnx1.stlassoc.com> MIME-version: 1.0 Content-type: text/plain; charset=us-ascii Content-transfer-encoding: 7BIT Content-disposition: inline User-Agent: Mutt/1.2.5.1i X-Operating-System: Linux/2.4.9-31 (i586) X-Uptime: 11:24am up 2 days, 18:06, 16 users, load average: 1.75, 1.76, 1.66 References: <20020522000205.A17321@stllnx1.stlassoc.com> <21113.1022041595@sss.pgh.pa.us> X-Archive-Number: 200205/179 X-Sequence-Number: 4354 > estimate that 139654 rows will match f_state = 'PA' in the right No, 375342 is the actual number. Using the index does appear slower (limited testing noted). explain select count(*) from state_tst where f_state = 'PA'/ NOTICE: QUERY PLAN: Aggregate (cost=277899.65..277899.65 rows=1 width=0) -> Seq Scan on state_tst (cost=0.00..277550.51 rows=139654 width=0) select count(*) from state_tst where f_state = 'PA'/ count '375342' Elapsed: 139 wallclock secs set enable_seqscan = off/ explain select count(*) from state_tst where f_state = 'PA'/ NOTICE: QUERY PLAN: Aggregate (cost=542303.53..542303.53 rows=1 width=0) -> Index Scan using st_f_state_idx on state_tst (cost=0.00..541954.39 rows=139654 width=0) select count(*) from state_tst where f_state = 'PA'/ count '375342' Elapsed: 222 wallclock secs Tom On Wed, May 22, 2002 at 12:26:35AM -0400, Tom Lane wrote: > "Thomas A. Lowery" writes: > > Can I force the use of an index? > > Try "set enable_seqscan = off". But on the basis of what you've shown, > it's not obvious that an indexscan will be faster. Is the planner's > estimate that 139654 rows will match f_state = 'PA' in the right > ballpark? > > regards, tom lane