I've developed a billing summary page use mysql + php.
- there are many users : (1M)
- light user :each has less than 10K record :0.99M users
- heavy user :each has about 1M record
SQL is the following :
SELECT SUM(value_a) A, SUM(value_b) B, SUM(value_c) C
FROM daily_data_sep_2010
WHERE user_id='<user_id>'
AND type
IN (
'type_a', 'typeb'
)
AND publish_date
BETWEEN '<start_date>'
AND '<end_date>'
GROUP BY publish_date
ORDER BY publish_date DESC
daily_data_sep_2010 table type is MyISAM
There are several types of same Queries,but SUM(value_a) A, SUM(value_b) B, SUM(value_c) C are realy same (equal) "WHERE", "GROUP BY" conditions are not same
This screen is very slow for heavy users. Do you have any good solutions?
explain is here
|table |type |possible_keys |key |key_len |ref |rows |Extra|
|daily_data_sep_2010| ALL| PRIMARY,user_id_key,type,publish_date|||| 1059756 |Using where; Using temporary; Using filesort|
I think row size is too large for sum. so I look forward to onother solutions (Hadoop?)