MySQL | REGEXP VS赞 [英] MySQL | REGEXP VS Like

查看:74
本文介绍了MySQL | REGEXP VS赞的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据库中有一个表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%';

推荐答案

REGEXPLIKE用于完全不同的情况.

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.

在您的情况下,firstnameREGEXP更可能使用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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆