I have large MySQL tables with hundreds of thousands of rows.
I need to write a query on a customers table which gets the count of when customers will be available to contact again.
eg.
SELECT 'This week', COUNT(*) FROM customers
WHERE sales_person_id = 1 AND DATEDIFF(NOW(), available_date) < 7
UNION
SELECT 'Next week', COUNT(*) FROM customers
WHERE sales_person_id = 1 AND DATEDIFF(NOW(), available_date) >= 7
AND DATEDIFF(NOW(), available_date) < 14
UNION
... (a few more like this)
Having written a similar query on a different large table, I did notice that changing the engine from InnoDB to MyISAM sped up the query considerably (InnoDB is not needed for these tables as they do not have foreign key checks). Is there anything else I can do to speed up counts like this (other than indexing the appropriate fields)?