进行精确的字符串匹配

进行精确的字符串匹配

本文介绍了使用LIKE vs. =进行精确的字符串匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我认识到两者之间的区别:
-Like使通配符%和_
可用-显着的尾随空格
-整理问题

First off, I recognize the differences between the two:
- Like makes available the wildcards % and _
- significant trailing whitespace
- colation issues

其他所有条件都相同,对于完全匹配的字符串而言,效率更高:

All other things being equal, for an exact string match which is more efficient:

SELECT field WHERE 'a' = 'a';

或者:

SELECT field WHERE 'a' LIKE 'a';

或者:差异是如此微小以至于没关系吗?

Or: Is the difference so insignificant that it doesn't matter?

推荐答案

我会说=比较器会更快.词法不会将比较发送到另一个词法系统以进行一般匹配.相反,引擎能够匹配或继续行驶.我们工作的数据库有数百万行,并且=总是更快.

I would say that the = comparator would be faster. The lexical doesn't send the comparison to another lexical system to do general matches. Instead the engine is able to just match or move on. Our db at work has millions of rows and an = is always faster.

这篇关于使用LIKE vs. =进行精确的字符串匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 05:11