We are facing performance related problem with select query. We have reports table which contains approximate 2 Crore (20 million) records.
When we are executing simple count(*) from to check count, its taking more than 1 minute to display result.
Here is the info about mysql, server and query
System info
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 info
mysql Ver 14.14 Distrib 5.1.66, for debian-linux-gnu (x86_64) using readline 6.1
my.conf settings
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
.
EDIT : Query execution with index and without index
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)
I am struggling with performance issue, can anyone please help me to improve performance of table?