I'm selecting Data from a mysql database table. When i'm searching a specific date, my index is wiorking fine. When I'm searching data between two dates the index isn't working and the query takes to long. Has anybody an idea how can i improve the query or the index?
Query A:
EXPLAIN SELECT * FROM sal_import WHERE dateStats>="2011-07-28" AND dateStats<="2011-07-30" GROUP BY f_shop id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE i range dateStats dateStats 3 (NULL) 7896 Using where; Using temporary; Using filesort Query B:
EXPLAIN SELECT * FROM sal_import i WHERE dateStats="2011-07-30" GROUP BY f_shop id select_type table type possible_keys key key_len ref rows Extra 1 SIMPLE i ref dateStats dateStats 3 const 2182 Using where This is the index of the table:
ALTER TABLE sal_import ADD INDEX(dateStats,f_shop); Thank you very much.