View Single Post

   
  #7 (permalink)  
Old 04-12-2008, 03:37 AM
Rodrigo Hjort
 
Posts: n/a
Default Re: LIKE, leading percent, bind parameters and indexes

>
> I think more exactly, the planner can't possibly know how to plan an
> indexscan with a leading '%', because it has nowhere to start.
>


The fact is that index scan is performed on LIKE expression on a string not
preceded by '%', except when bound parameter is used.

select * from table where field like 'THE NAME%'; -- index scan
select * from table where field like '%THE NAME%'; -- seq scan
select * from table where field like :bind_param; -- seq scan (always)

Regards,

Rodrigo Hjort
http://icewall.org/~hjort

Reply With Quote