0

以下两种说法是否有区别:

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)

一个性能更好还是比另一个更好?还是它们相同?

4

1 回答 1

1

IFNULL只是ANSI SQL 的语法糖IF它是 ANSI SQL 的语法糖CASE

因此,请使用您更喜欢的,以及适合您特定需求的。

PS:EXPLAIN不依赖SELECT

于 2012-06-21T22:28:07.870 回答