<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>StraightPath Consulting&#039;s SQL Server Blog &#187; SQL Server 2005</title>
	<atom:link href="http://www.straightpathsql.com/archives/category/sql-server-2005/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.straightpathsql.com</link>
	<description>Mike Walsh&#039;s Thoughts on SQL Server, Professional Development and Life</description>
	<lastBuildDate>Thu, 29 Jul 2010 12:11:46 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Good use for WITH RECOMPILE</title>
		<link>http://www.straightpathsql.com/archives/2008/12/good-use-for-with-recompile/</link>
		<comments>http://www.straightpathsql.com/archives/2008/12/good-use-for-with-recompile/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 05:22:38 +0000</pubDate>
		<dc:creator>Mike Walsh</dc:creator>
				<category><![CDATA[Performance]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[Syndicate]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Recompile]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://straightpathsql.mikewalshonline.com/?p=14</guid>
		<description><![CDATA[

Haven&#8217;t looked into all of the details underneath but at the surface probably a good reminder of where WITH RECOMPILE can be helpful&#8230;
Using SQL Server Reporting Services, a workaround was used (this is the part I want to look into more) to basically get a blank report showing when a user first links to a [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_blue" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.straightpathsql.com%252Farchives%252F2008%252F12%252Fgood-use-for-with-recompile%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Good%20use%20for%20WITH%20RECOMPILE%20%23%22%20%7D);"></div>
<p>Haven&#8217;t looked into all of the details underneath but at the surface probably a good reminder of where WITH RECOMPILE can be helpful&#8230;</p>
<p>Using SQL Server Reporting Services, a workaround was used (this is the part I want to look into more) to basically get a blank report showing when a user first links to a report until they change parameters and run the report themselves. So this first execution gives an false year/month to search back until (190001). The procedure behind this report looks for any &#8220;invalid&#8221; (per the business rules that means less than 195001) date and issues a &#8220;RETURN&#8221;, returning control to the color.</p>
<p>The problem was picked up during an execution after a restart. When the Reporting Services query ran asking for 200809 it ran until it timed out, no results coming back. When the query was executed for 200809 from SQL Server Management Studio, it came back in about 30 seconds.</p>
<p>Two issues at play here 1.) The sessions are getting different query plans (topic for another post.. various reasons this can happen even for the same proc) and 2.) The query plan used by SSRS is being compiled first with the first time an SSRS session ever executes the query (190001).</p>
<p>This can be verified by looking at the xml showplan for the execution and seeing what the parameter is compiled for.</p>
<p>In this case, adding WITH RECOMPILE to the stored procedure before the AS, tells SQL to recalculate the plan at each execution instead of cache and reuse a plan for every execution. This resulted in the reporting services query coming back in 35 seconds as opposed to timing out.</p>
<p>Obviously longer term solutions include figuring out why this was designed this way and looking at other possible options. Normally WITH RECOMPILE is best when working with queries that are called with dramatically different parameter values each time that cause differences in the way the plan is figured.</p>
<p>For another post, we&#8217;ll talk about how you can have the same procedure use different plans even for the same server and how to minimize/avoid that.</p>

<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.straightpathsql.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.straightpathsql.com/archives/2008/12/good-use-for-with-recompile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rolling Back (or is it??)</title>
		<link>http://www.straightpathsql.com/archives/2008/12/rolling-back-or-is-it/</link>
		<comments>http://www.straightpathsql.com/archives/2008/12/rolling-back-or-is-it/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 04:37:24 +0000</pubDate>
		<dc:creator>Mike Walsh</dc:creator>
				<category><![CDATA[DMV]]></category>
		<category><![CDATA[Linked Server]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[Syndicate]]></category>
		<category><![CDATA[Troubleshooting]]></category>
		<category><![CDATA[Interesting]]></category>
		<category><![CDATA[Rollback never finishes]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://straightpathsql.mikewalshonline.com/?p=13</guid>
		<description><![CDATA[

Interesting Issue Today/Yesterday -
A query was using a linked server to grab data from DB2 via an ODBC connection. Normal execution time is about 15 minutes. This had run on for at least 7 hours when it was decided to kill it, appeared to be doing nothing but causing blocks (due to Intent Shared and [...]]]></description>
			<content:encoded><![CDATA[
<div class="topsy_widget_data topsy_theme_blue" style="float: right;margin-left: 0.75em; background: url(data:,%7B%20%22url%22%3A%20%22http%253A%252F%252Fwww.straightpathsql.com%252Farchives%252F2008%252F12%252Frolling-back-or-is-it%252F%22%2C%20%22style%22%3A%20%22big%22%2C%20%22title%22%3A%20%22Rolling%20Back%20%28or%20is%20it%3F%3F%29%20%23%22%20%7D);"></div>
<p>Interesting Issue Today/Yesterday -</p>
<p>A query was using a linked server to grab data from DB2 via an ODBC connection. Normal execution time is about 15 minutes. This had run on for at least 7 hours when it was decided to kill it, appeared to be doing nothing but causing blocks (due to Intent Shared and Intent Exclusive locks preparing to do an update if the data ever came back).</p>
<p>Waited a few hours, still didn&#8217;t die so we figured we could wait, if it took 7 hours prior to killing, rollback could potentially take at least that long if not much longer.</p>
<p>Came back today and it was still running.. By this time now about 30 hours since initial query executed and 23 hours after KILL issued. Process state was rollback.</p>
<p>When I looked at the stats for the session (SELECT * FROM SYS.DM_EXEC_REQUESTS), I noticed the CPU counter incrementing so it was at least thinking about doing something if not in the middle of doing anything. Rollback just didn&#8217;t make sense to be so long knowing what the query did.</p>
<p>Left me with few options though:</p>
<ul>
<li>Restart SQL Service &#8211; risk this database coming back up in recovery and not available at all</li>
<li>Something horrible and drastic &#8211; Not a great troubleshooting methodology so put this out of my mind as a serious option&#8230; But rebuilding the log would probably have &#8220;solved&#8221; the immediate issue while potentially leaving a database in a transactionally inconsistent state</li>
<li>Wait and hope &#8211; Safest but due to timelines of necessary processing was not a truly viable option.</li>
</ul>
<p>So I called MS Support. Great assistance (as normal from SQL support) but confirmed what I was thinking: no help. They had no tools to undo this and had the three options I had above at first. They came back with a 4th I hadn&#8217;t considered:</p>
<ul>
<li>Take a full backup, restore it with a new name, verify everything appears right and cut over to that database (change name of DB with rollback operation, change name again of the restored DB).</li>
</ul>
<p>The escalatio engineer had a good point: when you take the full backup that transaction that is rolling back was never comitted and would not be grabbed by that backup so the restore will leave a consistent and ready database.</p>
<p>Before going that route, I searched some more on the issue and after looking at what it was doing (again not a lot of work) and some common repeats of this issue (when using a linked server some folks reported hung queries that on rollback after kill would be in rollback state for as long as 7 days before they gave up and restarted). So I decided to take two of the options to mitigate the risk. Feeling confident that a restart would probably be the end all I:</p>
<ol>
<li>Backed up the offending database to use the 4th option from MSFT PSS if need be</li>
<li>Went through the change notification process for the service recycle</li>
<li>Restarted SQL Service</li>
<li>Held my breath and</li>
<li>Presto! The database recovered instantly in a good state</li>
<li>DBCC CHECKDB run to ensure DB free of issues that would be picked up here</li>
<li>Had users query data to ensure it seemed right</li>
<li>Back in business</li>
</ol>
<p>In keeping with the thought of mitigation, I will be looking into more behind the why, investigate the ODBC drivers and versions being used here, attempt to recreate the same issue in a different environment and remember this blog post is here if I need it&#8230;</p>

<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save"><img src="http://www.straightpathsql.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.straightpathsql.com/archives/2008/12/rolling-back-or-is-it/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
