<?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>SQL in the Wild &#187; Community</title>
	<atom:link href="http://sqlinthewild.co.za/index.php/category/community/feed/" rel="self" type="application/rss+xml" />
	<link>http://sqlinthewild.co.za</link>
	<description>A discussion on SQL Server</description>
	<lastBuildDate>Sun, 01 Jan 2012 14:30:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>PASS Summit Session Votes</title>
		<link>http://sqlinthewild.co.za/index.php/2011/05/18/pass-summit-session-votes/</link>
		<comments>http://sqlinthewild.co.za/index.php/2011/05/18/pass-summit-session-votes/#comments</comments>
		<pubDate>Wed, 18 May 2011 14:30:00 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Syndication]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=1047</guid>
		<description><![CDATA[I blogged a week ago about the sessions that I submitted for the PASS Summit this year. At the point that I scheduled the post I hadn&#8217;t seen the announcement from PASS, hence a second post on the same topic. This year, you can vote for sessions that you want to see. How much influence [...]]]></description>
			<content:encoded><![CDATA[<p>I <a href="http://sqlinthewild.co.za/index.php/2011/05/10/pass-summit-abstracts/">blogged a week ago</a> about the sessions that I submitted for the <a href="http://www.sqlpass.org/summit/2011/">PASS Summit</a> this year. At the point that I scheduled the post I hadn&#8217;t seen the announcement from PASS, hence a second post on the same topic.</p>
<p>This year, you can vote for sessions that you want to see. How much influence this will have over the Program Committee isn&#8217;t defined anywhere, but anything is better than nothing.</p>
<p>Voting closes on the 20th May (Friday), so if you have any interest in what gets presented at PASS Summit this year, go over to the <a href="http://www.sqlpass.org/summit/2011/Speakers/SessionPreferencing.aspx?p=62&amp;preferred=False">speaker preference survey</a> and vote.</p>
<p>Oh, and to make things easier, if you want to vote for any of my sessions, they&#8217;re <a href="http://www.sqlpass.org/summit/2011/Speakers/SessionPreferencing.aspx?spid=309&amp;p=1&amp;preferred=False">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2011/05/18/pass-summit-session-votes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pass summit abstracts</title>
		<link>http://sqlinthewild.co.za/index.php/2011/05/10/pass-summit-abstracts/</link>
		<comments>http://sqlinthewild.co.za/index.php/2011/05/10/pass-summit-abstracts/#comments</comments>
		<pubDate>Tue, 10 May 2011 14:30:27 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[Conferences]]></category>
		<category><![CDATA[Syndication]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=1011</guid>
		<description><![CDATA[I missed the Pass summit last November for a number of reasons, but I&#8217;m hoping I can attend this year. Given that, I submitted a number of abstracts for consideration. The limits on number were as follows: Up to 4 abstracts for regular, spotlight or half-day sessions (ie main conference sessions) plus, providing some requirements [...]]]></description>
			<content:encoded><![CDATA[<p>I missed the Pass summit last November for a number of reasons, but I&#8217;m hoping I can attend this year. Given that, I submitted a number of abstracts for consideration.</p>
<p>The limits on number were as follows: Up to 4 abstracts for regular, spotlight or half-day sessions (ie main conference sessions) plus, providing some <a href="http://www.sqlpass.org/Community/SpeakerResource/PrePostConferencePrerequisites.aspx">requirements</a> are met, up to 2 abstracts for pre-con sessions.</p>
<p>I submitted five abstracts, four were ones I&#8217;ve been thinking about for some time, the last was a <a href="http://www.allenkinsel.com/archive/2011/05/further-promoting-the-growth-of-speakers/">last minute surprise</a>.</p>
<h3>Bad plan! Sit!</h3>
<blockquote><p>Bad execution plans are the bane of database performance everywhere they crop up. But what is a bad execution plan? How do you identify one in your system and, once identified how do you go about fixing it?</p>
<p>In this top-rated session from the 24 Hours of PASS we’ll look at some things that make a plan ‘bad’, how you might detect such plans and various methods of fixing the problem, both immediately and long-term.</p></blockquote>
<p>I wasn&#8217;t planning on submitting this one to be honest. It&#8217;s one I did for the <a href="http://www.sqlpass.org/24hours/spring2011/default.aspx">24 hours of Pass back in February</a>, and I didn&#8217;t think it appropriate to redo at the Summit the same year. Some people at Pass disagreed with me on that. The session was one of the top 3 from 24 hours of Pass and as such got a guaranteed slot at Pass summit, and a chance for a Spotlight slot.</p>
<h3>Is that a parameter I smell?</h3>
<blockquote><p>All too often a forum post on erratic query performance is met with a reply ‘Oh, it’s parameter sniffing. You can fix it with .’ The problem with that answer, even if it has identified the cause, is that it’s only part true. Parameter sniffing is not simply a problem that needs fixing, it&#8217;s an essential part of well-performing queries. In most cases.</p>
<p>Come to this session to learn what Parameter Sniffing really is and why it’s a good thing, most of the time. Learn how to identify the scenarios where it’s not good, why a feature that is supposed to improve query performance sometimes degrades it, and what your options are for resolving the problems when they do occur.</p></blockquote>
<h3>Performance improvements in 60 min or less. Guaranteed</h3>
<blockquote><p>The system is slow, users cry<br />
It&#8217;s impacting our bottom line<br />
In meetings the curses fly<br />
The situation is far from fine</p>
<p>While up on the IT floor<br />
The DBA tears his hair<br />
He&#8217;ll soon be shown the door<br />
If he cannot the performance repair,</p>
<p>It often seems, from looking at forum posts and client requests, that the steady-state of databases is &#8216;too slow&#8217; and all too often the people who are tasked with resolving performance problems are overwhelmed by the shear scope of the problem, and aren&#8217;t really sure where to start.</p>
<p>In this demo-heavy session, we&#8217;ll look at a fictional company&#8217;s database and website and work through finding the worst offenders in terms of poor performance, identifying the causes of the problems and at least starting to get the queries to perform better and the users to stop phoning and complaining.</p></blockquote>
<p>Yes, part of the abstract is written in verse. It&#8217;s something I was threatening to do since last year, and I decided that it shouldn&#8217;t harm my chances, much.</p>
<h3>Dos and don’ts of database corruption</h3>
<blockquote><p>Database corruption is one of the worst things you can encounter as a DBA. It can result in downtime, data loss, and unhappy users. What’s scary about corruption is that it can strike out of the blue and with no warning. If maintenance is not being done regularly on the database it&#8217;s easy for corruption to go unnoticed until it&#8217;s too late to repair without losing data.<br />
In this session we’ll look at</p>
<ul>
<li>Easy maintenance operations you should be running right now to ensure the fastest possible identification and resolution of corruption</li>
<li>Best practices for handling a database that you suspect may be corrupted</li>
<li>Common actions that can worsen the problem.</li>
<li>Appropriate steps to take and methods of recovery</li>
</ul>
</blockquote>
<p>I did this session initially for Quest, for their Pain of the Week webcast back in February. I enjoyed doing it a lot, and it got some good feedback, so I decided to submit it for Summit as a contrast to my usual performance-related presentations.</p>
<h3>All about Execution Plans</h3>
<p>Last, but far from least&#8230;</p>
<p>Grant Fritchey (<a href="http://www.scarydba.com/">blog</a> | <a href="https://twitter.com/#!/GFritchey">twitter</a>) and I submitted a join pre-con session on execution  plans. This is an area Grant is a well-known expert on, having written a  book on it, and we&#8217;re hoping that we&#8217;ll be given the chance to devote a  full day to this topic.</p>
<blockquote><p>The key to understanding how SQL Server is processing your queries is the execution plan.</p>
<p>This full day session focuses on the execution plan. We will start right at the beginning and talk about the compile process. We’ll also go over how, and more importantly, why, plans are stored in cache and how they are removed.</p>
<p>We’ll spend time exploring the key differences between actual and estimated plans, and why those descriptions are more than a little misleading. We’ll also show you assorted methods to obtain a query&#8217;s execution plan and what the differences and tradeoffs of each are.</p>
<p>A full day class on execution plans would not be complete without spending time learning to reading them. You’ll learn where to find useful information in execution plans, what the common operators are and how to decipher the sometimes cryptic messages the plans are sending to you. We&#8217;ll also debunk some myths surrounding query operators and execution plans.</p>
<p>All of this is meant to further your understanding of how queries work in order to improve the queries you’re responsible for. With this in mind, we’ll show how you can use execution plans to tune queries. All of the information presented will be taken from real world examples. We’ll build on the information through the day so that at the end, after following us through multiple examples at your own computer, you’ll have a stronger understanding of how to read, interpret and actually use execution plans in your day-to-day job.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2011/05/10/pass-summit-abstracts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sql Saturday #83</title>
		<link>http://sqlinthewild.co.za/index.php/2011/05/09/sql-saturday-83/</link>
		<comments>http://sqlinthewild.co.za/index.php/2011/05/09/sql-saturday-83/#comments</comments>
		<pubDate>Mon, 09 May 2011 14:30:00 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[Syndication]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=1014</guid>
		<description><![CDATA[Frikkie Bosch opened the day with a short keynote giving an overview of Denali, talking mostly from a marketing point of view about the major features coming in the next version. The virtual sessions were very popular, we don&#8217;t get many good international speakers down in our part of the world and the opportunity to [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/05/image.png"><img style="background-image: none; margin: 5px 10px 6px 1px; padding-left: 0px; padding-right: 0px; display: inline; float: left; padding-top: 0px; border-width: 0px;" title="image" src="http://sqlinthewild.co.za/wp-content/uploads/2011/05/image_thumb.png" border="0" alt="image" width="240" height="98" align="left" /></a>Frikkie Bosch opened the day with a short keynote giving an overview of Denali, talking mostly from a marketing point of view about the major features coming in the next version.</p>
<p>The virtual sessions were very popular, we don&#8217;t get many good international speakers down in our part of the world and the opportunity to listen to some new speakers was well received.</p>
<p>Benjamin kicked off the virtual sessions with his &#8217;10 query optimiser topics for better performance&#8217;. He covered parameter sniffing, showing how the optimiser estimates row counts based on statistics and the sniffed value of parameters, cardinality estimation errors (poor stats or missing statistics) and scalar expressions (hard for the optimiser to guess rows affected). Also discussed were the missing index DMVs and DTA (the database tuning advisor)</p>
<p>My session on poorly performing SQL went very well. It&#8217;s a session I&#8217;ve done several times and enjoy thoroughly every time. The audience was great, lots of good questions, good comments and good fun. I ran a bit short on time to discuss the fixes for the multiple execution path problem, so I&#8217;ll just direct anyone reading to a blog post on it: <a href="http://sqlinthewild.co.za/index.php/2009/09/15/multiple-execution-paths/">http://sqlinthewild.co.za/index.php/2009/09/15/multiple-execution-paths/</a></p>
<p>Big thanks to all the organisers, all the speakers, all the attendees. Special thanks to the international speakers who either stayed up late or woke early to give their sessions.</p>
<p><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/05/SQLSat83-1.jpg"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="SQLSat83-1" src="http://sqlinthewild.co.za/wp-content/uploads/2011/05/SQLSat83-1_thumb.jpg" border="0" alt="SQLSat83-1" width="364" height="244" /></a></p>
<p><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/05/SQLSat83-2.jpg"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="SQLSat83-2" src="http://sqlinthewild.co.za/wp-content/uploads/2011/05/SQLSat83-2_thumb.jpg" border="0" alt="SQLSat83-2" width="364" height="244" /></a></p>
<p><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/05/SQLSat83-3.jpg"><img style="background-image: none; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="SQLSat83-3" src="http://sqlinthewild.co.za/wp-content/uploads/2011/05/SQLSat83-3_thumb.jpg" border="0" alt="SQLSat83-3" width="164" height="244" /></a> <a href="http://sqlinthewild.co.za/wp-content/uploads/2011/05/SQLSat83-4.jpg"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="SQLSat83-4" src="http://sqlinthewild.co.za/wp-content/uploads/2011/05/SQLSat83-4_thumb.jpg" border="0" alt="SQLSat83-4" width="184" height="244" /></a></p>
<p><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/05/SQLSat83-5.jpg"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border-width: 0px;" title="SQLSat83-5" src="http://sqlinthewild.co.za/wp-content/uploads/2011/05/SQLSat83-5_thumb.jpg" border="0" alt="SQLSat83-5" width="164" height="244" /></a> <a href="http://sqlinthewild.co.za/wp-content/uploads/2011/05/SQLSat83-6.jpg"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="SQLSat83-6" src="http://sqlinthewild.co.za/wp-content/uploads/2011/05/SQLSat83-6_thumb.jpg" border="0" alt="SQLSat83-6" width="164" height="244" /></a></p>
<p><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/05/SQLSat83-7.jpg"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="SQLSat83-7" src="http://sqlinthewild.co.za/wp-content/uploads/2011/05/SQLSat83-7_thumb.jpg" border="0" alt="SQLSat83-7" width="364" height="244" /></a></p>
<p><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/05/SQLSat83-8.jpg"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="SQLSat83-8" src="http://sqlinthewild.co.za/wp-content/uploads/2011/05/SQLSat83-8_thumb.jpg" border="0" alt="SQLSat83-8" width="364" height="244" /></a></p>
<p><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/05/SQLSat83-9.jpg"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="SQLSat83-9" src="http://sqlinthewild.co.za/wp-content/uploads/2011/05/SQLSat83-9_thumb.jpg" border="0" alt="SQLSat83-9" width="164" height="244" /></a></p>
<p><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/05/SQLSat83-10.jpg"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="SQLSat83-10" src="http://sqlinthewild.co.za/wp-content/uploads/2011/05/SQLSat83-10_thumb.jpg" border="0" alt="SQLSat83-10" width="364" height="244" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2011/05/09/sql-saturday-83/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Q &amp; A from 24 Hours of PASS session</title>
		<link>http://sqlinthewild.co.za/index.php/2011/03/18/q-a-from-24-hours-of-pass-session/</link>
		<comments>http://sqlinthewild.co.za/index.php/2011/03/18/q-a-from-24-hours-of-pass-session/#comments</comments>
		<pubDate>Fri, 18 Mar 2011 14:30:00 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Syndication]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=962</guid>
		<description><![CDATA[Earlier this week I took part in the 24 Hours of PASS live webcast event. There were far more questions at the end of the presentation than what I could answer online, so the answers to the rest are given here. (I have edited some of the questions for spelling, grammar and readability). My slide [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier this week I took part in the <a href="http://www.sqlpass.org/24hours/spring2011/default.aspx">24 Hours of PASS</a> live webcast event. There were far more questions at the end of the presentation than what I could answer online, so the answers to the rest are given here. (I have edited some of the questions for spelling, grammar and readability). My slide deck and demos I was using are linked at the end. I&#8217;m not including a backup of the DB, as it&#8217;s 60MB. The schema is there, as is a SQL Data Generator project.</p>
<p><span style="color: #bd934f;">Q: Is the problem here that addition of checking if the variable is null? (This was related to catch-all queries. )</span></p>
<p>No, not specifically. The problem is the query pattern of &lt;column&gt; = &lt;parameter&gt; <span> </span>OR &lt;parameter&gt; <span> </span>= &lt;constant&gt; . It&#8217;s not specific to the case where that constant is NULL, though that is the more common form that I&#8217;ve seen.</p>
<p><span style="color: #bd934f;">Q: What are the good alternatives for catch-all queries?</span></p>
<p>If you are on SQL 2008 SP2 or later you can add OPTION(RECOMPILE) to the catch all query and get a plan that is optimal for each particular set of parameters.</p>
<p>On SQL 2005 and earlier, even with a recompile you would not get an optimal plan. This is because the optimizer was required to create a plan that was safe for reuse, even if it was never going to be reused.</p>
<p>On builds on SQL 2008 prior to SP1, the use of OPTION (RECOMPILE) worked, but there was a bug related to that which could produce inaccurate results, so use with caution.</p>
<p>On builds of SQL 2008 between SP1 and SP2 (or SP1 CU5), the behaviour of a catch-all with recompile was the same as for SQL 2005</p>
<p>If you&#8217;re using SQL 2005 (or horrors SQL 2000) or a build of SQL 2008 that did not have the recompile options working, you can use dynamic SQL (there are advantages to dynamic SQL even on the latest builds of SQL 2008). Use the parameters passed to build up a string that just filtered on the columns for which parameters were passed, then use sp_executesql to run the parameterised dynamic SQL statement.</p>
<p>Details are available on my blog &#8211; <a title="http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/" href="http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/">http://sqlinthewild.co.za/index.php/2009/03/19/catch-all-queries/</a></p>
<p><span style="color: #bd934f;">Q: If you don&#8217;t have access to run the execution plan, but have to have DBAs run it for you, is there a good way to have it captured?</span></p>
<p>Absolutely. In SQL 2005 and above, the execution plan is an XML document. You can save the plan as a .sqlplan file. That file can then be copied, emailed, etc. You can open it in management studio and SSMS will display the graphical plan.</p>
<p><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/03/SaveExecPlan.png"><img class="size-medium wp-image-969 alignnone" title="SaveExecPlan" src="http://sqlinthewild.co.za/wp-content/uploads/2011/03/SaveExecPlan-300x140.png" alt="" width="300" height="140" /></a></p>
<p>Or, you could download <a href="http://www.sqlsentry.com/plan-explorer/sql-server-query-view.asp">Plan Explorer</a> and open the plan in that.</p>
<p><span style="color: #bd934f;"><span id="more-962"></span>Q: Can you demo an example of fixing parameter sniffing using local variables?</span></p>
<pre class="brush: sql; title: ; notranslate">CREATE PROCEDURE OrdersByCountry (@Country CHAR(2))
AS
 DECLARE @CountryInner CHAR(2)
 SET @CountryInner = @Country
 SELECT
  OrderDate ,
  DestinationCountry ,
  SUM(ItemPrice) AS totalPrice ,
  SUM(QuantityPurchased) AS totalPurchased
 FROM dbo.BookOrders AS bo
  INNER JOIN dbo.OrderDetails AS od ON bo.OrderID = od.OrderID
 WHERE DestinationCountry = @CountryInner
 GROUP BY OrderDate, DestinationCountry
GO</pre>
<p>When run, this has a constant execution plan, no matter what parameter values it&#8217;s called with the first time.</p>
<p>With that, the exec plans are the same no matter what parameter value is passed. It&#8217;s not necessarily the best plan (for smaller row counts it is not), but it is consistent.</p>
<p><a href="http://sqlinthewild.co.za/wp-content/uploads/2011/03/ParamSniffing.png"><img style="background-image: none; padding-left: 0px; padding-right: 0px; display: inline; padding-top: 0px; border: 0px;" title="ParamSniffing" src="http://sqlinthewild.co.za/wp-content/uploads/2011/03/ParamSniffing_thumb.png" border="0" alt="ParamSniffing" width="484" height="377" /></a></p>
<p><span style="color: #bd934f;">Q: Doesn&#8217;t recreating indexes update statistics?</span></p>
<p>Rebuilding or dropping and recreating an index updates it&#8217;s associated statistics with full scan. Reorganizing the index does not. Neither will affect the column statistics, statistics that are not associated with an index.</p>
<p><span style="color: #bd934f;">Q: On fixing parameter sniffing, your suggestion that we should insure each possible parameter type gets its own plan seems counterintuitive to the avoid &#8216;Bad query patterns: multiple execution paths&#8217; advice. I think I&#8217;m missing something&#8230; can you clarify?</span></p>
<p>Not necessarily each possible different parameter types, just those with vastly different prevalences in the table. So going back to the book order table that I was using, it may be that most of the rows in table are for countries US, UK and AU (Australia). So we may want to have one stored procedure that&#8217;s used for those countries and another for everyone else (on the assumption that, for whatever reason, everyone else makes up a very small percentage of the table). So I might do something like this.</p>
<pre class="brush: sql; title: ; notranslate">CREATE PROCEDURE OrdersByCountryUSUKAU (@Country CHAR(2))
AS
 SELECT
  OrderDate ,
  DestinationCountry ,
  SUM(ItemPrice) AS totalPrice ,
  SUM(QuantityPurchased) AS totalPurchased
 FROM dbo.BookOrders AS bo
  INNER JOIN dbo.OrderDetails AS od ON bo.OrderID = od.OrderID
 WHERE DestinationCountry = @Country
 GROUP BY OrderDate, DestinationCountry
&lt;pre&gt;GO&lt;/pre&gt;
CREATE PROCEDURE OrdersByCountryOther (@Country CHAR(2))
AS
&lt;pre&gt; SELECT
  OrderDate ,
  DestinationCountry ,
  SUM(ItemPrice) AS totalPrice ,
  SUM(QuantityPurchased) AS totalPurchased
 FROM dbo.BookOrders AS bo
  INNER JOIN dbo.OrderDetails AS od ON bo.OrderID = od.OrderID
 WHERE DestinationCountry = @Country
 GROUP BY OrderDate, DestinationCountry
GO&lt;/pre&gt;
CREATE PROCEDURE OrdersByCountry (@Country CHAR(2))
AS
IF @Country IN ('UK','US','AU')
EXEC OrdersByCountryUSUKAU @Country
ELSE
EXEC OrdersByCountryOther @Country
GO</pre>
<p>Now this doesn&#8217;t cause the kind of problems seen with multiple execution paths because what is in the branches here are separate stored procedures, and each will have it&#8217;s own individual execution plan.</p>
<p>This is not necessarily the best solution, it&#8217;s not something I would do normally. It increases the amount of code in the database and now any changes to the book order stored procedure have to be made in two places. If that particular procedure is such that it absolutely must execute as optimally as possible no matter what (and we don&#8217;t want the overhead of constant recompiles), it is an option</p>
<p><span style="color: #bd934f;">Q: Any tips for improving quality of statistics for very large tables when they are already computed with a full scan? Are filtered indexes the only option?<br />
</span><br />
Filtered indexes or filtered statistics. The 250 steps for the statistics histogram can&#8217;t be configured. On larger tables that may be inadequate and the optimizer may think there are fewer rows for some value than there are because it has inadequate (rather than out-dated) statistics.</p>
<p>If you do chose to use filtered indexes or statistics, you need to update the statistics manually. With filtered statistics the 20% threshold for invalidating statistics is 20% of the table, not 20% of the filtered portion of the table. So you could have filtered statistics on just 5% of the table and you would still have to wait for 20% of the entire table to be updated before those stats would be invalidated.</p>
<p><span style="color: #bd934f;">Q: How efficiently do execution plans work with temp tables or table variables?</span></p>
<p>Same as for permanent tables. With table variables, because there are no statistics, row count estimations are often incorrect. It&#8217;s something that needs to be taken into account when using table variables.</p>
<p>With temp tables, if you want to use SSMS&#8217;s estimated execution plan feature, you need to create the temp table first or you&#8217;ll get an error saying that it doesn&#8217;t exist.</p>
<p><span style="color: #bd934f;">Q: I have been using local variable and substitute the passed variables to local variables to avoid parameter sniffing, is that good thing to do?</span></p>
<p>It&#8217;s one of the ways to fix parameter sniffing. I wouldn&#8217;t do it as default in every stored procedure, without parameter sniffing (which please remember is a good thing most of the time) you may be getting sub-optimal execution plans. For procedures that are prone to problems cause by parameter sniffing, sure.</p>
<p><span style="color: #bd934f;">Q: Do you think XQuery will work to interrogate the XML Query plans</span></p>
<p>Absolutely, yes. I&#8217;m no expert on XQuery (closer to the opposite), but it certainly can be done and can be very useful. There are examples here:</p>
<p>One word of caution here, if you are going to do this against the cached plans, don&#8217;t run the XQuery directly against the plan cache of the production server. Extract the plans you are interested in to a table, transfer that to a dev/test server and run your XQuery there.</p>
<p><span style="color: #bd934f;">Q: Do you ever use indexes to fix plans? You left them out.</span></p>
<p>I didn&#8217;t leave them out, indexes for fixing performance is a whole presentation of it&#8217;s own, if not a full day or two training.</p>
<p>Indexes alone aren&#8217;t going to help with the kind of problems I covered here, parameter sniffing, stale stats, bad query patterns, because the root of most of those is the optimizer creating a plan which is good (or at least one it thinks is good) which is then reused inappropriately.</p>
<p><span style="color: #bd934f;">Q: We all know NULL stands for &#8220;nothing here&#8221; or &#8220;no data&#8221; or &#8220;unknown value&#8221;. From a performance standpoint, shouldn&#8217;t we just drop NULL from physical designs and use a default value (empty string, 0, way out of bounds dates, etc.)? Does IFNULL() badly hit performance?</span></p>
<p>Wow, that&#8217;s opening the proverbial can of worms&#8230;</p>
<p>I&#8217;m actually in favour of nulls in a database. If there&#8217;s no data for a column I don&#8217;t want some made up value to indicate that the data is missing.</p>
<p>This is a major debate in DB design circles and there&#8217;s no single way that satisfies everyone.</p>
<p>ISNULL can have effects on performance, depending how it&#8217;s used. Like just about everything else, use it in appropriate places and you should be fine.</p>
<p><span style="color: #bd934f;">Q: Can the execution plans anyway be used in baselining performance? If yes, how?</span></p>
<p>I suppose you can. Baselining is all about getting stats and numbers for normal performance. Catching the execution plans for common queries and storing what their normal execution plans are could be useful when problems arise.</p>
<p>You can&#8217;t derive query performance from execution plans though.</p>
<p><span style="color: #bd934f;">Q: Is there any scenario the plan column could be null in plan cache ? I see entry for my SP in cache but column plan is always null. SP runs every 2-3 mins though. I am using option(recompile) for one statement in SP though.</span></p>
<p>I have seen cases where the plan is null, I don&#8217;t know what causes it.</p>
<p>Slide deck and demos: <a href="http://sqlinthewild.co.za/wp-content/uploads/2011/03/24HoP.zip">24HoP_demo</a>, <a href="http://sqlinthewild.co.za/wp-content/uploads/2011/03/24HoursofPASSPPT_GailShaw_Spring2011.pptx">24HoursofPASS_PPT</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2011/03/18/q-a-from-24-hours-of-pass-session/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Upcoming presentations</title>
		<link>http://sqlinthewild.co.za/index.php/2011/01/28/upcoming-presentations/</link>
		<comments>http://sqlinthewild.co.za/index.php/2011/01/28/upcoming-presentations/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 14:30:10 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[Syndication]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=876</guid>
		<description><![CDATA[It&#8217;s looking like it&#8217;s going to be a busy year. It&#8217;s only January and I already have three presentations lined up for the first quarter of the year. On the 10th February I&#8217;m presenting on database corruption for Quest&#8217;s Pain of the Week webcast. I&#8217;m not Paul Randal, but I think I might be able [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s looking like it&#8217;s going to be a busy year.</p>
<p>It&#8217;s only January and I already have three presentations lined up for the first quarter of the year.</p>
<ul>
<li>On the 10<sup>th</sup> February I&#8217;m presenting on <a href="http://www.quest.com/events/ListDetails.aspx?ContentID=13318">database corruption</a> for Quest&#8217;s <a href="http://www.quest.com/backstage/pow.aspx">Pain of the Week</a> webcast. I&#8217;m not <a href="http://sqlskills.com/blogs/paul/">Paul Randal</a>, but I think I might be able to muddle through the topic without making too much of a fool of myself.</li>
<li>27<sup>th</sup> February I&#8217;m speaking at <a href="http://www.sqlsaturday.com/65/eventhome.aspx">SQLSaturday 65</a> in Vancouver! First trip to Canada, first SQLSaturday attendance. I&#8217;m doing a presentation that&#8217;s an old favourite of mine – <a href="http://www.sqlsaturday.com/viewsession.aspx?sat=65&amp;sessionid=2962">Introduction to Indexes</a>. It&#8217;s very much aimed at beginners, so don&#8217;t expect any dark magic or mystical secrets</li>
<li>15th March I&#8217;m taking part in the <a href="http://www.sqlpass.org/24hours/spring2011/default.aspx">24 Hours of PASS</a>. The session is titled &#8220;<a href="http://www.sqlpass.org/24hours/spring2011/Home/BadPlanSit.aspx">Bad plan! Sit</a>&#8221; Thanks to Steve Jones (<a href="http://www.sqlservercentral.com/blogs/steve_jones/">blog</a>|<a href="http://twitter.com/#!/way0utwest">twitter</a>) for the initial idea.It&#8217;s going to have something to do with bad execution plans. I haven&#8217;t decided exactly what yet. I guess that means it will be a surprise.</li>
</ul>
<p>In addition to these, I&#8217;m also presenting at both the February and March meetings of the South African SQL Server usergroup.</p>
<p>That&#8217;s definitely enough work for the next two months…</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2011/01/28/upcoming-presentations/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Redgate&#039;s Exceptional DBA competition</title>
		<link>http://sqlinthewild.co.za/index.php/2010/05/07/redgates-exceptional-dba-competition/</link>
		<comments>http://sqlinthewild.co.za/index.php/2010/05/07/redgates-exceptional-dba-competition/#comments</comments>
		<pubDate>Fri, 07 May 2010 16:00:55 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Community]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=595</guid>
		<description><![CDATA[Redgate&#8217;s Exceptional DBA competition is back for a third year! I was one of the judges for this last year and, while I&#8217;m not judging it this year, I do have some advice for anyone considering entering. Be Explicit and detailed This is not a competition won by luck. There are no dice rolled, no [...]]]></description>
			<content:encoded><![CDATA[<p>Redgate&#8217;s <a href="http://www.exceptionaldba.com/">Exceptional DBA competition</a> is back for a third year! I was one of the judges for this last year and, while I&#8217;m not judging it this year, I do have some advice for anyone considering entering.</p>
<h3>Be Explicit and detailed</h3>
<p>This is not a competition won by luck. There are no dice rolled, no coins tossed, no numbers drawn from a hat.</p>
<p>As an entrant, you need to convince the judges that you (or the person you are nominating) are the best of the best. The only thing that you can use to do that are the answers on the entry form.</p>
<p>The more the better (within reason). To give an idea, last year the answers to one question (What&#8217;s the hallmarks of an exceptional DBA?) ranged from one word to half a page. Which of those two do you think the judges rated higher?</p>
<p>If you can, get a colleague to read over your answers before submitting them. Ask them for their opinion, ask them if there are any pieces that they&#8217;d change or add to show you (or the person you are nominating) in their very best light.</p>
<h3>Spell check</h3>
<p>Please, please, please run a spell check and grammar check over your entries before submitting. This goes double if English (or American) is not your first language. There is nothing that makes an entry look bad more than por speeling thet teh jugdes mast spand tyme desifering.</p>
<p>No, not all of us speak English fluently, but there are enough grammar and spell checkers available (hint Firefox includes one if you download the dictionary) that not bothering shows a lack of interest and professionalism. Besides, if the judges can&#8217;t work out what you&#8217;re saying, they&#8217;re not going to rate your entry highly.</p>
<p>On this point, watch the l33t speak and SMS/twitter style word-shortening. They&#8217;re harder to read that fully written out words, and space is not at a premium for these entries. Again, you should be trying to show that you are a professional, much like you would when writing up a CV.</p>
<h3>Watch the humour</h3>
<p>What&#8217;s funny for one person may be annoying or offensive to another. A joke about &#8216;cleaning up after those incompetent developers&#8217; may not be funny to a judge who is a developer or comes from a development background. Again, keep it professional, imagine that these answers are going to be seen by the CIO/owner/MD of the company you work for.</p>
<p>Along the same lines, funny answers aren&#8217;t. One entry last year, for the question &#8220;Why do you deserve to win?&#8221;, gave as an answer &#8220;No idea <img src='http://sqlinthewild.co.za/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> &#8221;</p>
<p>Well dude, if you don&#8217;t know why you should win, I sure as hell don&#8217;t.</p>
<h3>In Conclusion</h3>
<p>If you&#8217;re planning to enter this competition, you have one chance to make an impression with the judges &#8211; your answers. Make it the best impression that you can.</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2010/05/07/redgates-exceptional-dba-competition/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>SQL Server Usergroup &#8211; February meeting</title>
		<link>http://sqlinthewild.co.za/index.php/2010/02/10/sql-server-usergroup-february-meeting/</link>
		<comments>http://sqlinthewild.co.za/index.php/2010/02/10/sql-server-usergroup-february-meeting/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 07:00:26 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Community]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=547</guid>
		<description><![CDATA[The February meeting of the SA SQL Server usergroup will be on the 16th of February 2010. Venue and time are the same as always, 18h30 at the Microsoft offices This month, Richard Sweetnam, one of Microsoft SA&#8217;s Premier Field Engineers will be presenting on Tips and Tricks for Management Studio. Hope to see you [...]]]></description>
			<content:encoded><![CDATA[<p>The February meeting of the SA SQL Server usergroup will be on the 16th of February 2010. Venue and time are the same as always, 18h30 at the Microsoft offices</p>
<p>This month, Richard Sweetnam, one of Microsoft SA&#8217;s Premier Field Engineers will be presenting on Tips and Tricks for Management Studio.</p>
<p>Hope to see you all there.</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2010/02/10/sql-server-usergroup-february-meeting/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>South African SQL Server Usergroup &#8211; October meeting</title>
		<link>http://sqlinthewild.co.za/index.php/2009/10/08/south-african-sql-server-usergroup-october-meeting/</link>
		<comments>http://sqlinthewild.co.za/index.php/2009/10/08/south-african-sql-server-usergroup-october-meeting/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 20:06:40 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Community]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=388</guid>
		<description><![CDATA[It&#8217;s our 1st birthday this month! There will be cake and prizes. I have three autographed SQL books and a backpack laptop bag to give away this month. The meeting will be in the usual location &#8211; the Johannesburg Microsoft offices, 3012 William Nicol Drive, Bryanston. 18h30 on Tuesday the 20th October. I&#8217;ll be presenting [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s our 1st birthday this month! There will be cake and prizes. I have three autographed SQL books and a backpack laptop bag to give away this month.</p>
<p>The meeting will be in the usual location &#8211; the Johannesburg Microsoft offices, <a href="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=en&amp;geocode=&amp;q=3012+William+Nicol+Dr+Sandton+South+Africa&amp;sll=-26.045081,28.016253&amp;sspn=0.014999,0.027874&amp;ie=UTF8&amp;hq=&amp;hnear=3012+William+Nicol+Dr,+Sandton,+2191,+South+Africa&amp;ll=-26.04539,28.020651&amp;spn=0.014999,0.027874&amp;z=16">3012 William Nicol Drive, Bryanston</a>. 18h30 on Tuesday the 20th October. I&#8217;ll be presenting te a session entitled &#8220;Lies, damned lies and Statistics&#8221;.  This session will also be presented in 4 weeks  time at the PASS Summit in Seattle. Consider this a sneak preview.</p>
<p>Please let me know ASAP if you are coming. We need accurate attendance numbers or there won&#8217;t be enough cake. <img src='http://sqlinthewild.co.za/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2009/10/08/south-african-sql-server-usergroup-october-meeting/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>TechEd Online Interview</title>
		<link>http://sqlinthewild.co.za/index.php/2009/09/30/teched-online-interview/</link>
		<comments>http://sqlinthewild.co.za/index.php/2009/09/30/teched-online-interview/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 09:13:31 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Community]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Syndication]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=370</guid>
		<description><![CDATA[Back in August at TechEd Africa I did a TechEd Online interview with Frikkie Bosch. Frikkie&#8217;s the marketing manager for the Server products down here in South Africa. We discussed some common mistakes that I&#8217;ve seen regarding SQL Server performance. I&#8217;m not talking specifics of query/table design here, but rather mistakes at a higher level. [...]]]></description>
			<content:encoded><![CDATA[<p>Back in August at TechEd Africa I did a TechEd Online interview with Frikkie Bosch. Frikkie&#8217;s the marketing manager for the Server products down here in South Africa. We discussed some common mistakes that I&#8217;ve seen regarding SQL Server performance. I&#8217;m not talking specifics of query/table design here, but rather mistakes at a higher level.</p>
<p>The interview is available on the <a href="http://www.msteched.com/online/view.aspx?tid=d3325536-83bb-41e2-92d4-55850218d11f">TechEd Online site</a>. I&#8217;m interested in what people think, am I on the mark or completely in the wrong ballpark?</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2009/09/30/teched-online-interview/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server Usergroup – August resources</title>
		<link>http://sqlinthewild.co.za/index.php/2009/09/14/sql-server-usergroup-%e2%80%93-august-resources/</link>
		<comments>http://sqlinthewild.co.za/index.php/2009/09/14/sql-server-usergroup-%e2%80%93-august-resources/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 04:14:23 +0000</pubDate>
		<dc:creator>Gail</dc:creator>
				<category><![CDATA[Community]]></category>

		<guid isPermaLink="false">http://sqlinthewild.co.za/?p=329</guid>
		<description><![CDATA[Here&#8217;s the presentation from the August meeting. SQL User Group PSSDiag Presentation (Server 2008) (2MB file)]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s the presentation from the August meeting. <a href="http://sqlinthewild.co.za/wp-content/uploads/2009/09/SQL-User-Group-PSSDiag-Presentation-Server-2008.pptx">SQL User Group PSSDiag Presentation (Server 2008)</a> (2MB file)</p>
]]></content:encoded>
			<wfw:commentRss>http://sqlinthewild.co.za/index.php/2009/09/14/sql-server-usergroup-%e2%80%93-august-resources/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

