MySQL | REGEXP VS赞 [英] MySQL | REGEXP VS Like
问题描述
我的数据库中有一个表CANDIDATE,该表在MySQL 5.5下运行,我试图从表中获取行,其中RAM包含名字,因此我可以在两个查询下运行,但现在我想查询哪个查询应该在优化方面长期使用.
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, but I would like to now which query we should use for long term with respect to optimization.
SELECT * FROM CANDIDATE c WHERE firstname REGEXP 'ram';
SELECT * FROM CANDIDATE c WHERE firstname LIKE'%ram%';
推荐答案
REGEXP
和LIKE
用于完全不同的情况.
REGEXP
and LIKE
are used to totally different cases.
LIKE
用于将通配符添加到字符串,而REGEXP
用于将属性与正则表达式匹配.
LIKE
is used to add wildcards to a string whereas REGEXP
is used to match an attribute with Regular Expressions.
在您的情况下,firstname
比REGEXP
更可能使用LIKE
进行匹配,因此,它将得到更好的优化.
In your case a firstname
is more likely to be matched using LIKE
than REGEXP
and hence, it will be more optimized.
这篇关于MySQL | REGEXP VS赞的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!