I need to do a pretty big search once each day/week/month and having a problem with the speeed. I have been increasing the buffer sizes to use 50% of the ram (2gb) and some other tweaks but none have given any performance increase.
SELECT SUM(MessageCount) AS ErrorCount, Country, StatusCode, StatusText
FROM messages
WHERE StatusCode IN(3,4,5,6,8,9,10,11,13) AND SentOn >= 1394275285391 AND SentON < 1396863685391
GROUP BY Country, StatusCode
Takes around 50-70sec to process when running the query in mysql workshop and the table contains about 6,500,000 rows. To speed it up I added a index for StatusCode, SentOn and Country ( = CHAR(2)) and called it ErrorCountries seen below. I am not really happy about the speed in the workshop but I guess I could live with it if I had to.
I did an explain and got this result:
id=1
select_typ=SIMPLE
table=messages type=range
possible_keys=SentOn,ErrorCountries
key=ErrorCountries
key_len=12
rows=290977
filter=100.00
extra=Using index condition; Using MRR; Using temporary; Using filesort
I guess temporary and filesort might be a problem with the speed.
So while I said that the query takes 50-70sec in the workshop, it does not perform like this in my program. I did not have any command timeout in the connection string so I thought that adding it would solve this. But when I now have changed the timeout to 5min I started to wounder where the problem really is...
var sql = "SELECT SUM(MessageCount) AS ErrorCount, Country, StatusCode, StatusText" +
" FROM messages" +
" WHERE StatusCode IN(3,4,5,6,8,9,10,11,13) AND SentOn >= " + @from + " AND SentOn < " + to +
" GROUP BY Country, StatusCode";
var res = db.Database.SqlQuery<Result>(sql).ToList();
Why is this query taking a minute to run in the workshop? Why does it take over 5min to run in the program? I have the program importing to the db at both time. And what can I do to make it faster?