Re: indexed column not working as fast as expected

From: "gnari" <gnari(at)simnet(dot)is>
To: "Amir Zicherman" <amir(dot)zicherman(at)gmail(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: indexed column not working as fast as expected
Date: 2004-08-18 08:40:02
Message-ID: 004601c484fe$f467a7d0$0100000a@wp2000
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Amir Zicherman" <amir(dot)zicherman(at)gmail(dot)com> wrote:
>
> i have a btree index on col1 in table1. The column has either values
> 1,2,3, or 4. 4 does not appear that much in the table (only 5 times).
> there are about 20 million rows in the table. when i do a "select *
> from table1 where col1=4" it takes very long time to get back to me
> (around 4 minutes). why is it taking so long if i have an index on
> it? I also tried this with a hash index and it was still slow.

you need to "analyze table1"

possibly a "select * from table1 where col1=4 order by col1 DESC" could
be faster, as this is the highest value, but i am not sure.

if it is known that the value 4 will always appear MUCH less frequently
then the others, you might try
create index table1_partial on table1(col1) where col1=4;
then the select will definitively be faster for this value.

gnari

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Gregory S. Williamson 2004-08-18 08:46:57 Re: indexed column not working as fast as expected
Previous Message Julian Scarfe 2004-08-18 08:14:01 8.0 release schedule?