2019-02-25
閱讀量:
796
sql語(yǔ)句執(zhí)行性能分析
問題描述:
有什么可視化的,能夠特別直觀的分析SQL語(yǔ)句性能的工具?
select * limit offset,amount;
select * where id between offset and offset+amount;
select * where id > offset limit amount;
以上三個(gè)SQL語(yǔ)句,哪個(gè)性能更佳呢?
解決方法:
可以用explain查看
mysql> explain select * from users limit 1000,20;
+----+-------------+-------+------+---------------+------+---------+------+--------+-------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+------+---------------+------+---------+------+--------+-------+
| 1 | SIMPLE | users | ALL | NULL | NULL | NULL | NULL | 169847 | |
+----+-------------+-------+------+---------------+------+---------+------+--------+-------+
1 row in set (0.00 sec)
mysql> explain select * from users where uid>1000 limit 20;
+----+-------------+-------+-------+---------------+---------+---------+------+-------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+---------+---------+------+-------+-------------+
| 1 | SIMPLE | users | range | PRIMARY | PRIMARY | 4 | NULL | 84923 | Using where |
+----+-------------+-------+-------+---------------+---------+---------+------+-------+-------------+
1 row in set (0.00 sec)
mysql> explain select * from users where uid between 1000 and 1020;
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
| 1 | SIMPLE | users | range | PRIMARY | PRIMARY | 4 | NULL | 1 | Using where |
+----+-------------+-------+-------+---------------+---------+---------+------+------+-------------+
1 row in set (0.00 sec)






評(píng)論(0)


暫無(wú)數(shù)據(jù)
CDA考試動(dòng)態(tài)
CDA報(bào)考指南
推薦帖子
0條評(píng)論
0條評(píng)論
0條評(píng)論
1條評(píng)論