我需要创建什么索引来避免使用临时文件排序的顺序
EXPLAIN SELECT tid, sum(count)
FROM test
WHERE cid = 1
GROUP BY tid
ORDER BY sum(count) DESC
1 SIMPLE test ref PRIMARY,id_UNIQUE,cid cid 4 const 2 Using where; Using index; Using temporary; Using filesort
创建表:
CREATE TABLE test(
cid INT,
tid INT,
datedm INT,
count INT,
PRIMARY KEY(cid,tid,datedm),
INDEX(cid,tid,count),
UNIQUE INDEX id_UNIQUE(cid,tid,datedm)
);