我对一张大表(超过200万行)进行查询,需要大约10秒才能完成。有没有办法优化它?查询如下:
SELECT
DATE_FORMAT(date0, '%Y-%m' ) AS Yr_Mo,
DATE_FORMAT(date0, '%p' ) AS AM_PM,
province AS Province,
SUM( IF( top_ads + left_ads =0, 1, 0 ) ) AS pagesWithRightAdsOnly,
AVG( top_ads ) AS top_ads,
AVG( left_ads ) AS left_ads,
AVG( right_ads ) AS right_ads
FROM ad_counts
GROUP BY Yr_Mo, AM_PM, Province
表'ad_counts':
date0 (timestamp)
province(varchar)
keyword_id
number_ads(int)
top_ads (int)
left_ads (int)
right_ads (int)
date0上的索引,但date0不是唯一的。
有什么想法吗?
编辑: 说明:
id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE baidu_pro_ad_counts ALL NULL NULL NULL NULL 2160752 Using temporary; Using filesort