[ubuntu-florida] MySQL and REGEX

Ryan Parrish ryan at stickystyle.net
Tue Sep 21 20:17:46 BST 2010


On Tue, Sep 21, 2010 at 1:27 PM, j.e.aneiros <jesus.aneiros at gmail.com> wrote:
> Thanks for the clever observation Ryan. Perhaps to "help" the optimizer a
> little maybe the REGEXP could be combined with a LIKE part in the same
> query?
>

Yes, adding a LIKE operator to the query with a regex will help with
the performance of the query greatly if it can be applied in your
situation.  The optimizer will evaluate the LIKE pattern first (which
mysql is actually pretty fast at) and then apply the regex to the
remaining result set.

Although the above is based on my observations doing an EXPLAIN on the
queries, I can't seem to find concreate docs that say this is
precisely how the optimizer handles LIKE + REGEX queries, I just know
it's not looking at all 1M rows when done this way on my db.

--Ryan



More information about the Ubuntu-us-fl mailing list