X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 5CA8C5E46DC for ; Sat, 28 Aug 2004 05:51:01 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 26236-06 for ; Sat, 28 Aug 2004 08:50:52 +0000 (GMT) Received: from vscan02.westnet.com.au (vscan02.westnet.com.au [203.10.1.132]) by svr1.postgresql.org (Postfix) with ESMTP id 712635E46D1 for ; Sat, 28 Aug 2004 05:50:51 -0300 (ADT) Received: from localhost (localhost.localdomain [127.0.0.1]) by localhost (Postfix) with ESMTP id 84D5811AA5A; Sat, 28 Aug 2004 16:50:41 +0800 (WST) Received: from [192.168.1.3] (dsl-202-72-133-22.wa.westnet.com.au [202.72.133.22]) by vscan02.westnet.com.au (Postfix) with ESMTP id DB5FD11AA52; Sat, 28 Aug 2004 16:50:32 +0800 (WST) Message-ID: <41304752.3050208@familyhealth.com.au> Date: Sat, 28 Aug 2004 16:50:26 +0800 From: Christopher Kings-Lynne User-Agent: Mozilla Thunderbird 0.7.3 (Windows/20040803) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Artimenko Igor Cc: pgsql-performance@postgresql.org Subject: Re: Why those queries do not utilize indexes? References: <20040827192911.72205.qmail@web11905.mail.yahoo.com> In-Reply-To: <20040827192911.72205.qmail@web11905.mail.yahoo.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200408/410 X-Sequence-Number: 8046 First things first: try vacuum full analyze on all the tables involved. > 1. Should I afraid of high cost indexes? Or query will still be very efficient? Not necessarily. However, EXPLAIN output is pretty much useless for us for helping you. You need to post EXPLAIN ANALYZE output. Then, you need to use explain analyze to check the speed difference between the index and seq scan versions. Is the seq scan actually slower? > 2. Postgres does not use the index I need. For my data sets it’s always msgstatus index is > narrowest compare with ‘messagesStatus’ one. Is any way to “enforce” to use a particular index? > What’s the logic when Postgres chooses one index compare with the other. It's complicated, but it's based on teh statistics in pg_statistic that the vacuum analyze command gathers. > 3. I can change db structure to utilize Postgres specifics if you can tell them to me. I avoid using int8 and int2 in the first place :) In PostgreSQL 8.0, they will be less troublesome, but I've never seen a need for them! > 4. Also, originally I had “messagesStatus” index having 2 components ( “msgstatus”, “user_id” ). > But query SELECT * FROM messageinfo WHERE msgstatus = 0 did not utilize indexes in this case. It > only worked if both index components are in WHERE part. So I have to remove 2-nd component > “user_id” from messagesStatus index even I wanted it. Is any way that where clause has only 1-st > component but index is utilized? So long as your where clause matches a subset of the columns in the index in left to right order, the index can be used. For example, if your index is over (a, b, c) then select * where a=1 and b=2; can use the index. Chris