mysql优化count(*)查询语句

 

1)count(*)会忽略所有的列,直接统计所有列数,不要使用count(列名),也就是不要使用count(1),count(id)

2)可以使用explain查询近似值,用近似值替代count(*)

3)使用缓存,记录总数

4)允许的话,把innodb改为myisam

5)SELECT (SELECT COUNT(*) from test_student) AS count FROM test_student;

posted @ 2020-07-10 18:16  一个人的孤独自白  阅读(849)  评论(0编辑  收藏  举报