List:General Discussion« Previous MessageNext Message »
From:(Hal Date:December 5 2011 5:05am
Subject:Re: the best way compare String
View as plain text  
;>>> 2011/12/04 20:25 +0100, Rafael Valenzuela >>>>
In one query,  I am comparing a string with a 'like=%patron%', but is very
slow and expensive .What is the best way to compare a string? like or
regular expression?
The data base is too big table 1TB, any idea? 
<<<<<<<<
Any decent implementation of "like '%patron%'" is in the gross linear, and also, say,
LOCATE('patron', ) in a setting where only 0 or not 0 is tested for. If all your
LIKE-searches look like this one, a string to be matched from a value by putting it
between '%'s, maybe by using "LOCATE" you can save time--unless the MySQL developers were
clever enough to make a special case of this, and used the same algorithm for both. (One
can always use the Boyer-Moore algorithm for "LOCATE".)

In any case, if an in-the-gross-linear algorithm is used and that is too slow, indexing is
the only help, and, as Shiva said, you have to know your problem.

Thread
the best way compare StringRafael Valenzuela4 Dec
  • Re: the best way compare StringReindl Harald4 Dec
    • Re: the best way compare StringRafael Valenzuela4 Dec
      • Re: the best way compare StringReindl Harald4 Dec
        • Re: the best way compare StringBasil Daoust5 Dec
  • Re: the best way compare StringShiva4 Dec
    • Re: the best way compare StringAndrĂ©s Tello5 Dec
      • Re: the best way compare StringRafael Valenzuela5 Dec
  • Re: the best way compare Stringhsv5 Dec