MySQL Forums
Forum List  »  Performance

Optimize LIKE '%abc%' queries
Posted by: Apachez
Date: August 04, 2006 02:12PM

In mysql (and most likely any other sql server software) a query such as LIKE '%abc%' cannot use the index efficient such as a LIKE 'abc%' can do due to the leading % wildcard.

I am thinking of creating an additional column in my table which will have the word in reversed form and create a combined index of (col1, col2_reversed) and then execute the query such as: col1 LIKE 'abc% AND col2_reversed LIKE 'cba%'.

But I guess that wont bring me the same answers as: col1 LIKE '%abc%'. However this will optimize LIKE '%abc' queries by executing them as: col2_reversed LIKE 'cba%'.

Is there perhaps some other optimization I could use in order to boost LIKE '%abc%' queries ?

Options: ReplyQuote


Subject
Views
Written By
Posted
Optimize LIKE '%abc%' queries
13507
August 04, 2006 02:12PM
6224
August 04, 2006 02:30PM
5725
August 04, 2006 02:36PM
5433
August 04, 2006 02:56PM
6173
August 04, 2006 03:35PM
4856
August 10, 2006 12:41PM
4426
August 10, 2006 01:54PM
4981
August 10, 2006 04:12PM
3777
August 10, 2006 04:27PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.