[go: up one dir, main page]

Re: Index non-usage problem in 8.2.9

From: Joseph S <jks(at)selectacast(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Index non-usage problem in 8.2.9
Date: 2008-09-03 02:40:22
Message-ID: 48BDF916.4090308@selectacast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Creating an index without the IS NOT NULL did not help. The complete
version:

PostgreSQL 8.2.9 on x86_64-unknown-linux-gnu, compiled by GCC gcc
(GCC) 4.1.1 20070105 (Red Hat 4.1.1-52)

Starting with a fresh database I got the same results you did, but not
with my production table.

Tom Lane wrote:
> Joseph S <jks(at)selectacast(dot)net> writes:
>> It seems that postgres can't figure out that it can use the index on
>> sacode unless I put "d2.sacode > 0" in my where clause.
>
> Works for me ...
>
> regression=# create table d2(sgcode int, sacode int);
> CREATE TABLE
> regression=# create index d2i on d2 (sgcode, sacode) WHERE sacode IS NOT NULL AND sacode > 0;
> CREATE INDEX
> regression=# explain select count(*) from d2 where d2.sgcode = 156 AND d2.sacode IN(2,1);
> QUERY PLAN
> ------------------------------------------------------------------------------------
> Aggregate (cost=8.54..8.55 rows=1 width=0)
> -> Bitmap Heap Scan on d2 (cost=4.52..8.54 rows=1 width=0)
> Recheck Cond: ((sgcode = 156) AND (sacode = ANY ('{2,1}'::integer[])))
> -> Bitmap Index Scan on d2i (cost=0.00..4.52 rows=1 width=0)
> Index Cond: ((sgcode = 156) AND (sacode = ANY ('{2,1}'::integer[])))
> (5 rows)
>
> You sure the server is 8.2.9? Awhile ago there were some bug fixes
> around the handling of IS NULL/IS NOT NULL in predicates.
>
> One thought is that the IS NOT NULL is really redundant, since it's
> implied by the sacode > 0 test anyway. Does it work better if you
> make the index just "WHERE sacode > 0" ?
>
> regards, tom lane

In response to Responses Browse pgsql-general by date
  From Date Subject
Next Message Robert Treat 2008-09-03 02:56:51 Re: Oracle and Postgresql
Previous Message aderose 2008-09-03 00:38:33 Re: vacuum analyze hurts performance