我们正在面对与选择查询相关的性能问题。 我们有报告表,其中包含大约2 Crore(2000万)记录。MySQL:选择查询性能问题
当我们执行简单计数(*)来检查计数时,它将花费超过1分钟来显示结果。
下面是关于MySQL,服务器和查询信息
系统信息
OS : Debian 6.0.7
Model : AMD Opteron(tm) Processor 6172
cpu MHz : 2100.154
cache size : 512 KB
processor : 2
Memory total used free shared buffers cached
Mem: 16083 6335 9747 0 153 5323
Mysql的信息
mysql Ver 14.14 Distrib 5.1.66, for debian-linux-gnu (x86_64) using readline 6.1
my.conf设置
key_buffer = 16M
max_allowed_packet = 16M
thread_stack = 192K
thread_cache_size = 8
max_connections = 1000
table_cache = 128
innodb_buffer_pool_size = 3G
query_cache_limit = 512M
query_cache_size = 3G
mysql> select count(*) from reports;
+-----------+
| count(*) |
+-----------+
| 23311587 |
+-----------+
1 row in set (67.07 sec)
DB engine : Innodb
。
编辑:查询执行索引和无索引
mysql> select count(id) from Reports USE INDEX(PRIMARY);
+-----------+
| count(id) |
+-----------+
| 17835433 |
+-----------+
1 row in set (55.56 sec)
mysql>
mysql> select count(id) from Reports;
+-----------+
| count(id) |
+-----------+
| 17835433 |
+-----------+
1 row in set (55.65 sec)
我与性能问题挣扎,任何人都可以请帮我提高表的性能?
请显示表格布局。 –
尝试只是做一个索引/键不计数*看看是否有所作为 – Dave
这可以帮助:http://stackoverflow.com/questions/1332624/speeding-up-row-counting-in-mysql – NewInTheBusiness