i am running into a problem, i have huge database and now i cant make changes i need to process all this data first. Problem is that each query which is writen below takes about 1-2 Minutes. If anyone know how to make a optimized select i would apprichiate it.
select distinct x.peerId
,(select max(id) from checkPeer where peerId=x.peerId) as idd
from checkPeer x where x.id>0 order by x.id desc
Is there way to optimize this select from below defined table?
CREATE TABLE `checkPeer` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`peerId` varchar(100) COLLATE utf8_bin DEFAULT NULL,
`peerDate` datetime DEFAULT NULL,
`peerUrl` bigint(20) DEFAULT '0',
`peerState` bigint(20) DEFAULT '0',
`peerMessage` varchar(500) COLLATE utf8_bin DEFAULT NULL,
`peerResource` varchar(5000) COLLATE utf8_bin DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `peerId` (`peerId`),
KEY `peerUrl` (`peerUrl`)
) ENGINE=MyISAM AUTO_INCREMENT=688791 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
Thank you!
a few immediate suggestions, remove
DISTINCTand try the following:The above works great, if you wind up needing more fields but you stated you only need the two so you can try: