I am working on improving the performance of some SQL queries on SQL-Server-2008. There are different ways to fulfill each request, and I want to find the fastest one.
However, the problem I am facing is that I am having problems identifying what is actually faster. Ideally, I could run each request one by one and see what works fastest. Perfectly...
The problem is that SQL is too smart to my liking. When building these queries, I run them several times. When I do this, query performance improves on its own. I would do this because of some of the backstage things SQL does. What is it? How can i avoid this?
For example, I run the query once and it takes 30 seconds. I run it again and takes 10 seconds. The more I run the request, the faster it works.
So, is there a way to "clear the cache" or what the equivalent will be in SQL? I want to get an exact indication of which request will work faster. Alternatively, what would be the best way to do the types of testing I want?
Any information regarding this topic will be accepted as a valid input.
Imreg source share