"="和“< =>"之间是否存在性能差异?
我最近将所有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