Reputation: 237
We have a database, and tables contains more than 2 million records. Database is hosted in Amazon aws server.
Sometimes the "select" query execution time is very very slow. What could be the reason behind this slow execution?
One of my query was this :
select UserDID, count(*) from exportusers
group by UserDID
having count(*) > 1;
The query say "executing query...
" and it never ends. I forcefully exit from the query browser.
Here is my Explain on select statement
mysql> Explain select count(*) from exportusers where status != 'active' and PREndDate < now() - interval 3 month and DTModified < now() - interval 3 month;
+----+-------------+------------+-------+-----------------------------------------------------------------------+--------------------------+---------+------+---------+------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra |
+----+-------------+------------+-------+-----------------------------------------------------------------------+--------------------------+---------+------+---------+------------------------------------+
| 1 | SIMPLE | exportusers | range | index_jobs_on_DTModified,index_jobs_on_PREndDate,index_jobs_on_Status | index_jobs_on_DTModified | 5 | NULL | 2377287 | Using index condition; Using where |
+----+-------------+------------+-------+-----------------------------------------------------------------------+--------------------------+---------+------+---------+------------------------------------+
1 row in set (0.30 sec)
Upvotes: 4
Views: 118
Reputation: 631
There could be a lot of reasons for a slow query on a larger table. A few:
NOTE: Some of these items may also be influenced by the database engine in use.
Upvotes: 1