I am having an issue with a login log table that I was wondering if I can get some assistance on. I have a table with 1.8 million records and the query (below) runs really slow. Any advice on how to resolve the slowness.
QUERY
I am trying to get the most recent log (last log)
* for each computer in the database.
SELECT DISTINCT userlogin.machineName, userlogin.DateTime, userlogin.Uname FROM vvcomputers.vvuserlogin ORDER BY DateTime desc
** This Query takes 23.5644 seconds to run when I try getting 500,000 records (it times out when I query the entire table).
TABLE STRUCTURE
CREATE TABLE IF NOT EXISTS `userlogin` (
`index` int(11) NOT NULL AUTO_INCREMENT,
`MachineName` varchar(255) CHARACTER SET ascii NOT NULL,
`DateTime` datetime NOT NULL,
`Uname` text CHARACTER SET ascii NOT NULL,
PRIMARY KEY (`index`),
KEY `dateTimeIndex` (`DateTime`),
KEY `machineNameIndex` (`MachineName`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1827287 ;
I recently added the dateTimeIndex and machineNameIndex keys but that didn't help much.