views:

30

answers:

1

In SQL Server 2005 management studio I am testing a query which uses some table variables, one of which has a clustered unique constraint on it. I am noticing that the total execution time actually goes down by a good amount when I include the actual execution plan to analyze it.

What is the reason for this, and should I only test for the total execution time when the option to include the execution plan is off.

Thanks!

+1  A: 

Sounds a bit odd to me tbh. Are you sure that the difference you're seeing is not down to caching? I would always test the performance of a sproc by NOT including the execution plan, and I would clear the cache down before each run in order to have a fair comparison (on a test/dev db server, not production).

DBCC FREEPROCCACHE -- will clear the execution plan cache
DBCC DROPCLEANBUFFERS -- will clear the data cache
AdaTheDev
When I run DBCC DROPFREEBUFFERS I get an error -- Incorrect DBCC statement. When I google it the command DBCC DROPCLEANBUFFERS comes up.
Chris Mullins
@Chris - sorry, typo! corrected now
AdaTheDev
Well I tested it with DBCC FREEPROCCACHE and DBCC DROPCLEANBUFFERS commands before the statement, and it is still faster with the Show Execution Plan on. I wonder if it has something to do with statistics, and if so how I can get the faster set of results when I run the query in production.
Chris Mullins
I am going to mark your answer as correct. Although I still don't understand why it happens, it is probably a bug in the way the client statistics are counted, maybe they don't include the time for creating the execution plan when the execution plan display is on, or something like that. Your tip about clearing the cache helps me get a good baseline on the total execution time between trys so thanks for that.
Chris Mullins