<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://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>Search results matching tags 'Best Practices' and 'denali'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=Best+Practices,denali&amp;orTags=0</link><description>Search results matching tags 'Best Practices' and 'denali'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>SQL Server v.Next (Denali) : Breaking change to sys.dm_exec_sessions</title><link>http://sqlblog.com/blogs/aaron_bertrand/archive/2011/07/19/sql-server-v-next-denali-breaking-change-to-sys-dm-exec-sessions.aspx</link><pubDate>Tue, 19 Jul 2011 11:22:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:37059</guid><dc:creator>AaronBertrand</dc:creator><description>&lt;p&gt;If you're not OCD about prefixing every single column in a query, this is one that might bite you. Today you might have code that assumes that, because database_id is in sys.dm_exec_requests but not in sys.dm_exec_sessions, you don't need to prefix database_id in the following example:&lt;/p&gt;&lt;blockquote&gt;&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT TOP &lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;s.session_id&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;database_id&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="green"&gt;sys&lt;/font&gt;&lt;font&gt;&lt;font color="black"&gt;.&lt;/font&gt;&lt;/font&gt;&lt;font color="green"&gt;dm_exec_sessions &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;s&lt;br&gt;&lt;/font&gt;&lt;font color="magenta"&gt;LEFT &lt;/font&gt;&lt;font color="gray"&gt;OUTER &lt;/font&gt;&lt;font color="blue"&gt;JOIN &lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="green"&gt;sys&lt;/font&gt;&lt;font&gt;&lt;font color="black"&gt;.&lt;/font&gt;&lt;/font&gt;&lt;font color="green"&gt;dm_exec_requests&lt;/font&gt;&lt;font color="black"&gt; &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;r&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;ON &lt;/font&gt;&lt;font color="black"&gt;s.session_id = &lt;/font&gt;&lt;font color="black"&gt;r.session_id&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/blockquote&gt;&lt;p&gt;In SQL Server 2005, 2008 and 2008 R2, the above code works perfectly fine, because the server can determine quite easily that the database_id column comes from the sys.dm_exec_requests DMV. However, if you run this same code on Denali CTP3, you get the following error:&lt;/p&gt;&lt;blockquote&gt;&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;&lt;tr&gt;&lt;td&gt;&lt;div style="color:red;padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;p&gt;Msg 209, Level 16, State 1, Line 3&lt;br&gt;Ambiguous column name 'database_id'. &lt;br&gt;&lt;/p&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/blockquote&gt;&lt;p&gt;Why is that? Well, we're finally getting indication of some database context even when the session is idle. Back in SQL Server 2005, they deprecated the sysprocesses system table in favor of the new DMVs sys.dm_exec_sessions, sys.dm_exec_sessions and sys.dm_exec_requests, though they made a compatibility view called sys.sysprocesses. They couldn't eliminate sysprocesses immediately because of the volume of code that it would break; and they quickly found that they couldn't eliminate it in the longer run because some crucial information was missing (see &lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/257502/deprecation-of-sysprocesses-dmvs-doesnt-fully-replace-all-columns" title="http://connect.microsoft.com/SQLServer/feedback/details/257502/deprecation-of-sysprocesses-dmvs-doesnt-fully-replace-all-columns" target="_blank"&gt;Connect #257502&lt;/a&gt; for more info). In sys.sysprocesses you can see database context, for example, in the dbid column; in sys.dm_exec_sessions, there is no equivalent. There is a database_id column in the sys.dm_exec_requests DMV, but this only helps you get database context information for sessions with an active request.&lt;/p&gt;&lt;p&gt;Now in Denali, we have some new columns in sys.dm_exec_sessions, including database_id. This allows us to determine database context even for a session that currently doesn't have an active request; but it comes at the potential cost of breaking code, as demonstrated above. To make the above code sample work, you'll need to properly prefix the database_id column, maybe even with a COALESCE:&lt;/p&gt;&lt;blockquote&gt;&lt;table bgcolor="#eeeeee" cellpadding="0" cellspacing="0"&gt;&lt;tr&gt;&lt;td&gt;&lt;pre style="padding:10px 20px;font-size:12px;font-family:consolas,lucida console,courier new,courier;-moz-background-inline-policy:continuous;"&gt;&lt;font color="blue"&gt;SELECT TOP &lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;1&lt;/font&gt;&lt;font color="gray"&gt;)&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="black"&gt;s.session_id&lt;/font&gt;&lt;font color="gray"&gt;,&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font&gt;&lt;font color="black"&gt;database_id&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt; = &lt;/font&gt;&lt;font&gt;&lt;font color="magenta"&gt;COALESCE&lt;/font&gt;&lt;/font&gt;&lt;font color="gray"&gt;(&lt;/font&gt;&lt;font color="black"&gt;r.database_id, s.database_id&lt;/font&gt;&lt;font color="gray"&gt;)&lt;/font&gt;&lt;font color="black"&gt;&lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;FROM &lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="green"&gt;sys&lt;/font&gt;&lt;font&gt;&lt;font color="black"&gt;.&lt;/font&gt;&lt;/font&gt;&lt;font color="green"&gt;dm_exec_sessions &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;s&lt;br&gt;&lt;/font&gt;&lt;font color="magenta"&gt;LEFT &lt;/font&gt;&lt;font color="gray"&gt;OUTER &lt;/font&gt;&lt;font color="blue"&gt;JOIN &lt;br&gt;&lt;/font&gt;&lt;font color="blue"&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="green"&gt;sys&lt;/font&gt;&lt;font&gt;&lt;font color="black"&gt;.&lt;/font&gt;&lt;/font&gt;&lt;font color="green"&gt;dm_exec_requests&lt;/font&gt;&lt;font color="black"&gt; &lt;/font&gt;&lt;font color="blue"&gt;AS &lt;/font&gt;&lt;font color="black"&gt;r&lt;br&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="blue"&gt;ON &lt;/font&gt;&lt;font color="black"&gt;s.session_id &lt;/font&gt;&lt;font&gt;&lt;font color="gray"&gt;=&lt;/font&gt;&lt;/font&gt;&lt;font color="black"&gt; &lt;/font&gt;&lt;font color="black"&gt;r.session_id&lt;/font&gt;&lt;font color="gray"&gt;;&lt;/font&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/blockquote&gt;&lt;p&gt;There are some other interesting columns that have been added, such as authenticating_database_id - which will allow you to determine the original database even in cases where ORIGINAL_DB_NAME() is not available. This one warrants some testing and further treatment in a future blog post.&lt;br&gt;&lt;/p&gt;&lt;p&gt;Now don't get me wrong, database_id is a fantastic and welcome addition - I can stop looking at sys.sysprocesses to determine the database for sessions that aren't currently running a query. But if you're not currently in the habit of properly qualifying column names throughout your queries, here's one more reason you should start. This is another one of those "maybe breaking changes" that is almost certainly not going to show up using the Upgrade Advisor or Best Practices Analyzer, so it can be a real problem if the first time you see it is after you upgrade.&lt;br&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp; &lt;br&gt;&lt;/p&gt;</description></item><item><title>Connect Digest : 2011-05-09</title><link>http://sqlblog.com/blogs/aaron_bertrand/archive/2011/05/09/connect-digest-2011-05-09.aspx</link><pubDate>Mon, 09 May 2011 11:27:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:35253</guid><dc:creator>AaronBertrand</dc:creator><description>&lt;p&gt;This week we're going to look at some issues involving tempdb...&lt;/p&gt;&lt;p&gt;&lt;br&gt;&lt;b&gt;Provide a tempdb per database&lt;/b&gt; &lt;br&gt;
&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/281202" title="http://connect.microsoft.com/SQLServer/feedback/details/281202" target="_blank"&gt;#176241 : Eliminating TempDb By Adding Temp Filegroup to Each Database&lt;br&gt;#281202 : multiple tempdb&lt;/a&gt;&lt;/p&gt;&lt;p&gt;For these two requests, I am hoping that the Contained Databases feature (&lt;a href="http://sqlblog.com/blogs/aaron_bertrand/archive/tags/Contained+databases/default.aspx" title="http://sqlblog.com/blogs/aaron_bertrand/archive/tags/Contained+databases/default.aspx" target="_blank"&gt;which I've talked about multiple times&lt;/a&gt;)
 will get to this capability in the version that follows Denali. They've
 taken care of the collation issue, but it would be nice to be able to 
set up different tempdb file / filegroup structures for databases that 
have different demands, and be able to move those files easily - along 
with the user database - without disrupting the rest of the system, or 
requiring a "one size fits all" mentality for tempdb. &lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;br&gt;&lt;b&gt;Tempdb on local disk for clusters&lt;/b&gt; &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/532759" title="http://connect.microsoft.com/SQLServer/feedback/details/532759" target="_blank"&gt;#488725 : Creating TempDB On Local drives for clusters&lt;br&gt;#532759 : Support local disk location for TempDB in failover cluster installation&lt;/a&gt;&lt;/p&gt;&lt;p&gt;I found it curious that one of these items is marked as "fixed" and the other is marked as "won't fix" - both with no comment. The capability is in Denali CTP1, but as a disclaimer, that doesn't mean it will pass all testing and make it into the final Denali release. If it is (or is not) intended to be in the Denali release, it would be great to get both of these items closed out properly with an official comment from Microsoft.&lt;br&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;br&gt;&lt;b&gt;Place version store elsewhere&lt;/b&gt;&lt;/p&gt;
&lt;blockquote&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/648100" title="http://connect.microsoft.com/SQLServer/feedback/details/648100" target="_blank"&gt;#648100 : ability to put the row version store somewhere other than in tempdb&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Chris Adkin (&lt;a href="http://twitter.com/ChrisAdkin8" title="http://twitter.com/ChrisAdkin8" target="_blank"&gt;twitter&lt;/a&gt;)
 asks for the ability to place version store data into a dedicated 
filegroup for a user database, instead of putting the version store for 
all databases into tempdb.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;br&gt;&lt;b&gt;Allow tempdb to bypass model inheritance&lt;/b&gt; &lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/415343" title="http://connect.microsoft.com/SQLServer/feedback/details/415343" target="_blank"&gt;#415343 : Enhancements to model database&lt;/a&gt; &lt;br&gt;&lt;/p&gt;&lt;p&gt;This was a suggestion for a few enhancements to the model database, but one specific item was: "Allow tempdb to bypass inheriting objects and data from model.  I use model as a template for new databases and in some cases tempdb inherits a lot of schema and data that will never be used ... this can affect startup time on a reboot or failover."&amp;nbsp; I'm not sure if I should file a separate Connect item for this suggestion alone. Thoughts anyone? &lt;br&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;br&gt;&lt;b&gt;Do not track temp table creation in default trace&lt;/b&gt;&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/542102" title="http://connect.microsoft.com/SQLServer/feedback/details/542102" target="_blank"&gt;#542102 : The default trace should not include creation of temp tables&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Erland Sommarskog described a trace on one of his systems that was very heavily weighted toward the creation of #temp tables. I agree with him that there should be a way to configure the default trace to not bother logging certain types of operations. That said, any suggestions about tracing in any form will likely be routed to the "use XEvents instead" department.&lt;br&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;br&gt;&lt;b&gt;Fix bad suggestions about tempdb log files&lt;/b&gt; &lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/643742" title="http://connect.microsoft.com/SQLServer/feedback/details/643742" target="_blank"&gt;#643742 : Remove the recommendation of creating multiple log files for tempdb to improve performance&lt;/a&gt; &lt;/p&gt;&lt;p&gt;Sankar Reddy (&lt;a href="http://sankarreddy.com/" title="http://sankarreddy.com/" target="_blank"&gt;blog&lt;/a&gt; | &lt;a href="http://twitter.com/SannkarReddy13" title="http://twitter.com/SannkarReddy13" target="_blank"&gt;twitter&lt;/a&gt;) noted that in &lt;a href="http://msdn.microsoft.com/en-us/library/ms345118.aspx" title="http://msdn.microsoft.com/en-us/library/ms345118.aspx" target="_blank"&gt;this MSDN topic&lt;/a&gt; (admittedly, written for SQL Server 2005), it has a sample with a really bad idea: "This example creates two additional data files for tempdb, each with an initial size of 8 MB, and two log files with an initial size of 1 MB." In addition to scoffing at the recommendation to add log files to improve performance, I'd like to add that creating two additional data log files at only 8 MB (and presumably leaving the autogrowth rate at 10%) has very little chance of having a positive impact on performance. In many cases the results will be even worse - three tiny data files for tempdb? and three even tinier log files? really? Clearly the example was written by someone who assumed that I/O works differently on data files and log files. The only upside to this is that I couldn't find an equivalent document for SQL Server 2008, 2008 R2 or Denali, so they aren't continuing to recommend this bad practice - but this article is still out there for people to "learn" from. Kevin Kline (&lt;a href="http://sqlblog.com/blogs/kevin_kline/default.aspx" title="http://sqlblog.com/blogs/kevin_kline/default.aspx" target="_blank"&gt;blog&lt;/a&gt; | &lt;a href="http://twitter.com/kekline" title="http://twitter.com/kekline" target="_blank"&gt;twitter&lt;/a&gt;) also &lt;a href="http://sqlblog.com/blogs/kevin_kline/archive/2009/06/23/old-performance-tuning-recommendations-die-hard.aspx" title="http://sqlblog.com/blogs/kevin_kline/archive/2009/06/23/old-performance-tuning-recommendations-die-hard.aspx" target="_blank"&gt;commented on this issue in a blog post in 2009&lt;/a&gt;. I find it funny that they fixed his observation about calling SQL Server 2005 "SQL Server 9.0" but didn't bother fixing the code sample.&lt;br&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&lt;br&gt;&lt;b&gt;Stop defaulting all data/log files to C:\&lt;/b&gt;&lt;br&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;a href="http://connect.microsoft.com/SQLServer/feedback/details/338763" title="http://connect.microsoft.com/SQLServer/feedback/details/338763" target="_blank"&gt;#338763 : Setup : Encourage better practice for db/log locations&lt;/a&gt;&lt;p&gt;I filed this issue because I found it alarming that, even on a system with gobs and gobs of disks on other drives, all system and user data and log file locations (including tempdb) were pre-populated with C:\Program Files\... If C:\ is the only drive letter found (e.g. on a virtual machine or a workstation), I think the default is fine; however, if other drive letters are found, I think it makes more sense to either prompt for a more obvious choice or to leave the values blank. The time it takes during installation to choose these locations by putting some actual thought into it is much preferred over the time it will take later to correct those choices during a production emergency.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>