Re: Functional Indices

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: kavoos <kavoos(at)issn(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Functional Indices
Date: 2001-05-22 19:29:28
Message-ID: Pine.BSF.4.21.0105221228090.63455-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 21 May 2001, kavoos wrote:

> Hi all,
>
>
> The pg manual, chapter 7 :
> "For example, a common way to do case-insensitive comparisons is to use
> the lower: SELECT * FROM test1 WHERE lower(col1) = 'value';
> In order for that query to be able to use an index, it has to be defined
> on the result of the lower(column) operation:
> CREATE INDEX test1_lower_col1_idx ON test1 (lower(col1));"
>
> I have a table like this :
> \d titles
> Table "titles"
> Attribute | Type | Modifier
> -----------+------------------------+----------------------------------------------
> id | integer | not null default
> nextval('titles_seq'::text)
> issn | character(9) | not null
> tag | integer | not null
> prefix | character varying(32) |
> title | character varying(640) | not null
> Indices: issn,
> prefix,
> tag,
>
>
> create index lower_title on titles (lower(title));
> vacuum analyze;
> ...
> explain select * from titles where lower(title) = 'monde';
> Seq Scan on titles (cost=0.00..39392.10 rows=14145 width=44)

How many rows are in titles? It seems to estimate 14000+
rows are going to match. If that's true, sequence scan may
be a better plan than the index. Or, perhaps, do you have
a very common title value that's throwing off the statistics?

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2001-05-22 19:43:02 Re: Functional Indices
Previous Message Peter Eisentraut 2001-05-22 19:22:59 Re: Cant get Perl Module loaded