Re: create index on function - why?

Поиск
Список
Период
Сортировка
От Christopher Kings-Lynne
Тема Re: create index on function - why?
Дата
Msg-id GNELIHDDFBOCMGBFGEFOCEIFCBAA.chriskl@familyhealth.com.au
обсуждение исходный текст
Ответ на Re: create index on function - why?  (Bruce Momjian <root@candle.pha.pa.us>)
Список 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



В списке pgsql-sql по дате отправления:

Предыдущее
От: "Christopher Kings-Lynne"
Дата:
Сообщение: Re: all tables in a DB\?
Следующее
От: Bruce Momjian
Дата:
Сообщение: Re: [HACKERS] Array slice subscripts (was Re: plpgsql function