<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www2.sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>&amp;quot;Planning&amp;quot; for Success (A Month of Activity Monitoring, Part 11 of 30)</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2011/04/11/planning-for-success-a-month-of-activity-monitoring-part-11-of-30.aspx</link><description>This post is part 11 of a 30-part series about the Who is Active stored procedure. A new post will run each day during the month of April, 2011. After April all of these posts will be edited and combined into a single document to become the basis of the</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>re: "Planning" for Success (A Month of Activity Monitoring, Part 11 of 30)</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2011/04/11/planning-for-success-a-month-of-activity-monitoring-part-11-of-30.aspx#34824</link><pubDate>Tue, 12 Apr 2011 13:11:24 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:34824</guid><dc:creator>Alejandro Mesa</dc:creator><description>&lt;p&gt;Adam,&lt;/p&gt;
&lt;p&gt;Great series and an awesome proc.&lt;/p&gt;
&lt;p&gt;&amp;gt; Can you describe the problem?&lt;/p&gt;
&lt;p&gt;Are you talking about the number of nested levels allowed in the xml data type?&lt;/p&gt;
&lt;p&gt;We should use sys.dm_exec_text_query_plan if the plan has more than 128 levels of nested elements.&lt;/p&gt;
&lt;p&gt;Here is a quick and dirty example.&lt;/p&gt;
&lt;p&gt;USE Northwind;&lt;/p&gt;
&lt;p&gt;GO&lt;/p&gt;
&lt;p&gt;DECLARE @sql nvarchar(MAX);&lt;/p&gt;
&lt;p&gt;DECLARE @i int;&lt;/p&gt;
&lt;p&gt;SET @i = 3;&lt;/p&gt;
&lt;p&gt;SET @sql = N'&lt;/p&gt;
&lt;p&gt;SELECT&lt;/p&gt;
&lt;p&gt;	*&lt;/p&gt;
&lt;p&gt;FROM&lt;/p&gt;
&lt;p&gt;	(SELECT TOP(1) OH.OrderID FROM dbo.Orders AS OH) AS T1(c1)&lt;/p&gt;
&lt;p&gt;	INNER JOIN&lt;/p&gt;
&lt;p&gt;	(SELECT TOP(1) OH.OrderID FROM dbo.Orders AS OH) AS T2(c1)&lt;/p&gt;
&lt;p&gt;	ON T2.c1 = T1.c1';&lt;/p&gt;
&lt;p&gt;WHILE @i &amp;lt; 129&lt;/p&gt;
&lt;p&gt;BEGIN&lt;/p&gt;
&lt;p&gt;	SET @sql = @sql + N'&lt;/p&gt;
&lt;p&gt;	INNER JOIN&lt;/p&gt;
&lt;p&gt;	(SELECT TOP(1) OH.OrderID FROM dbo.Orders AS OH) AS T' + LTRIM(@i) + N'(c1)&lt;/p&gt;
&lt;p&gt;	ON T' + LTRIM(@i) + N'.c1 = T' + LTRIM(@i - 1) + N'.c1';&lt;/p&gt;
&lt;p&gt;	SET @i = @i + 1;&lt;/p&gt;
&lt;p&gt;END&lt;/p&gt;
&lt;p&gt;EXEC sp_executesql @sql;&lt;/p&gt;
&lt;p&gt;GO&lt;/p&gt;
&lt;p&gt;--&lt;/p&gt;
&lt;p&gt;AMB&lt;/p&gt;
</description></item><item><title>re: "Planning" for Success (A Month of Activity Monitoring, Part 11 of 30)</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2011/04/11/planning-for-success-a-month-of-activity-monitoring-part-11-of-30.aspx#34828</link><pubDate>Tue, 12 Apr 2011 13:43:28 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:34828</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Alejandro, that's the problem to which I was referring. But Northwind? Come on man! It's 2011 :-)&lt;/p&gt;
</description></item><item><title>re: "Planning" for Success (A Month of Activity Monitoring, Part 11 of 30)</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2011/04/11/planning-for-success-a-month-of-activity-monitoring-part-11-of-30.aspx#34834</link><pubDate>Tue, 12 Apr 2011 14:33:49 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:34834</guid><dc:creator>Alejandro Mesa</dc:creator><description>&lt;p&gt;LOL!!!&lt;/p&gt;
</description></item><item><title>re: "Planning" for Success (A Month of Activity Monitoring, Part 11 of 30)</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2011/04/11/planning-for-success-a-month-of-activity-monitoring-part-11-of-30.aspx#34880</link><pubDate>Thu, 14 Apr 2011 02:03:31 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:34880</guid><dc:creator>Michael Codanti</dc:creator><description>&lt;p&gt;I get an error message about exceeding the nested levels, I don't get NULL in the query_plan column. And while I have a query that does it I can't post it.&lt;/p&gt;
</description></item><item><title>re: "Planning" for Success (A Month of Activity Monitoring, Part 11 of 30)</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2011/04/11/planning-for-success-a-month-of-activity-monitoring-part-11-of-30.aspx#34883</link><pubDate>Thu, 14 Apr 2011 02:31:48 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:34883</guid><dc:creator>Alejandro Mesa</dc:creator><description>&lt;p&gt;Michael,&lt;/p&gt;
&lt;p&gt;What version and service pack are you working with?&lt;/p&gt;
&lt;p&gt;--&lt;/p&gt;
&lt;p&gt;AMB&lt;/p&gt;
</description></item><item><title>re: "Planning" for Success (A Month of Activity Monitoring, Part 11 of 30)</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2011/04/11/planning-for-success-a-month-of-activity-monitoring-part-11-of-30.aspx#34884</link><pubDate>Thu, 14 Apr 2011 02:42:56 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:34884</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Michael,&lt;/p&gt;
&lt;p&gt;Are you running a really old version of Who is Active, or have you modified the logic in some way? (You mentioned doing so in some prior communication we had.) I've had exception handling in there for quite some time so it should be impossible to receive the error unless something has been messed with or there is a bug in SQL Server (perhaps Alejandro knows of one that he's alluding to). &lt;/p&gt;
&lt;p&gt;The follow up post to this one (#12) contains a query in the Homework section that exceeds the nesting level. I just tested it and it behaves as intended; the exception is caught and [query_plan] is NULL. Give it a try with an unmodified recent build of Who is Active and see if you can repro the issue.&lt;/p&gt;</description></item><item><title>The Almighty Transaction (A Month of Activity Monitoring, Part 12 of 30)</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2011/04/11/planning-for-success-a-month-of-activity-monitoring-part-11-of-30.aspx#34885</link><pubDate>Thu, 14 Apr 2011 02:43:54 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:34885</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;This post is part 12 of a 30-part series about the Who is Active stored procedure. A new post will run&lt;/p&gt;
</description></item><item><title>re: "Planning" for Success (A Month of Activity Monitoring, Part 11 of 30)</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2011/04/11/planning-for-success-a-month-of-activity-monitoring-part-11-of-30.aspx#34886</link><pubDate>Thu, 14 Apr 2011 02:55:12 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:34886</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Michael,&lt;/p&gt;
&lt;p&gt;I just re-read your message, and ran another test on this end. Are you saying that you get an error message in the column itself? If so, that's a different story. It's expected behavior, that I should probably include in this post or a followup. The query plan functions won't always throw an error for the exception handling to catch. If they don't, the [query_plan] column winds up NULL. If they do, the error is reported in that column in an XML fragment. This is done so that the user can get some information about why no plan has been shown. (I don't ever like to swallow errors.)&lt;/p&gt;
&lt;p&gt;Please let me know what, exactly, you're seeing.&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Adam&lt;/p&gt;
</description></item><item><title>re: "Planning" for Success (A Month of Activity Monitoring, Part 11 of 30)</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2011/04/11/planning-for-success-a-month-of-activity-monitoring-part-11-of-30.aspx#34910</link><pubDate>Fri, 15 Apr 2011 04:19:05 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:34910</guid><dc:creator>Michael Codanti</dc:creator><description>&lt;p&gt;Alejandro,&lt;/p&gt;
&lt;p&gt;I am running SQL Server 2008 R2 CU6.&lt;/p&gt;
&lt;p&gt;Adam,&lt;/p&gt;
&lt;p&gt;Yes, I am seeing the error message, in XML form, in the query_plan column. (So Who Is Active is running fine and doing exactly what it is supposed to.) But I hate seeing that error, as it is usually a plan I want/need to look at.&lt;/p&gt;
</description></item><item><title>re: "Planning" for Success (A Month of Activity Monitoring, Part 11 of 30)</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2011/04/11/planning-for-success-a-month-of-activity-monitoring-part-11-of-30.aspx#34911</link><pubDate>Fri, 15 Apr 2011 04:34:17 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:34911</guid><dc:creator>Michael Codanti</dc:creator><description>&lt;p&gt;Adam,&lt;/p&gt;
&lt;p&gt;I just ran the query from day #12 when running Who Is Active I got this in the query_plan column:&lt;/p&gt;
&lt;p&gt;&amp;lt;error message=&amp;quot;XML datatype instance has too many levels of nested nodes. Maximum allowed depth is 128 levels.&amp;quot; /&amp;gt;&lt;/p&gt;
&lt;p&gt;Note: The only way I could get it was to modify the query so that it got blocked... (Since query_plan is never populated for sleeping spids.)&lt;/p&gt;
</description></item><item><title>re: "Planning" for Success (A Month of Activity Monitoring, Part 11 of 30)</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2011/04/11/planning-for-success-a-month-of-activity-monitoring-part-11-of-30.aspx#34924</link><pubDate>Fri, 15 Apr 2011 14:43:41 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:34924</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Hi Michael,&lt;/p&gt;
&lt;p&gt;I agree, it would be much nicer to see the plan. Unfortunately, there's not much that can be done about the nesting limitation until Microsoft fixes it. (FYI it is an arbitrary limitation set to avoid problems with XML indexing -- and IMHO it's completely unnecessary, especially given how few people use XML indexing.) I may be able to bring back the plan in the additional_info column or something along those lines, but it would be quite a hassle to have to copy and paste it, save it to a .SQLPLAN file, etc. I'm not sure whether it's worth the effort to implement that.&lt;/p&gt;
&lt;p&gt;--Adam&lt;/p&gt;
</description></item><item><title>Twenty Nine Days of Activity Monitoring (A Month of Activity Monitoring, Part 30 of 30)</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2011/04/11/planning-for-success-a-month-of-activity-monitoring-part-11-of-30.aspx#35339</link><pubDate>Sat, 30 Apr 2011 15:45:08 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:35339</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;This post is part 30 of a 30-part series about the Who is Active stored procedure. A new post will run&lt;/p&gt;
</description></item><item><title>re: "Planning" for Success (A Month of Activity Monitoring, Part 11 of 30)</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2011/04/11/planning-for-success-a-month-of-activity-monitoring-part-11-of-30.aspx#39759</link><pubDate>Fri, 11 Nov 2011 01:14:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:39759</guid><dc:creator>DBAGeek</dc:creator><description>&lt;p&gt;Hello Adam,&lt;/p&gt;
&lt;p&gt;Great series and perfect procedure, must have for every DBA :-)&lt;/p&gt;
&lt;p&gt;ps.&lt;/p&gt;
&lt;p&gt;why you don't use sys.dm_exec_query_plan to return compiled plan ?&lt;/p&gt;
</description></item><item><title>re: "Planning" for Success (A Month of Activity Monitoring, Part 11 of 30)</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2011/04/11/planning-for-success-a-month-of-activity-monitoring-part-11-of-30.aspx#39770</link><pubDate>Fri, 11 Nov 2011 15:31:15 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:39770</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Hi DBAGeek,&lt;/p&gt;
&lt;p&gt;The sys.dm_exec_text_query_plan function is much more flexible--it includes the ability to pass statement start and end offsets, and the ability to get back plans that exceed XML nesting depth limitations. Without these two features the plan collection facilities of Who is Active would be quite limited.&lt;/p&gt;
&lt;p&gt;--Adam&lt;/p&gt;
</description></item></channel></rss>