Re: create index on function - why?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: wweng(at)kencast(dot)com
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: create index on function - why?
Date: 2002-02-15 16:46:46
Message-ID: 14409.1013791606@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Wei Weng <wweng(at)kencast(dot)com> writes:
> But what is the rationale behind creating index on a function?

To speed up searching.

For example, given

create table foo (f1 text);

create index fooi on foo (upper(f1));

the index can be used for queries like

select * from foo where upper(f1) = 'HELLO';

Without the index, there'd be no way to avoid a sequential scan --- not
to mention evaluation of the function at every row. With the index,
the above query actually performs zero evaluations of upper() --- the
work got pushed into row insertion, instead.

A functional index is sort of like a hidden, precomputed column added to
your table.

regards, tom lane

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Bruno Wolff III 2002-02-15 17:01:28 Re: create index on function - why?
Previous Message Nick Fankhauser 2002-02-15 16:33:41 Re: create index on function - why?