MySQL | REGEXP VS Like

前端 未结 4 1709
甜味超标
甜味超标 2020-12-10 10:34

I have a table CANDIDATE in my db which is running under MySQL 5.5 and I am trying to get rows from table where RAM is contains in firstname, so I can run below two queries,

4条回答
  •  误落风尘
    2020-12-10 11:07

    I've tried it out on MySQL 8.0.13 and compared LIKE vs REGEXP on a table with 1M+ rows on a column with an index:

    SELECT * FROM table WHERE column LIKE '%foobar%';
    

    Query took 10.0418 seconds.

    SELECT * FROM table WHERE REGEXP_LIKE(column, 'foobar');
    

    Query took 11.0742 seconds.

    LIKE performance is faster. If you can get away with using it instead of REGEXP, do it.

提交回复
热议问题