If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Index where like

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-17-04, 05:19
Matrix28 Matrix28 is offline
Registered User
 
Join Date: Sep 2003
Posts: 47
Index where like

Everytime I try to query using an index, it stops using the indexes if I use two percentage signs. Why is that and what can I do?
Reply With Quote
  #2 (permalink)  
Old 08-17-04, 09:10
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
do you mean

... WHERE foo LIKE '%bar%'

you can't do anything, it is in the nature of this construct that all values of foo must be examined, hence there's no point to using an index

the index will be used for this --

... WHERE foo LIKE 'bar%'
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 08-17-04, 10:05
Matrix28 Matrix28 is offline
Registered User
 
Join Date: Sep 2003
Posts: 47
Well I'm trying to write a search engine for my site, what options do I have? Can I opimize the query or anything?
Reply With Quote
  #4 (permalink)  
Old 08-17-04, 10:22
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
if you need to search all rows of the table to find those which match '%bar%' then that's already as optimized as you're gonna get
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On