Mysql查询提高性能

use*_*740 5 php mysql indexing

我有以下查询:

SELECT COUNT(sid),fDate,COUNT(DISTINCT(cid)) 
    FROM forwarding  
    WHERE fDate BETWEEN "2011-06-01" AND "2011-06-30" 
    GROUP BY fDate
Run Code Online (Sandbox Code Playgroud)

解释给我以下输出:

id  select_type table   type    possible_keys   key key_len ref rows    Extra
1   SIMPLE  forwarding  index   fDate,fDate_2   fDate_2 3       1481127 Using where
Run Code Online (Sandbox Code Playgroud)

你可以看到有很多数据.总工作时间为12秒.我该如何改善表现?我不知道在设置索引时我能做些什么.

这个表有我的索引:

fDate (fDate, f_shop)
fDate2(dDate),
f_shop(f_shop)
Run Code Online (Sandbox Code Playgroud)

谢谢您的帮助.

更新:

现在我在where子句中添加了一个列,查询比之前慢得多.

SELECT COUNT(sid),fDate,COUNT(DISTINCT(cid)) FROM forwarding 
WHERE fDate BETWEEN "2011-06-01" AND "2011-06-30"  AND f_shop=10077 GROUP BY fDate
Run Code Online (Sandbox Code Playgroud)

我有一个关于forwardDate和f_shop的索引,但性能会变慢.什么是完美的解决方案?谢谢

mic*_*667 2

MySQL 如何使用索引到目前为止回答了我所有有关 MySQL 索引的问题。这可能值得一读。