I have about 20 simple queries running seperately on loading a php page with mysql querying. On my localhost the page takes about 3 seconds to load but on the live server this is over 30 seconds. I'm trying to shave some time off but I'm having trouble figuring out exactly why it is so slow. Even on my localhost 3 seconds seems a bit long for just a few simple queries.
The database I am selecting from has about 100,000 rows of which I'm selecting for the most part just one field from. It uses a MyISAM engine.
An example of where it slows up:
I am running two similar queries, one without a conditional and one with. The first:
SELECT COUNT(*) AS sales FROM Master
takes about 0.0003 second to run on my localhost. When I add a conditional:
SELECT COUNT(*) AS sales FROM Master WHERE YEARWEEK(SaleDate) = YEARWEEK(DATE_SUB(CURDATE(),INTERVAL 2 WEEK))
it takes about 0.2 seconds on my localhost.
In the last query I am trying to get the number of sales from 2 weeks ago. The week number is a dynamic variable from php.
Is there a better way to write the last query and speed things up?