Having trolled the net many discussions cover aspects of my problem but I fail to see a pattern that applies here:
I have a basic .NET WinForm application using EF 3.5 with MySQL. The application works fine with most queries, but any query containing Distinct() is very slow or causes the "The timeout period elapsed prior to completion of the operation or the server is not responding." exception the first time it is run after a reboot of the machine. I.e. when restarting the aplication, even after stopping and re-starting the MySQL Service the Distinct() queries work fine from now on (i.e. taking less than 1 second).
The fact that I cannot reproduce the problem by re-running the application or re-starting MySQL rules out that EF compilation or MySQL caching is a factor. Only after rebooting the problem re-occurs. Makes me think it's perhaps a .NET initialization issue or something else related to the OS. The problem has been observed on XP and Win 7.
Any ideas are appreciated. (Also ideas on trying to reproduce the problem without re-booting the machine, which is highly impractical :-)
Update:
The query generated by EF looks like this:
SELECT Distinct1.C2 FROM (
SELECT DISTINCT YEAR(Extent1.RecDate) AS C2
FROM dailyrecord AS Extent1
WHERE (Extent1.STN = 430030) AND (Extent1.WBAN = 99999)
) AS Distinct1;
Running this in the mysql shell takes around 30s the first time, around 1s all subsequent times even after re-starting mysql. Back to 30s after rebooting. It appears the OS is reading the entire db file the first time, but not thereafter (very little HD activity on subsequent queries, even with modified query parameters).
How can I flush the OS's read cache to test my theory?