Received: from maia.hub.org (maia-5.hub.org [200.46.204.29]) by mail.postgresql.org (Postfix) with ESMTP id CB1FD643C25 for ; Thu, 10 Jun 2010 18:00:08 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.29]) (amavisd-maia, port 10024) with ESMTP id 22367-10 for ; Thu, 10 Jun 2010 21:00:00 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og126.obsmtp.com (exprod7og126.obsmtp.com [64.18.2.206]) by mail.postgresql.org (Postfix) with SMTP id 81387643BF2 for ; Thu, 10 Jun 2010 17:59:58 -0300 (ADT) Received: from source ([74.125.82.175]) by exprod7ob126.postini.com ([64.18.6.12]) with SMTP ID DSNKTBFSTDUX0hWOaNdJwITBlyIikQZ8cArF@postini.com; Thu, 10 Jun 2010 13:59:59 PDT Received: by mail-wy0-f175.google.com with SMTP id 11so302290wyi.20 for ; Thu, 10 Jun 2010 13:59:56 -0700 (PDT) Received: by 10.227.156.5 with SMTP id u5mr849196wbw.27.1276203596461; Thu, 10 Jun 2010 13:59:56 -0700 (PDT) Received: from [192.168.1.117] (dsl-hkibrasgw2-ff7ac300-240.dhcp.inet.fi [88.195.122.240]) by mx.google.com with ESMTPS id u19sm2879332wbc.8.2010.06.10.13.59.55 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 10 Jun 2010 13:59:55 -0700 (PDT) Message-ID: <4C11524A.9090702@enterprisedb.com> Date: Thu, 10 Jun 2010 23:59:54 +0300 From: Heikki Linnakangas Organization: EnterpriseDB User-Agent: Mozilla/5.0 (X11; U; Linux i686; fi-FI; rv:1.9.1.9) Gecko/20100515 Iceowl/1.0b1 Icedove/3.0.4 MIME-Version: 1.0 To: Anne Rosset CC: Craig James , pgsql-performance@postgresql.org Subject: Re: Need to increase performance of a query References: <4C1125F0.8090101@collab.net> <4C112B19.6080908@krogh.cc> <4C113098.5040105@collab.net> <98414706.20100610212211@erwied.eu> <4C113E2F.6000305@collab.net> <4C11413B.8080107@emolecules.com> <4C11439C.3010603@enterprisedb.com> <4C11463B.7080608@collab.net> In-Reply-To: <4C11463B.7080608@collab.net> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-4.2 tagged_above=-10 required=5 tests=BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3 X-Spam-Level: X-Archive-Number: 201006/190 X-Sequence-Number: 39046 On 10/06/10 23:08, Anne Rosset wrote: > Heikki Linnakangas wrote: >> On 10/06/10 22:47, Craig James wrote: >>> Postgres normally doesn't index NULL values even if the column is >>> indexed, so it has to do a table scan when your query includes an IS >>> NULL condition. >> >> That was addressed in version 8.3. 8.3 and upwards can use an index >> for IS NULL. >> >> I believe the NULLs were stored in the index in earlier releases too, >> they just couldn't be searched for. >> > I am using postgres 8.3.6. So why doesn't it use my index? Well, apparently the planner doesn't think it would be any cheaper. I wonder if this helps: CREATE INDEX item_rank_project_id ON item_rank(project_id, rank, pf_id); And make sure you drop any of the indexes that are not being used, to make sure the planner doesn't choose them instead. (You should upgrade to 8.3.11, BTW. There's been a bunch of bug-fixes in-between, though I don't know if any are related to this, but there's other important fixes there) -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com