MySQL InnoDB table returns 20% of rows then halts
I am trying to return a result set from a MySQL database table of email subscriptions.
The table is called subscribe and looks like this:
+-----------------+------------------+------+-----+---------------------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------+------------------+------+-----+---------------------+-------+
| eid | int(11) unsigned | NO | PRI | NULL | |
| subscribeStatus | varchar(4) | NO | PRI | NULL | |
| transDate | datetime | NO | PRI | 0000-00-00 00:00:00 | |
| senttoevDate | datetime | YES | | NULL | |
+-----------------+------------------+------+-----+---------------------+-------+
The PK is (eid,subscribeStatus,transDate) and there are the following extra indexes:
idxEid on eid, idxTDate on transDate
The table is an InnoDB table. It contains about 480K rows.
The version of MySQL is 5.1.39 x86_64 and I'm running Windows 7 64bit.
The table has a row inserted each time a user subscribes or u开发者_如何学Pythonnsubscribes from email. I want to know what the latest subscription status is for all users. The query I want to run is:
select
eid, transDate from subscribe s
where
transDate = (select max(transDate) from subscribe si where si.eid = s.eid)
When I run this in MySQL Query Browser (and in TOAD for MySQL) it immediately returns about 98K rows (into the results grid), and then just hangs. I can see from MySQL Administrator GUI that the state is "Sending data". I have left it for up to an hour and it hasn't finished returning the results, or even moved on from the 98K.
I have adjusted the my.ini params for InnoDB to increase the innodb_buffer_pool_size to 3Gb (my machine has 4Gb) but I can see from Task Manager that mysqld is never using more than about 400K Mb.
I have created a MyISAM version of the table to see if that is any better, but it also hangs at around about the same number of rows returned.
Can anyone suggest why the query returns some rows but then "hangs", and also what I can do to get around this and get the query to return as it should?
Many thanks in advance for any help you can offer!
I have no idea why it would hang, but why don't you try to avoid the subquery with something like
select eid, max(transDate) from subscribe group by eid
精彩评论