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 9D0DDD1B9C7 for ; Thu, 21 Aug 2003 09:48:08 -0300 (ADT) 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 96773-09 for ; Thu, 21 Aug 2003 09:48:01 -0300 (ADT) Received: from mail.psychofx.com (unknown [217.71.230.39]) by svr1.postgresql.org (Postfix) with ESMTP id 39666D1BB51 for ; Thu, 21 Aug 2003 09:47:57 -0300 (ADT) Received: by mail.psychofx.com (Postfix, from userid 10002) id 8DB2B23EDD; Thu, 21 Aug 2003 13:47:25 +0100 (BST) Received: from psychofx.com (unknown [217.71.230.212]) by mail.psychofx.com (Postfix) with ESMTP id F025423441; Thu, 21 Aug 2003 13:47:21 +0100 (BST) Message-ID: <3F44BEA3.2020408@psychofx.com> Date: Thu, 21 Aug 2003 13:44:19 +0100 From: Chris Miles Organization: chrismiles.info User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Stephan Szabo Cc: pgsql-admin@postgresql.org, Chris Miles Subject: Re: This table won't use INDEX until I DUMP/RESTORE it ? References: <20030820160024.X20088-100000@megazone.bigpanda.com> In-Reply-To: <20030820160024.X20088-100000@megazone.bigpanda.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/255 X-Sequence-Number: 9976 Stephan Szabo wrote: > On Tue, 19 Aug 2003, Chris Miles wrote: >>I have a DB that appears to perform badly. A test of one table >>with one of the typical queries gives me a query plan indicating >>a Seq Scan; > > What does it give if you set enable_seqscan=off; before the explain? ok, with enable_seqscan=off it gives an index scan for the explain. > And what does explain analyze give both with seqscan disabled and enabled? test=# set enable_seqscan=on; SET VARIABLE test=# EXPLAIN ANALYSE select pcref,pcseqnbr from catrecrel where pcbsref='test' and (pccaref is null or pccaref='') and pcpar is null order by pcseqnbr ; NOTICE: QUERY PLAN: Sort (cost=38288.75..38288.75 rows=4 width=58) (actual time=7271.47..7272.59 rows=743 loops=1) -> Seq Scan on catrecrel (cost=0.00..38288.70 rows=4 width=58) (actual time=0.10..7266.19 rows=743 loops=1) Total runtime: 7273.92 msec EXPLAIN test=# set enable_seqscan=off; SET VARIABLE test=# EXPLAIN ANALYSE select pcref,pcseqnbr from catrecrel where pcbsref='test' and (pccaref is null or pccaref='') and pcpar is null order by pcseqnbr ; NOTICE: QUERY PLAN: Index Scan using ind_pcseqnbr on catrecrel (cost=0.00..38390.48 rows=4 width=58) (actual time=0.28..229.19 rows=743 loops=1) Total runtime: 230.53 msec EXPLAIN > Also, what version are you running? Sorry forgot to mention it is: 7.2.3 So why do I have to force seqscan off to get better behaviour? This wouldn't be practical to do within our code. Is a newer version, such as 7.3.4, much smarter with query planning? Regards, Chris. -- Chris Miles http://chrismiles.info/