why index scan not working when using 'like'?

Поиск
Список
Период
Сортировка
От LIANHE SHAO
Тема why index scan not working when using 'like'?
Дата
Msg-id 3d83693d9fe0.3d9fe03d8369@jhmimail.jhmi.edu
обсуждение исходный текст
Ответы Re: why index scan not working when using 'like'?  (Dror Matalon <dror@zapatec.com>)
Re: why index scan not working when using 'like'?  (Josh Berkus <josh@agliodbs.com>)
Список pgsql-performance
Hi all,

I want to use index on the gene_symbol column in my
query and gene_symbol is indexed. but when I use
lower (gene_symbol) like lower('%mif%'), the index
is not used. While when I change to
lower(gene_symbol) = lower('mif'), the index is used
and index scan works, but this is not what I like. I
want all the gene_symbols  containing substring
'mif' are pulled out, and not necessarily exactly match.

could anybody give me some hints how to deal with
this. If I do not used index, it take too long for
the query.


PGA> explain select distinct probeset_id, chip,
gene_symbol, title, sequence_description, pfam from
affy_array_annotation where lower(gene_symbol) like
upper('%mif%');
                                       QUERY PLAN
-----------------------------------------------------------------------------------------
 Unique  (cost=29576.44..29591.44 rows=86 width=265)
   ->  Sort  (cost=29576.44..29578.59 rows=857
width=265)
         Sort Key: probeset_id, chip, gene_symbol,
title, sequence_description, pfam
         ->  Seq Scan on affy_array_annotation
(cost=0.00..29534.70 rows=857 width=265)
               Filter: (lower((gene_symbol)::text)
~~ 'MIF%'::text)
(5 rows)


PGA=> explain select distinct probeset_id, chip,
gene_symbol, title, sequence_description, pfam from
affy_array_annotation where lower(gene_symbol) =
upper('%mif%');

 QUERY PLAN
---------------------------------------------------------------------------------------------------------------------
 Unique  (cost=3433.44..3448.44 rows=86 width=265)
   ->  Sort  (cost=3433.44..3435.58 rows=857 width=265)
         Sort Key: probeset_id, chip, gene_symbol,
title, sequence_description, pfam
         ->  Index Scan using gene_symbol_idx_fun1
on affy_array_annotation  (cost=0.00..3391.70
rows=857 width=265)
               Index Cond:
(lower((gene_symbol)::text) = '%MIF%'::text)
(5 rows)





Regards,
William


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

Предыдущее
От: Torsten Schulz
Дата:
Сообщение: [Fwd: Re: Optimize]
Следующее
От: Dror Matalon
Дата:
Сообщение: Re: why index scan not working when using 'like'?