My applications run queries against a SQL Server database.
In many cases, I see the advantage of the execution plan: for example, I press the button for the first time on the button
SELECT * from Tasks
WHERE IdUser = 24 AND
DATE < '12/12/2010' and DATE > '01/01/2010'
it takes 15 seconds for the first time, 8 seconds for the next time points.
EDIT: I USE PARAMETRIZED REQUESTS.
So, the second time I have an improvement of 7 seconds.
Now, when I start the application again (so that I am making a new connection to the database), the first time it takes 15 seconds, the second time 7 ...
How can you tell SQL Server to store execution plans, at least to remember them for the same days? Or, how can I benefit from already calculated implementation plans? If different users run the same query, this is a way to tell SQL Server to be smart enough to use the same execution plan, even if IdUser is different in this case.
I have some parameters in the software, so maybe the next query execution will have different MinDate and MaxDate, but will this affect the query plan?
source
share