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`
EXPLAIN結果:
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
問題:
如何優化它,以便不使用臨時表?