以下两个陈述之间是否存在差异:
mysql> EXPLAIN SELECT IF(arms IS NULL, 'asdf', arms) FROM limbs;
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| 1 | SIMPLE | limbs | ALL | NULL | NULL | NULL | NULL | 12 | |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
1 row in set (0.00 sec)
mysql> EXPLAIN SELECT IF(arms IS NULL, 'asdf', arms) FROM limbs;
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
| 1 | SIMPLE | limbs | ALL | NULL | NULL | NULL | NULL | 12 | |
+----+-------------+-------+------+---------------+------+---------+------+------+-------+
1 row in set (0.00 sec)
一个人表现得更好还是优于另一个?或者它们是否相同?
答案 0 :(得分:1)
IFNULL
只是IF
的{{3}},这是ANSI SQL CASE
的语法糖。
因此,您可以根据自己的特殊需求使用自己喜欢的任何一种。
PS:EXPLAIN
不依赖SELECT