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 5AFAAD1B958 for ; Tue, 19 Aug 2003 13:50:10 -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 01551-03 for ; Tue, 19 Aug 2003 13:50:00 -0300 (ADT) Received: from mail.psychofx.com (unknown [217.71.230.39]) by svr1.postgresql.org (Postfix) with ESMTP id E00FDD1B8B8 for ; Tue, 19 Aug 2003 13:49:58 -0300 (ADT) Received: by mail.psychofx.com (Postfix, from userid 10002) id 649AE240A3; Tue, 19 Aug 2003 17:49:23 +0100 (BST) Received: from psychofx.com (unknown [217.71.230.212]) by mail.psychofx.com (Postfix) with ESMTP id 8ABA22403B; Tue, 19 Aug 2003 17:49:16 +0100 (BST) Message-ID: <3F425458.2020802@psychofx.com> Date: Tue, 19 Aug 2003 17:46:16 +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: pgsql-admin@postgresql.org Cc: Chris Miles Subject: This table won't use INDEX until I DUMP/RESTORE it ? 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/241 X-Sequence-Number: 9962 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; DB=# EXPLAIN select pcref,pcseqnbr from catrecrel where pcbsref='something' and (pccaref is null or pccaref='') and pcpar is null order by pcseqnbr ; NOTICE: QUERY PLAN: Sort (cost=38266.65..38266.65 rows=4 width=58) -> Seq Scan on catrecrel (cost=0.00..38266.61 rows=4 width=58) Ok, that's no good, but it _should_ be using an index instead, and if I dump this table, restore it onto a different (non-live) DB, and try again, I see that it does indeed plan to use the index: DB=# EXPLAIN select pcref,pcseqnbr from catrecrel where pcbsref='something' and (pccaref is null or pccaref='') and pcpar is null order by pcseqnbr ; NOTICE: QUERY PLAN: Sort (cost=469.92..469.92 rows=1 width=58) -> Index Scan using ind_pcbsref on catrecrel (cost=0.00..469.91 rows=1 width=58) Now, why is this? The first (live) DB is VACUUM ANALYSEd nightly, and was done so again just before this test. Data, schema and indexes should be the same in both (well it was dumped/restored directly from one to the other). The only fix I can think of is to dump and restore the whole DB, based on the fact that a newly restored DB appears to work much better, but surely I shouldn't have to do this? What else can i do to fix it? Cheers, CM -- Chris Miles http://chrismiles.info/