MySQL Forums
Forum List  »  Optimizer & Parser

Why does this query take 2 minutes?
Posted by: Mike Petit
Date: February 02, 2005 10:39AM

Following output for your consideration (mySQL 4.0.20 on fast Linux server):

mysql> SELECT COUNT(*) as preCount from hapresults.hresult
-> WHERE hresultid>0
-> AND hresult.hcreationtimestamp>'2003-10-17 14:01:17'
-> AND hid='petit';

+----------+
| preCount |
+----------+
| 298784 |
+----------+
1 row in set (1 min 57.17 sec)

mysql> explain SELECT COUNT(*) as preCount from hapresults.hresult
-> WHERE hresultid>0
-> AND hresult.hcreationtimestamp>'2003-10-17 14:01:17'
-> AND hid='petit';
+---------+------+--------------------------------+------+---------+-------+--------+-------------+
| table | type | possible_keys | key | key_len | ref | rows | Extra |
+---------+------+--------------------------------+------+---------+-------+--------+-------------+
| hresult | ref | PRIMARY,hcreationtimestamp,hid | hid | 64 | const | 268172 | Using where |
+---------+------+--------------------------------+------+---------+-------+--------+-------------+
1 row in set (0.00 sec)

Primary key on hresult is hresultid. Both hcreationtimestamp and hid are keys. Table hresult is about 6 million rows. Especially given the fact that this is a count-only operation, I'm mystified why it performs so poorly. Anyone have any ideas? Any help greatly appreciated.

Options: ReplyQuote


Subject
Views
Written By
Posted
Why does this query take 2 minutes?
3862
February 02, 2005 10:39AM
2529
February 02, 2005 07:36PM
2257
February 03, 2005 07:21AM
2320
February 03, 2005 08:34PM
2442
February 03, 2005 08:43PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.