Re: create index on function - why?

From: "Christopher Kings-Lynne" <chriskl(at)familyhealth(dot)com(dot)au>
To: "Bruce Momjian" <root(at)candle(dot)pha(dot)pa(dot)us>, <wweng(at)kencast(dot)com>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: create index on function - why?
Date: 2002-02-22 03:13:42
Message-ID: GNELIHDDFBOCMGBFGEFOCEIFCBAA.chriskl@familyhealth.com.au
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

> Wei Weng wrote:
> > I can understand the rationale behind creating index on tables, it
> > speeds up the searching.
> >
> > But what is the rationale behind creating index on a function? how does
> > it help with the database performance?

Say you always use a query like this:

select * from mytable where upper(name) = 'ASDF';

Now, postgres CANNOT use its indices as it has to retrieve every single row,
convert the 'name' field to upper case, and then compare it to 'ASDF'.

Now, say you add an index like this:

create index myindex on mytable (upper(name));

Now, postgres can just use the 'myindex' index instead of having to scan
every row.

Is that any clearer?

Chris

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Bruce Momjian 2002-02-22 03:55:55 Re: Array slice subscripts (was Re: [SQL] plpgsql function
Previous Message Christopher Kings-Lynne 2002-02-22 03:10:53 Re: all tables in a DB\?