Rafael, Without more details it is hard how you can optimize a query. 1. even though database 1TB, what about the table on which your running this query? Do you have any index on the column? How may chars long is the column? etc. 2. Run the explain and see what is the optimizer is telling - using key or not, full scan or not, etc. 3. see whether you can change the like to 'ABCpatron%'. See - " http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html - The index also can be used for LIKE<http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like>comparisons if the argument to LIKE<http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html#operator_like>is a constant string that does not start with a wildcard character." 4. you may want to take subset of data and try both RegEx and like. Compare them. 5. Also, see if you can make use of prefix-indexing where you only first N characters are used.
Best, Shiva On Sun, Dec 4, 2011 at 11:25 AM, Rafael Valenzuela <rav...@gmail.com> wrote: > Hi all, > 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? > thanks a lot > -- > Mit forever > My Blog <http://www.redcloverbi.wordpress.com> > My Faborite Web< > http://ocw.mit.edu/OcwWeb/Electrical-Engineering-and-Computer-Science/index.htm > > > http://www.technologyreview.com/ >