Обсуждение: Re: postgres index on ILIKE

Поиск
Список
Период
Сортировка

Re: postgres index on ILIKE

От
Josh Berkus
Дата:
Alex,

> mydb=# explain select filename from neighbors where filename ilike
> '%test%'; QUERY PLAN
> -------------------------------------------------------------
>   Seq Scan on neighbors  (cost=0.00..17449.64 rows=774 width=37)
>     Filter: ((filename)::text ~~* '%test%'::text)

I just looked at your query.   What you have above is an "unanchored text 
search", where you are looking for a snippet of text anywhere in the field.   
Such a search *cannot* be indexed using a regular index.

Instead, you need to employ the TSearch full text searching module for 
PostgreSQL.    
hmmm ... the Tsearch home page appears to be down.  Check out the readme in 
your postgreSQL source code:  PG_SOURCE/contrib/tsearch/readme
-- 
Josh Berkus
Aglio Database Solutions
San Francisco