Performance of RegEx vs LIKE in MySql queries

后端 未结 2 1676
太阳男子
太阳男子 2020-12-25 11:45

Rumour has it that this:

SELECT * FROM lineage_string where lineage like \'%179%\' and  lineage regexp \'(^|/)179(/|$)\'

Would be faster th

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-25 12:42

    Yeah, it probably would be a tiny bit faster because standard-SQL LIKE is a simpler comparison operation than a full-on regex parser.

    However, in real terms both are really slow, because neither can use indices. (LIKE can use an index if the match string doesn't start with a wildcard, but that's not the case here.)

    If you are concerned about speed, you should change your schema so that you can put the 179 directly in a column and index it, rather than having to check through a string manually on every row.

提交回复
热议问题