Re: Index not used on single select, but used in join. - Mailing list pgsql-novice

From Tom Lane
Subject Re: Index not used on single select, but used in join.
Date
Msg-id 6461.1005165697@sss.pgh.pa.us
Whole thread Raw
In response to Index not used on single select, but used in join.  (Francisco Reyes <lists@natserv.com>)
Responses Re: Index not used on single select, but used in join.
Re: Index not used on single select, but used in join.
List pgsql-novice
Francisco Reyes <lists@natserv.com> writes:
> 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.

Seems to work for me:

regression=# create table hraces (horse text);
CREATE
regression=# create index hri on hraces(lower(horse));
CREATE
regression=# explain select horse from hraces where lower(horse) = 'little irish nut';
NOTICE:  QUERY PLAN:

Index Scan using hri on hraces  (cost=0.00..17.08 rows=5 width=32)

EXPLAIN

What does EXPLAIN actually show for you?  If you try to force an
indexscan by doing "SET enable_seqscan TO off", does the EXPLAIN
result change?  Have you VACUUM ANALYZEd the table recently?

            regards, tom lane

pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: IS NULL
Next
From: Francisco Reyes
Date:
Subject: Re: Index not used on single select, but used in join.