本文介绍了慢计数(*)在innoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有3000000条记录的表 message_message

I have a table message_message with 3000000 records.

当我进行计数(*)查询时,它很慢...:

when I make a count(*) query, It's very slow...:

mysql> select message(*)from message_message ;

+ ---------- +

+----------+

| count(*)|

| count(*) |

+ ---------- +

+----------+

2819416 |

| 2819416 |

+ ---------- +

+----------+

min 35.35 sec)

1 row in set (2 min 35.35 sec)

解释:
mysql> 从message_message解释select count(*)

| id | select_type |表|类型| possible_keys |键| key_len | ref | rows | Extra |

| id | select_type| table | type | possible_keys | key | key_len | ref | rows |Extra |

| 1 | SIMPLE | message_message |索引| NULL | PRIMARY | 4 | NULL | 2939870 |使用索引|

| 1 | SIMPLE | message_message | index | NULL | PRIMARY | 4 | NULL | 2939870 | Using index |

集合中的1行(0.02秒)

1 row in set (0.02 sec)

会发生什么?

推荐答案

请查看在InnoDB中,你需要做一个全表扫描,在MyISAM它的索引读取。

Have a look at This Post in InnoDB you need to do a full table scan, where as in MyISAM its a index read.

如果您使用其中子句,但它会更改执行模式以使用索引,因此InnoDB比完全不受限计数的MyISAM慢,其中性能与受限计数匹配。

If you use a where clause though it changes the execution pattern to use indexes, so in general InnoDB will be slower than MyISAM on full unrestricted counts, where as the performance matches up on restricted counts.

这篇关于慢计数(*)在innoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 00:03