桌子:
CREATE TABLE `T1` (
`UserId` int(10) unsigned NOT NULL,
`FriendUserId` int(10) unsigned NOT NULL,
`IsDisplayed` tinyint(1) unsigned NOT NULL,
`Created` datetime NOT NULL,
KEY `FriendUserId` (`FriendUserId`,`IsDisplayed`,`UserId`,`Created`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
查询:
SELECT `UserId`, `FriendUserId`, UNIX_TIMESTAMP(`Created`) AS `Created`
FROM `T1` WHERE `FriendUserId` = 22
AND `IsDisplayed` = 0
GROUP BY `UserId`
ORDER BY `Created`
解释结果:
id: 1
select_type: SIMPLE
table: T1
type: ref
possible_keys: FriendUserId
key: FriendUserId
key_len: 5
ref: const,const
rows: 1
Extra: Using where; Using index; Using temporary; Using filesort
问题:
如何优化它以便不使用临时表?