"="和“< =>"之间是否存在性能差异? [英] Is there a performance difference between `=` and `<=>`?

查看:96
本文介绍了"="和“< =>"之间是否存在性能差异?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近将所有where条件更改为使用<=>而不是=,因为我需要检查是否为空.有性能方面的问题吗?

I've recently changed all my where conditions to use <=> instead of = because I need to check against nulls. Are there any performance concerns?

推荐答案

这对性能没有实际影响,这是一个可以自己验证的测试

There is no real performance impact here is a test to verify for yourself

mysql> SELECT BENCHMARK(1000000, (SELECT SQL_NO_CACHE userId FROM Activity WHERE userId<=>42459204 LIMIT 1));

确保您需要使用< =>

Make sure that you need to use <=>

NULL安全等于.这个运算符 执行像这样的相等比较 =运算子,但传回1 如果两个操作数均为NULL,则返回NULL, 如果一个操作数,则返回0而不是NULL 是NULL.

NULL-safe equal. This operator performs an equality comparison like the = operator, but returns 1 rather than NULL if both operands are NULL, and 0 rather than NULL if one operand is NULL.

如果只需要检查右值,就可以

If you just need to check the rvalue do

col = CONST并且CONST不为空

col=CONST AND CONST IS NOT NULL

或t1.col = t2.col

or t1.col=t2.col

这篇关于"="和“&lt; =&gt;"之间是否存在性能差异?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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