下面1和2的效率一样吗?1....
select value from riqi where (id=2 or id=3 or id=7 or id=8 or id=9) and articles is not null2....
select value from riqi where id=2 and articles is not null
select value from riqi where id=3 and articles is not null
select value from riqi where id=7 and articles is not null
select value from riqi where id=8 and articles is not null
select value from riqi where id=9 and articles is not null
select value from riqi where (id=2 or id=3 or id=7 or id=8 or id=9) and articles is not null2....
select value from riqi where id=2 and articles is not null
select value from riqi where id=3 and articles is not null
select value from riqi where id=7 and articles is not null
select value from riqi where id=8 and articles is not null
select value from riqi where id=9 and articles is not null
哪个更快一些
-> union select * from test where id=3;
+----+--------------+------------+-------+---------------+---------+---------+-------+------+----------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+--------------+------------+-------+---------------+---------+---------+-------+------+----------+-------+
| 1 | PRIMARY | test | const | PRIMARY | PRIMARY | 4 | const | 1 | 100.00 | |
| 2 | UNION | test | const | PRIMARY | PRIMARY | 4 | const | 1 | 100.00 | |
| NULL | UNION RESULT | <union1,2> | ALL | NULL | NULL | NULL | NULL | NULL | NULL | |
+----+--------------+------------+-------+---------------+---------+---------+-------+------+----------+-------+
3 rows in set, 1 warning (0.00 sec)mysql> explain extended select * from test where (id=2 or id=3 or id=7 or id=8 or id=9);
+----+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+----+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
| 1 | SIMPLE | test | ALL | PRIMARY | NULL | NULL | NULL | 5 | 100.00 | Using where |
+----+-------------+-------+------+---------------+------+---------+------+------+----------+-------------+
1 row in set, 1 warning (0.00 sec)