September 09, 2010

"For successful technology, reality must take precedence over public relations, for nature cannot be fooled."    --  Richard Feynman
Moving Sql Server Code
May8

Written by:RBarryYoung
5/8/2009 10:04 AM 

I am developing a T-SQL test harness for automated performance tests. The testing procedure will receive a string to execute as Dynamic SQL. I am going to add a bunch of standard initialization and measurement stuff to it, that's all easy. However, one additional thing that I want to do is to capture the Execution Plan (the actual plan is preferred) into an XML variable or column to be saved as part of the test header record.

I puzzled over how to do this for while this morning, until I came up with the following approach:

Declare @qp as XML

SELECT @qp = query_plan

 From sys.dm_exec_requests

  Cross Apply sys.dm_exec_query_plan(plan_handle)

 Where session_id = @@spid

 

-- Put Code to Test Here

 

select @qp

True, this will include some extra/redundant stuff like the QP for the Test-Harness statments themselves, but I think that I can live with that.

Tags:

10 comment(s) so far...

Re: Performance Test-Harness, pt1: Capturing the execution plan.

Does this only work with 2005 and higher?

By Dan White on  5/14/2009 8:39 AM

Re: Performance Test-Harness, pt1: Capturing the execution plan.

Yes, sorry. I have very little occasion to work on SQL Server 2000 anymore.

By RBarryYoung on  5/25/2009 12:01 PM

Re: Performance Test-Harness, pt1: Capturing the execution plan.

Look forward to seeing your test harness :-)

By Christopher Stobbs on  5/27/2009 3:25 AM

Re: Performance Test-Harness, pt1: Capturing the execution plan.

Will have soon!

By host on  5/27/2009 11:42 AM

Re: Performance Test-Harness, pt1: Capturing the execution plan.

Merci pour cette information casinos virtuels

By sarat on  1/20/2010 8:09 AM

Re: Performance Test-Harness, pt1: Capturing the execution plan.

Being a blogger myself, I am really impressed with your blog and the topics you’ve chosen to discuss. www.flashdevs.com/"> flex development

By Mike on  2/24/2010 8:41 AM

Re: Performance Test-Harness, pt1: Capturing the execution plan.

Being a blogger myself, I am really impressed with your blog and the topics you’ve chosen to discuss.

By flex development on  2/24/2010 8:44 AM

Re: Performance Test-Harness, pt1: Capturing the execution plan.

Being a blogger myself, I am really impressed with your blog and the topics you’ve chosen to discuss.

By cheap auto insurance on  4/9/2010 1:18 PM

Re: Performance Test-Harness, pt1: Capturing the execution plan.

Very good article, thank you
jouer casino

By Maurice on  4/26/2010 9:34 AM

good

This code is most useful in all ways casino en ligne francais

By stew biff on  5/10/2010 12:04 AM

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Add Comment  Cancel 
 

Copyright 2008 by R. Barry Young
 RBarryYoung.net  |  Terms Of Use  |  Privacy Statement