From: | Frank Bax <fbax(at)sympatico(dot)ca> |
---|---|
To: | Wei Weng <wweng(at)kencast(dot)com> |
Cc: | <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: Resources |
Date: | 2002-01-11 21:13:13 |
Message-ID: | 3.0.6.32.20020111161313.007a2310@pop6.sympatico.ca |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
At 03:42 PM 1/11/02 -0500, Wei Weng wrote:
>Can you index on a function?
>How exactly does that help performance of a query?
If a table "employee" contains a field "last" and you are not sure how the
last name might make use of capital letters, then to get all names starting
with 'MC', you might code a query like:
select * from employee where last ILIKE 'MC%';
which does not use an index on "last" because we used ILIKE instead of LIKE.
In this case, we would create an index using "lower" function, like:
create index employee_last on employee ( lower(last) );
then write the query as:
select * from employee where lower(last) LIKE 'mc%';
which does make use of the index (and a faster executing query).
Frank
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2002-01-11 22:01:04 | Re: who has lock on table/row |
Previous Message | Frank Bax | 2002-01-11 19:18:09 | Re: Resources |