So I have a DB with ~5 million rows and I am trying to optimize the load times. My DB has columns and indexes as optimized as I can think so I assume its the query. This query runs on a table with ~5 million rows and returns 40 of them, but it takes 101 seconds.
If I remove the timezone conversions the same query takes 0.0015 seconds but returns slightly different results because of the timezone difference. How could I optimize to get the correct results with more speed?
SELECT *, date(CONVERT_TZ(eventDate, "US/Eastern", "America/New_York")) as `timezoneDate`
FROM `transactions`
WHERE `isValid` = X
AND `storeID` = X
AND date(CONVERT_TZ(eventDate, "US/Eastern", "America/New_York")) >= '2014-11-19'
AND date(CONVERT_TZ(eventDate, "US/Eastern", "America/New_York")) <= '2014-11-25'
ORDER BY `eventDate`
Also if it was not clear before, the second timezone I am converting to changes depending on user, so right now its America/New_York which is the same as US/Eastern but it changes.
where foo=1is fine and could use any applicable indexes.where somefunc(foo)=1isn't, because the result ofsomefuncis unindexed.eventdate = date(convert_tz('2014-11-19'))-type thing. then you CAN use indexes. because the indexed field is being used "raw".