表结构
iMoney 类型:float dtEventTime 类型:datetime iType 类型:tinyint iAction 类型:tinyint
现在存在的索引(test)是:
iType 跟 dtEventTime 的一个组合索引
select sum(iMoney) as iMoney,iAction from CostMoney where iType = 3 and dtEventTime between '2012-09-29' and '2012-09-30' group by iAction
这条语句查询后explain 下
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE CostMoney range test test 9 NULL 3893 Using where; Using temporary; Using filesort
这个表里面的数据每天特别大 , 请问有什么好的优化办法?
给你点建议:
1、按天分表,这样每个表就不会那么大
2、用另一个缓存、或者表专门累加iMoney,每天的分记录,产生一条累加一次
3、group by iAction order by NULL ?(天知道有没有效果)