Index not used on single select, but used in join.

From: Francisco Reyes <lists(at)natserv(dot)com>
To: Pgsql Novice <pgsql-novice(at)postgresql(dot)org>
Subject: Index not used on single select, but used in join.
Date: 2001-11-07 20:10:46
Message-ID: 20011107145446.X27009-100000@zoraida.natserv.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I have a table, hraces, with a column called "horse" and an index
"lower(horse)".

If I try:
explain select horse from hraces where lower(horse) = 'little irish nut';

The query doesn't use the index. It says it would do a sequential scan.

I have another table, tmp, which also has a horse column.

If I do:
explain select hr.horse from hraces hr, tmp where lower(hr.horse) =
lower(tmp.horse);

The explain says it would do a sequential in tmp and use the index on
hraces. This makes perfect sense since hraces has close to 8 million records
and tmp has less than 300 records.

What I can't understand is why doing the select against hraces alone
doesn't use the index. If I do the select without the 'explain' it does
find the 84 records on hraces for 'little irish nut'.

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Tom Lane 2001-11-07 20:31:27 Re: IS NULL
Previous Message Francisco Reyes 2001-11-07 19:54:01 Re: Getting info on index