Networking

February 19, 2009 at 8:36 am (Misc, PASS) (, , , , )

Andy Warren has just posted the last entry in a very interesting set of posts about building and working your own network. I think they’re all worth a read, especially if you’ve been thinking about blogging, Twitter, LinkedIn or just volunteering at your local users group.

Permalink Leave a Comment

Procedure Cache and Dynamic Management Views

October 30, 2008 at 9:48 am (SQL Server 2005, SQL Server 2008, TSQL) (, , , , , , , , , )

I’m just going through the chapter on the procedure cache in the new book and I’m having a blast playing with the dynamic management views and functions that let you access the procedure cache. It’s just too much fun and way too easy to get detailed information about the queries in the system, not like the old days. First, you can access the cache itself with the DMV, sys.dm_exec_cached_plans. This shows some of the data describing the plan in cache, but most importantly it provides the plan_handle. You need this for other joins later. You can also use sys.dm_exec_query_stats to get aggregated performance statistics about the plan. It also has the plan_handle and two things new to SQL Server 2008, the query_hash and the query_plan_hash, also known as query fingerprints. I’ll get into those things another day, but they’re pretty exciting all by themselves. Finally, you can also get information about currently executing queries, which may or may not be in the cache, through sys.dm_exec_requests. These are all views, so you can just query them directly. Unfortunately, the first two don’t offer any chance to filter the information returned by database or spid, etc., but sys.dm_exec_requests does.

So, getting basic information about the size of a plan or how long it’s been cache or the accumulated time that it’s run is all interesting and everything, but what about getting a peek at the execution plan itself. Enter the dynamic management function sys.dm_exec_query_plan( plan_handle ). Just join it with one of the other views and suddenly you’ve got some real information:

SELECT *
FROM sys.dm_exec_cached_plans c
CROSS APPLY sys.dm_exec_query_plan(c.plan_handle) p

You’ll get an XML plan, which, when you click on it in 2008 opens up as a graphical plan since, to Management Studio in 2008, they’re the same thing. Easy-peasy.

But what about that query that’s hanging up and blocking all the othe query’s? What the heck did the developers do this time? Let’s try out the DMF sys.dm_exec_sql_text ( plan_handle ).

SELECT *
FROM sys.dm_exec_requests r
CROSS APPLY sys.dm_exec_sql_text(r.plan_handle) t

You’ll see the query, as it was passed, in the text field. Great stuff. Really handy.

There is a ton to explore here and it’s all very useful stuff.  These are available in SQL Server 2005 in addition to SQL Server 2008.

Permalink Leave a Comment

Twitter?

October 29, 2008 at 9:50 am (Misc) (, )

After much discussion in a set of emails between some of the more dangerous people that attend the PASS conference, I’ve decided to create a Twitter account. I created it under my name for the time being. I may blow it up later & go with something else. I’m not sure. I still don’t quite get the point of this one, but I’m hooked in now. If you’re interested in “following” me (like I could lead you anywhere), click here.

Permalink Leave a Comment