I am using a SP in my database which I have reused from a previous question Date Intervals to query a start and end date and return all days between the 2 dates which I then do a JOIN to my orders table.
For some reason the query with the SP takes over 40sec and under 3sec without with the SP.
I have done some research here and this answer suggests that the character set may have something to do it. SP Performance
The collation connection and database collation state utf8_general_ci and latin1_swedish_ci respective, and the table collation for the table is latin1_swedish_ci.
Here is my sql
call make_intervals('2014-01-29 00:00:00','2015-03-03 00:00:00',1,'DAY');
SELECT
interval_start,
SUM(TenderedAmt) total
FROM time_intervals ti
LEFT JOIN tblorderheaders o
ON o.OrderDate = ti.interval_start AND ( ClientId=35 or ClientId IS NULL ) GROUP BY DATE(ti.interval_start) ORDER BY ti.interval_start ASC;
If I execute the following query it takes within 0.2sec without the JOIN to the table produced by the procedure.
SELECT SUM(TenderedAmt) total FROM tblorderheaders WHERE ClientId=35 AND (OrderDate>='2014-01-29' AND OrderDate<='2015-02-27') GROUP BY DATE(OrderDate)
Can anyone advise to why this query takes so long?
Thanks in advance.