X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id BAC36D1E0FF for ; Thu, 19 Feb 2004 03:44:37 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 02882-07 for ; Wed, 18 Feb 2004 23:44:39 -0400 (AST) Received: from millenium.mst.co.jp (unknown [210.230.185.241]) by svr1.postgresql.org (Postfix) with ESMTP id DBD72D1E130 for ; Wed, 18 Feb 2004 23:44:33 -0400 (AST) Received: from mst1x5r347kymb (lc12114 [192.168.1.114]) by millenium.mst.co.jp (8.11.6p2/3.7W) with SMTP id i1J3iI632498; Thu, 19 Feb 2004 12:44:19 +0900 Message-ID: <005f01c3f69a$a9632770$7201a8c0@mst1x5r347kymb> From: "Iain" To: "David Witham" , References: Subject: Re: Indexes and statistics Date: Thu, 19 Feb 2004 12:44:22 +0900 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/268 X-Sequence-Number: 16958 > The computed cost of using the index was a factor of 10 higher which I presume is why the query planner wasn't > using the index, but it ran in half the time Have you tried playing with the random_page_cost parameter? The default is 4. Try: set random_page_cost = 1; in psql to alter it for the current session (you can change this in postgresql.conf too). This will make index usage more attractive by reducing the computed cost. This is the simple way of looking at it anyway. On my system I tested a 'typical' query exercising some joins on large tables which didn't use an index, but I thought maybe it would perform better if it did. I determined that a random_page_cost of 1.8 would cause indexes to be used, but in this case the *actual* performance didn't improve very much. I took this to mean that a random_page_cost of around 1.8/1.9 represents a rough balance point on my development server (one slow IDE disk, and a big database). As well as the other things mentioned by Tom, perhaps you should be looking for the "correct" setting of random_page_cost for your system. It may be appropriate to alter it globally using postgresql.conf, and for specific situations such as you mentioned. HTH Iain