mysql> select count(*) from fdp.reuters_rkd_pm;
+----------+
| count(*) |
+----------+
| 9431256 |
+----------+
1 row in set (8 min 55.33 sec)mysql版本5.5.10, 数据库服务器内存4G,innodb存储引擎,程序员开发测试库,没有任何并发压力,现在任何时候执行都是需要9分钟左右。
查询总记录数竟然要9分钟,这是神马情况,如何调整优化呢?附带explain执行计划mysql> explain select count(xref) from fdp.reuters_rkd_pm;
+----+-------------+----------------+-------+---------------+---------+---------+------+----------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------------+-------+---------------+---------+---------+------+----------+-------------+
| 1 | SIMPLE | reuters_rkd_pm | index | NULL | PRIMARY | 53 | NULL | 12597698 | Using index |
+----+-------------+----------------+-------+---------------+---------+---------+------+----------+-------------+
1 row in set (0.00 sec)
mysql>走的也是索引啊,非常快就出来结果了。我非常迷茫了......
+----------+
| count(*) |
+----------+
| 9431256 |
+----------+
1 row in set (8 min 55.33 sec)mysql版本5.5.10, 数据库服务器内存4G,innodb存储引擎,程序员开发测试库,没有任何并发压力,现在任何时候执行都是需要9分钟左右。
查询总记录数竟然要9分钟,这是神马情况,如何调整优化呢?附带explain执行计划mysql> explain select count(xref) from fdp.reuters_rkd_pm;
+----+-------------+----------------+-------+---------------+---------+---------+------+----------+-------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+----------------+-------+---------------+---------+---------+------+----------+-------------+
| 1 | SIMPLE | reuters_rkd_pm | index | NULL | PRIMARY | 53 | NULL | 12597698 | Using index |
+----+-------------+----------------+-------+---------------+---------+---------+------+----------+-------------+
1 row in set (0.00 sec)
mysql>走的也是索引啊,非常快就出来结果了。我非常迷茫了......
恩,好的。我去试试看,innodb也可以吗?
你的表有其它索引吗?
如果有
select count(*) from tt where 其它索引字段>0 条件可以修改,只有能用到索引
有索引的,你看后面的explain结果,走的都是主键索引的。
repair table fdp.reuters_rkd_pm;报错如下:
'fdp.reuters_rkd_pm', 'repair', 'note', 'The storage engine for the table doesn''t support repair'
你早说啊,杯具了,看不到这个state状态了,我都drop table ,然后create new table了。
呵呵,莫紧张,我也就随口一说,因为之前有听过这个bug,太多statistic状态的process导致所有语句都很慢.
然后innodb引擎里,第一次select count(*)是会全表扫描的,因为它本身没有记录这个行总数,这个和myisam不同,所以
看看chinaunix类似问题的讨论
http://bbs.chinaunix.net/thread-1018546-1-1.html