当数据表中数据量大,而只需要其中某些字段的值做为验证时不需要所有数据,只需要查几行就可以,此时用limit
如:
1.select * from tags limit 4; 就是取4行数据,看看id或者其他需要的字段的的值是什么。
查询结果为:id=102或者..........,在下面就用id = 102
2.
explain select * from tags where id=102; 检查该表中id或者其他字段
是否为索引很有效。
+----+-------------+----------+------+---------------+------+---------+------+---------+-------+
| id | select_type | table | type |
possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------+------+---------------+------+---------+------+---------+-------+
| 102 | SIMPLE | tags | ALL |
NULL | NULL | NULL | NULL | 6226057 | |
+----+-------------+----------+------+---------------+------+---------+------+---------+-------+
可以看出在这里没有用到id 索引【为id建的索引一般为PRIMARY】
MySQL查询前几行
猜你喜欢
转载自hllnihao.iteye.com/blog/1455455
今日推荐
周排行