I have a quite simple table used for logging visits on members profiles, with a multi-column key (member_id, visitor_id, month_visited) and a more precise date. The month_visited is a CHAR(7) column like that : '2013-10'
Each new month, I want to compact in another table the data for the previous month, and then delete it.
My request is simply:
DELETE FROM visits WHERE month_visited = '2013-10'
It takes AGES to remove these lines, like several minutes on my dedicated server. The same goes when I just query a simple SELECT COUNT(*) FROM visits.
I have 1.8M entries for 2013-10.
But it takes ages. And when I try
EXPLAIN SELECT * FROM visits WHERE month_visited = "2013-10"
it tells me:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE visits ref idx_month_visited idx_month_visited 21 const 1782148 Using where
"using where", seriously??
EDIT : sorry, I forgot to specify that I also added an INDEX on just the month_visited column :) (as the EXPLAIN shows, actually, but it does not use it...)
How can I improve those (obviously) simple queries? I am a noob in MySQL but I don't think it is quite normal that it takes minutes to perform these queries.
Thanks for any input!
Best regards,