From: Tom Lane <tgl@sss.pgh.pa.us>
To: wweng@kencast.com
Cc: pgsql-sql@postgresql.org
Subject: Re: create index on function - why?
Date: Fri, 15 Feb 2002 11:46:46 -0500
Message-ID: <14409.1013791606@sss.pgh.pa.us> (raw)
In-Reply-To: <3C6D3684.9040101@kencast.com>
References: <3C6D3684.9040101@kencast.com>
Wei Weng <wweng@kencast.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, wweng@kencast.com
Subject: Re: create index on function - why?
In-Reply-To: <14409.1013791606@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox