SELECT
SUM(num) AS numSum,
type
FROM
table
WHERE DATE BETWEEN “2015-09-03”
AND “2015-09-18”
GROUP BY type
ORDER BY numSum DESC
LIMIT 0, 10
Mysql
单独索引分别建在num,type和date上
explain提示Using where; Using temporary; Using filesort
问一下索引怎样建,能避免创建临时表和一次额外的排序?
SUM(num) AS numSum,
type
FROM
table
WHERE DATE BETWEEN “2015-09-03”
AND “2015-09-18”
GROUP BY type
ORDER BY numSum DESC
LIMIT 0, 10
Mysql
单独索引分别建在num,type和date上
explain提示Using where; Using temporary; Using filesort
问一下索引怎样建,能避免创建临时表和一次额外的排序?
解决方案
35
创建这个索引试试:
create index idx_table on table(date,type,num)
35
以文本方式贴出
explain select …
show index from ..
以供分析。
explain select …
show index from ..
以供分析。