<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/atom.xsl" media="screen"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-US"><title type="html">SQL Server Storage Engine</title><subtitle type="html" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/atom.aspx</id><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/" /><link rel="self" type="application/atom+xml" href="http://blogs.msdn.com/b/sqlserverstorageengine/atom.aspx" /><generator uri="http://telligent.com" version="5.6.583.21163">Telligent Community 5.6.583.21163 (Build: 5.6.583.21163)</generator><updated>2009-09-16T20:53:00Z</updated><entry><title>AlwaysOn: Comparing Readable Secondary with the similar functionality available in DB2</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2012/01/22/alwayson-comapring-readble-secondary-with-the-similar-functionality-available-in-db2.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2012/01/22/alwayson-comapring-readble-secondary-with-the-similar-functionality-available-in-db2.aspx</id><published>2012-01-22T06:45:00Z</published><updated>2012-01-22T06:45:00Z</updated><content type="html">&lt;p&gt;In my previous blogs, I had described how Readable Secondary functionality works SQL Server 2012. As you look at other database vendors, you will realize that they also provide the functionality to offload read workload to secondary or mirror. However, if you look closer, you will realize each vendor has significant differences on how this functionality is made available to customers. Here is one comparison that I have done between SQL Server and DB2.&lt;/p&gt;
&lt;p&gt;&lt;span style="text-decoration: underline;"&gt;Competitive study of Readable Secondary in DB2 9.7&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;DB2 9.7 HADR configuration supports &amp;lsquo;active&amp;rsquo; standby server that can be used for query workload. From competition perspective, it is similar to Readable Secondary functionality. This report is based on DB2 9.7&lt;br /&gt;documentation. For details, please refer to the link&lt;/p&gt;
&lt;p&gt;&lt;a href="http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.admin.ha.doc/doc/c0054257.html"&gt;http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.admin.ha.doc/doc/c0054257.html&lt;/a&gt;&lt;/p&gt;
&lt;table border="1" cellspacing="0" cellpadding="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" width="169"&gt;
&lt;p&gt;&lt;b&gt;Key Feature&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="256"&gt;
&lt;p&gt;&lt;b&gt;DB2&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;&lt;b&gt;SQL Server 2012&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="169"&gt;
&lt;p&gt;&lt;b&gt;Isolation Level Mapping:&lt;/b&gt; This is very&amp;nbsp; relevant for SQL Server as the DB2 provides similar isolation levels&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="256"&gt;
&lt;p&gt;By default only support &amp;lsquo;Uncommitted Read&amp;rsquo;. An application that uses any other isolation level fails.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can however use configuration option DB2_STANDBY_ISO registry variable and set it to UR. In that case, all isolation levels are mapped to Uncommitted Read.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;Provides consistent read by mapping all isolation levels to Snapshot Isolation.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="169"&gt;
&lt;p&gt;&lt;b&gt;DDL and Read Workload: &lt;/b&gt;What happens when DDL or maintenance operations are executed on the primary. What is the impact on the read&amp;nbsp; workload on the secondary&lt;b&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="256"&gt;
&lt;p&gt;When an HADR active standby database is replaying DDL log records or maintenance operations, the standby enters the replay-only window. When the standby is in the replay-only window, existing connections to the standby are terminated and new connections to the standby are blocked.&lt;/p&gt;
&lt;p&gt;DB2 recommends customers to run these operations during specific time window&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;No such restrictions. In many cases, the DDL may not get blocked due to concurrent read workload.&amp;nbsp; In case of DDL getting blocked due to concurrent read-workload and the &amp;lsquo;recovery interval&amp;rsquo; threshold is crossed, we generate an XEvent which can be used to kill the blocking readers. We expect this to be not that common, based on &amp;lsquo;recovery interval&amp;rsquo; option.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="169"&gt;
&lt;p&gt;&lt;b&gt;Auto Statistics Creation:&lt;/b&gt; Since secondary is available for read-only access, how does it address making statistics available needed only for the queries running on the readable secondary? If statistics are not available, it can potentially increase the execution time by orders of magnitude.&lt;br /&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="256"&gt;
&lt;p&gt;Requires customers to manually create/update statistics.&amp;nbsp; Since this is a DDL operation, it can only be done in &amp;lsquo;replay-only window&amp;rsquo;. This means that query plans will be sub-optimal until the statistics are made available.&lt;/p&gt;
&lt;p&gt;Note: DB2 document does not explicitly calls this out but references to statistics seem to imply this.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;Allows auto-create/update of statistics on the readable secondary so that optimizer will always generate optimized query plans.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="169"&gt;
&lt;p&gt;&lt;b&gt;Auditing&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="256"&gt;
&lt;p&gt;Manually create the instance level auditing&lt;br /&gt;&amp;nbsp; configuration on the standby server&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;Manually create the instance level audit specification on the readable secondary.&lt;br /&gt;.&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="169"&gt;
&lt;p&gt;&lt;b&gt;Secondary falling behind: &lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="256"&gt;
&lt;p&gt;Manually kill the read workload. It is not clear from DB2 documentation if they generate any event to notify customers&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;If REDO is slowing down, we will generate an XEvent when &amp;lsquo;recovery interval&amp;rsquo; threshold is crossed. The customer can choose to kill the offending readers. If the slowdown is because of resources, the reader workload can be throttled using Resource Governor.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="169"&gt;
&lt;p&gt;&lt;b&gt;Temporary Objects&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="256"&gt;
&lt;p&gt;Created temporary tables (CGTTs) and declared temporary tables (DGTTs) are not supported on the standby.&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;No restrictions. The read workload is free to do any DDL in temporary database.&lt;br /&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="169"&gt;
&lt;p&gt;&lt;b&gt;Data types: LOB, XML, &lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="256"&gt;
&lt;p&gt;Not supported on the standby server&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;No&amp;nbsp; restrictions. SQL Server will support LOBS, XML, FILESTREAM, and FTS&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="169"&gt;
&lt;p&gt;&lt;b&gt;Backup on Secondary&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="256"&gt;
&lt;p&gt;Not supported&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;Supported&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Sunil Agarwal&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10259332" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="High Availability" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/High+Availability/" /></entry><entry><title>AlwaysOn: I just enabled Readable Secondary but my query is blocked?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-i-just-enabled-readble-secondary-but-my-query-is-blocked.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-i-just-enabled-readble-secondary-but-my-query-is-blocked.aspx</id><published>2011-12-22T23:23:00Z</published><updated>2011-12-22T23:23:00Z</updated><content type="html">&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: medium;" size="3"&gt;&lt;span face="Calibri"&gt;When you connect to Secondary Replica, but it has not been enabled for read workload, you will get the following error under two situations &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: medium;"&gt;&lt;span face="Calibri" size="3"&gt;(1)&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span size="3"&gt;&lt;span face="Calibri"&gt;You connect directly to one of the databases under availability group. It is denied because the database is not enabld for read workload.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: medium;"&gt;&lt;span face="Calibri" size="3"&gt;(2)&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span size="3"&gt;&lt;span face="Calibri"&gt;You connect to a non-AG database such as master database which&amp;nbsp;succeeds&amp;nbsp;and now you execute &amp;lsquo;use &amp;lt;db&amp;gt;&amp;rsquo; command.&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #ff0000; font-family: verdana,geneva; font-size: medium;"&gt;Msg 976, Level 14, State 1, Line 1&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #ff0000; font-family: verdana,geneva; font-size: medium;"&gt;The target database, 'hadr_test', is participating in an availability group and is currently not accessible for queries. Either data movement is suspended or the availability replica is not enabled for read access. To allow read-only access to this and other databases in the availability group, enable read access to one or more secondary availability replicas in the group.&amp;nbsp; For more information, see the ALTER AVAILABILITY GROUP statement in SQL Server Books Online.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: medium;" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: medium;" size="3"&gt;&lt;span face="Calibri"&gt;To connect to readable secondary database, you will need to enable the secondary replica for read workload.&amp;nbsp;Once it is done, you can connect but there is one catch. Your queries will block until all active transactions active at the time of enabling readable secondary have been committed and processed on the secondary replica. This is needed to guarantee that row versions are available on the secondary replica before executing the query under snapshot isolation as all isolation levels are implicitly mapped to snapshot isolation.&amp;nbsp; Here is one example to illustrate this&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: medium;" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff; font-family: verdana,geneva; font-size: medium;" size="3"&gt;&lt;span face="Calibri"&gt;&lt;i&gt;-- On primary replica, execute a transaction that updates all the rows in employee&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff; font-family: verdana,geneva; font-size: medium;"&gt;&lt;i&gt;&lt;span size="3"&gt;&lt;span face="Calibri"&gt;-- but don't commit it&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff; font-family: verdana,geneva; font-size: medium;" size="3"&gt;&lt;span face="Calibri"&gt;&lt;i&gt;create&lt;/i&gt;&lt;i&gt; table employee (name char (100), id int)&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff; font-family: verdana,geneva; font-size: medium;" size="3"&gt;&lt;span face="Calibri"&gt;&lt;i&gt;go&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff; font-family: verdana,geneva; font-size: medium;"&gt;&lt;i&gt;&lt;span face="Calibri" size="3"&gt;&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff; font-family: verdana,geneva; font-size: medium;" size="3"&gt;&lt;span face="Calibri"&gt;&lt;i&gt;declare&lt;/i&gt;&lt;i&gt; @i int&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff; font-family: verdana,geneva; font-size: medium;" size="3"&gt;&lt;span face="Calibri"&gt;&lt;i&gt;select&lt;/i&gt;&lt;i&gt; @i = 0&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff; font-family: verdana,geneva; font-size: medium;" size="3"&gt;&lt;span face="Calibri"&gt;&lt;i&gt;while &lt;/i&gt;&lt;i&gt;(&lt;/i&gt;&lt;i&gt;@i&lt;/i&gt;&lt;i&gt; &amp;lt; 10000)&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff; font-family: verdana,geneva; font-size: medium;" size="3"&gt;&lt;span face="Calibri"&gt;&lt;i&gt;begin&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff; font-family: verdana,geneva; font-size: medium;"&gt;&lt;i&gt;&lt;span size="3"&gt;&lt;span face="Calibri"&gt;&amp;nbsp;insert into employee values ('my name' + CONVERT(varchar(10), @i), 33)&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff; font-family: verdana,geneva; font-size: medium;"&gt;&lt;i&gt;&lt;span size="3"&gt;&lt;span face="Calibri"&gt;&amp;nbsp;select @i = @i + 1&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff; font-family: verdana,geneva; font-size: medium;"&gt;&lt;i&gt;&lt;span size="3"&gt;&lt;span face="Calibri"&gt;end&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff; font-family: verdana,geneva; font-size: medium;"&gt;&lt;i&gt;&lt;span face="Calibri" size="3"&gt;&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff; font-family: verdana,geneva; font-size: medium;" size="3"&gt;&lt;span face="Calibri"&gt;&lt;i&gt;begin&lt;/i&gt;&lt;i&gt; tran&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff; font-family: verdana,geneva; font-size: medium;"&gt;&lt;i&gt;&lt;span size="3"&gt;&lt;span face="Calibri"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; update employee set id = 1000&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: medium;" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: medium;" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: medium;" size="3"&gt;&lt;span face="Calibri"&gt;The transaction on the primary replica is still active. Now, enable secondary replica to accept read workload and issue the following query on the secondary replica. This query will get blocked&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: medium;" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff; font-family: verdana,geneva; font-size: medium;"&gt;&lt;i&gt;&lt;span size="3"&gt;&lt;span face="Calibri"&gt;-- on secondary replica, connect to the secondary database, your connection will succeed but the&lt;/span&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff; font-family: verdana,geneva; font-size: medium;" size="3"&gt;&lt;span face="Calibri"&gt;&lt;i&gt;-- following query will block&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff; font-family: verdana,geneva; font-size: medium;" size="3"&gt;&lt;span face="Calibri"&gt;&lt;i&gt;select&lt;/i&gt;&lt;i&gt; count(*) from employee&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: medium;" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: medium;" size="3"&gt;&lt;span face="Calibri"&gt;You can run query the DMV&amp;nbsp;to see where the blocking is (in my example, the query above was issued on session_id 54). Note, while the queries on user data are blocked but readable secodnary still allows you to query DMVs otherwise you would not have been able to troubleshoot or understand what is going on.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;&lt;em&gt;&lt;span style="font-family: verdana,geneva; font-size: medium;"&gt;select session_id, wait_type&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;&lt;em&gt;&lt;span style="font-family: verdana,geneva; font-size: medium;"&gt;from sys.dm_exec_requests where session_id = 54&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;&lt;em&gt;&lt;span style="font-family: verdana,geneva; font-size: medium;" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/span&gt;&lt;/em&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: medium;" size="3"&gt;&lt;span face="Calibri"&gt;The output is as follows. This wait stat corresponds to versioning transition.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: medium;" face="Calibri" size="3"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/7167.block.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/7167.block.jpg" /&gt;&lt;/a&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: medium;" size="3"&gt;&lt;span face="Calibri"&gt;If you now&amp;nbsp;commit the transaction on the primary, the query will get unblocked once the commit log record has been processed by the secondary replica.&amp;nbsp;We expect that enabling secondary replica is a very in-frequent and in a typical configuration, it would need to be done only once.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: medium;" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: medium;" size="3"&gt;&lt;span face="Calibri"&gt;Thanks&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: verdana,geneva; font-size: medium;" size="3"&gt;&lt;span face="Calibri"&gt;Sunil Agarwal&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10250550" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="High Availability" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/High+Availability/" /></entry><entry><title>AlwaysOn: Making latest statistics available on Readable Secondary, Read-Only database and Database Snapshot</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-making-upto-date-statistics-available-on-readable-secondary-read-only-database-and-database-snapshot.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-making-upto-date-statistics-available-on-readable-secondary-read-only-database-and-database-snapshot.aspx</id><published>2011-12-22T23:00:00Z</published><updated>2011-12-22T23:00:00Z</updated><content type="html">&lt;p&gt;&lt;span style="font-family: Calibri; font-size: medium;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: medium;"&gt;&lt;span style="font-family: Calibri;" size="3" face="Calibri"&gt;In the previous blog &lt;/span&gt;&lt;a href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-challenges-with-statistics-on-readonly-database-database-snapshot-and-secondary-replica.aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri;" size="3" face="Calibri" color="#0000ff"&gt;http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-challenges-with-statistics-on-readonly-database-database-snapshot-and-secondary-replica.aspx&lt;/span&gt;&lt;/a&gt;&lt;span size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt; we described that stale or missing statistics will potentially lead to a sub-optimal query plan and how it can impact the query performance on on read-only database, database snapshot and readable secondary. This blog describes how we have solved this in SQL 12 for all three flavors of databases transparently without any user intervention.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;As mentioned earlier, the read-only database, by definition, allows no physical changes to any persistent information. Similarly, no physical changes can be done on a read-only access database (i.e. readable secondary) as it must follow the strict rule of exact physical replica of the primary database. So the question arises how can we allow creating/updating statistics on one or objects in read-only or read-accessible databases user databases? The short answer is that we cannot. However, we do recognize the fact that statistics on an object can be created and re-created using the data in the base object. We use this fact to create temporary statistics in TempDB. This change guarantees that up to date statistics are available on the secondary replica just like they are on the primary replica for the query optimizer. This guarantees similar optimized query plans as you would get on the primary database. The implication of creating temporary statistics is that these statistics can be lost if the SQL Server is re-started but this is not a data loss situation because, as we had noted earlier, these statistics can be recreated at a relatively low cost by querying the underlying objects. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: medium;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Let us take couple of examples to illustrate how temporary stats work.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: medium;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;b&gt;Example-1&lt;/b&gt;: &lt;strong&gt;Missing statistics:&lt;/strong&gt;&amp;nbsp;&amp;nbsp; Key scenario here is that you execute a query on the secondary replica that requires statistics on a column but the statistics are missing because the same query or any other query that requires the statistics on the same column was never run on the primary replica.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;i&gt;create&lt;/i&gt;&lt;i&gt; table T1 (c1 int, c2 int, c3 int)&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;i&gt;go&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Calibri;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;i&gt;-- insert into T1 1 row&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;i&gt;insert&lt;/i&gt;&lt;i&gt; into T1 values (-1, -1, -1)&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Calibri;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;i&gt;-- query T1 and show that stats got created automatically on T1/c1&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;i&gt;select&lt;/i&gt;&lt;i&gt; * from T1 where c1 = 1&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Calibri;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;i&gt;-- check the stats on table T1&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;i&gt;select&lt;/i&gt;&lt;i&gt; * from sys.stats where OBJECT_ID = object_id('T1')&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Here is the output. Note, that it shows that statistics was created automatically on table with object_id as 59757167 which happen to represent table &amp;lsquo;T1&amp;rsquo;. Other interesting thing to note here is that there is a new column &amp;lsquo;is_temporary&amp;rsquo; representing that this statistics is permanent implying that it was created on the primary replica. This statistics will survive the failover (assuming no data-loss) and restart.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: medium;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/1513.statsRS1.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/1513.statsRS1.jpg" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;If you query sys.stats table on the secondary replica, you will see the same results because any logged operation is automatically available on the secondary replica. If you want to know more details, you can execute the following&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;i&gt;dbcc&lt;/i&gt;&lt;i&gt; show_statistics('t1', 'c1')&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;The output shows the row count, column on which the statistics is available along with other information.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/6886.statsRS2.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/6886.statsRS2.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Now, let us execute the following query on the secondary replica and check the statistics&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;i&gt;-- query on column C2 to show TEMPSTATS&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;i&gt;select&lt;/i&gt;&lt;i&gt; * from t1 where c2= -1&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;i&gt;--show the stats on the secondary&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;i&gt;select&lt;/i&gt;&lt;i&gt; * from sys.stats WHERE OBJECT_ID = OBJECT_ID('t1')&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: medium;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Here is the output.&amp;nbsp; Note, a new temporary statistics got created with the name &amp;lsquo;_WA_Sys_00000002_239E4DCF_readonly_database_statistics&amp;rsquo; with the &amp;lsquo;is_temporary&amp;rsquo; flag indicating that it is temporary. The statistics was automatically created because the optimizer needed it. The name of the statistics&amp;nbsp; is appended with the suffix &amp;lsquo;_readonly_database_statistics&amp;rsquo;. This is done so that this name does not clash with other automatically created statistics on the primary replica.&amp;nbsp; SQL Server 2012 prevents creating any statistics with this suffix. There is an outside chance that a permanent statistics already exists with this name (assuming someone explicitly created a statistics with this name) before database was upgraded to SQL2012. In that case, the temporary statistics creation will fail but your query will still succeed but the optimizer will not have the statistics as needed for optimization. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: medium;" size="3" face="Calibri"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/6840.statsRS3.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/6840.statsRS3.jpg" width="663" height="82" /&gt;&lt;/a&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;The temporary statistics are stored in TempDB and each statistics typically takes 8K (1 page) of storage. You can always query sys.stats table to find out all temporary statistics and estimate the storage space taken in the temporary database. Other point to note is that statistics created as part of auto-stats use data sampling so the creation of these statistics is fast and does not depend on the size of the table. One drawback is that if the data for the column is skewed then the statistics based on the sampled data are not very accurate. In such cases, if you want, you can create the statistics on the primary replica without sampling and then it will be available on the secondary replica. The temporary statistics are lost when the secondary replica is either restarted or when primary replica fails over.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: medium;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;b&gt;Example-2&lt;/b&gt;: &lt;strong&gt;Stale Statistics:&lt;/strong&gt; &amp;nbsp;Key scenario is that the statistics on a column was either explicitly or automatically created but has become stale due to DML operations. The statistics stay stale because there was no query run on the primary that required this statistics since the last update. Now, if we run a query on the secondary replica, this statistics will get updated automatically so that the optimizer can use it for optimization. Let us take the previous example where we have a table T1 with 1 row and permanent statistics on column C1 and temporary statistics on C2. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;-- insert 10000 rows on the primary to make the statistics stale&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;declare @i int = 0&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;while (@i &amp;lt; 10000)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;begin&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; insert into t1 values (@i, @i + 1000, @i + 10000)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set @i = @i + 1&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;end &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: medium;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Now, we execute the following query on the secondary&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;i&gt;-- Query on the secondary so that stats are updated with TEMPSTATS&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;i&gt;select&lt;/i&gt;&lt;i&gt; c2 from t1 where c1 = 100&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: medium;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Here is the output of the statistics. Note that the statistics &amp;lsquo;_WA_Sys_00000001_239E4DCF&amp;rsquo; got updated and is now marked as &amp;lsquo;is_temporary&amp;rsquo; being 1. This implies that SQL Server has created a temporary statistics. This does not mean that the permanent statistics got lost.&amp;nbsp; It is still available but SQL Server knows that there is an updated version on this statistics in TempDB and it will use that. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: medium;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/3051.statsRS4.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/3051.statsRS4.jpg" width="822" height="91" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;span style="font-family: Calibri;" size="3" face="Calibri"&gt;&lt;/span&gt;&lt;span size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Let us see the full details of this statistics&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;i&gt;dbcc&lt;/i&gt;&lt;i&gt; show_statistics('t1', '_WA_Sys_00000001_239E4DCF')&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;The output is as follows showing that there are now 10001 rows and this statistics in on column C1&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/1055.statsRS5.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/1055.statsRS5.jpg" width="782" height="140" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;If you restart your secondary replica, the temporary statistics will be lost and you will see the following output. In fact, if you query the statistics on the primary, you will see the same output as well.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: medium;" size="3" face="Calibri"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/2046.statsRS1.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/2046.statsRS1.jpg" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;You may wonder what happens if the statistics on C1 get updated on the primary replica. Let us repeat this experiment by running the following query on the primary&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;i&gt;-- query t1 and show that stats got created created automatically on t1/c1&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;i&gt;select&lt;/i&gt;&lt;i&gt; * from t1 where c1 &amp;gt; 1000&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;This query will cause the statistics on column C1 to get updated and when it flows to secondary replica, the statistics will be marked as permanent and now the optimizer will use the permanent statistics as it is the latest statistics available on column C1.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;In summary, to illustrate various interactions, let us take a table T1 with&amp;nbsp; three columns C1, C2, and C3. For this discussion, it does not matter what the column type is. We will use C1&lt;sub&gt;prim &lt;/sub&gt;&amp;nbsp;and C1&lt;sub&gt;sec&lt;/sub&gt; to represent statistics on column C1 that got created on primary and secondary replica respectively&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;The following table summarizes various interactions&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table border="1" cellspacing="0" cellpadding="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;b&gt;Action&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;b&gt;Primary Replica&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;b&gt;Secondary Replica&lt;/b&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;Query on Secondary with predicate on C1&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;C1&lt;sub&gt;sec&lt;/sub&gt; gets created&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;Query on Primary with predicate on C1&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;C1&lt;sub&gt;prim&lt;/sub&gt; gets created&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;C1&lt;sub&gt;prim&lt;/sub&gt; is created on when the log for the statistics is processed. At this time, both C1&lt;sub&gt;sec&lt;/sub&gt; and C1&lt;sub&gt;prim&lt;/sub&gt; exist on secondary replica but the C1&lt;sub&gt;prim&lt;/sub&gt; is latest and optimizer will use it. At this time C1&lt;sub&gt;sec&lt;/sub&gt; is not useful and user can explicitly drop it.&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;Memory pressure forces T1 out of cache&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;C1&lt;sub&gt;sec&lt;/sub&gt; is removed from the cache but it still persists in TempDB&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;Insert bunch of rows in T1 such that auto-stat threshold is crossed. Now query on the secondary with predicate on C1&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;C1&lt;sub&gt;sec&lt;/sub&gt; gets refreshed.&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;Query on Primary with predicate on C2&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;C2&lt;sub&gt;prim&lt;/sub&gt; gets created&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;C2&lt;sub&gt;prim&lt;/sub&gt; is created on when the log for the statistics is processed.&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;Insert bunch of rows in T1 such that auto-stat threshold is crossed. Now query on the secondary with predicate on C2&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;C2&lt;sub&gt;sec&lt;/sub&gt; gets created. At this time, both C2&lt;sub&gt;sec&lt;/sub&gt; and C2&lt;sub&gt;prim&lt;/sub&gt; exist on secondary replica but the C2&lt;sub&gt;sec&lt;/sub&gt; is latest and optimizer will use it.&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;Do a DDL operation on table T1&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="232"&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;Cached metadata for T1 is deleted and as part of it C1&lt;sub&gt;sec &lt;/sub&gt;&amp;nbsp;and C2&lt;sub&gt;sec&lt;/sub&gt; gets dropped.&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: medium;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;The same mechanism works on read-only database and database snapshot.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Thanks&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Sunil Agarwal&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10250546" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="High Availability" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/High+Availability/" /></entry><entry><title>AlwaysOn: Challenges with statistics on ReadOnly database, Database Snapshot and Secondary Replica</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-challenges-with-statistics-on-readonly-database-database-snapshot-and-secondary-replica.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-challenges-with-statistics-on-readonly-database-database-snapshot-and-secondary-replica.aspx</id><published>2011-12-22T22:32:00Z</published><updated>2011-12-22T22:32:00Z</updated><content type="html">&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;I am sure you all have dealt with situations when the statistics on one or more columns is either missing or not up-to date. When user submits a query for execution, the SQL Server goes through logical (simplifying or restructuring a query) and physical optimization that considers various query plans based on statistical information and then picks the one that has the least estimated cost. The key to physical optimization is the accurate estimation of data distribution (i.e. statistical information) of the input tables and intermediate results (e.g. output of JOIN operator). When optimizing a query, the optimizer generates, the statistical information on one or more tables/indexes, if not available and auto-stats has not been&amp;nbsp;explicitly disabled by the user. It uses statistics generate the optimized query plan. It is not recommended to generate a query plan without the statistics because you may end up with a sub-optimal plan that can take many orders of magnitude longer to execute. There are customer reported cases where a good query plan allows a query execution to complete in minutes while a bad query plan can take hours. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;The challenge for readable secondary is that that statistical information cannot be created or updated as this will amount to modifying the data on the secondary replica in the context of a read-only access. One common question that comes up in the context of readable secondary is &amp;lsquo;if the statistics created on the primary replica are automatically available on the secondary replica, why do I care about creating/updating statistics on the secondary?&amp;rsquo;&amp;nbsp; While it is true that any statistics that is created on the primary replica is automatically available on the secondary replica however the queries that you will run on the secondary replica are, in all likelihood, very different than the ones you run on the primary replica. For this reason, the statistics may either be missing or possibly stale when a query is run on the secondary replica. Interestingly, this issue is not limited to readable secondary. You can experience the same issues on a database snapshot or to a lesser degree on databases that are marked as read-only. The reason I say is to a lesser degree for read-only databases is because, in theory, a customer can mark a database read-only after creating all possible statistical information and since the data never changes, there will never be stale statistics. However, in reality, it is hard to predict what read-only workload will be executed which can lead to poor execution plan due to missing statistical information. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&lt;b&gt;Example: &lt;/b&gt;Here is one example that illustrates this issue using a Read-Only database&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;create database test&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;go&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;use test&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;go&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;create&amp;nbsp; table t1 (c1 int, c2 int, c3 char (50))&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;go&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;create nonclustered index t1_nci on t1(c1)&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;go&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&lt;i&gt;-- show statistics&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;select * from sys.stats where object_id = object_id('t1')&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;&amp;nbsp;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/2134.stat1.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/2134.stat1.jpg" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;If you look at the stats,&amp;nbsp; it will show 1 statistics that got created as part of creating an index. Note, it shows that&amp;nbsp; there are 0 rows as you would expect.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;-- show the statistics&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&lt;i&gt;dbcc&lt;/i&gt;&lt;i&gt; show_statistics('t1', 't1_nci')&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/4442.stats2.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/4442.stats2.jpg" width="692" height="67" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;&lt;/span&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;Now, let us insert 1 row into the table&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;--insert 1 row&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&lt;i&gt;insert&lt;/i&gt;&lt;i&gt; into t1 values (1,1,'hello')&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;-- show the statistics&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&lt;i&gt;dbcc&lt;/i&gt;&lt;i&gt; show_statistics('t1', 't1_nci')&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&amp;nbsp;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/4555.stats2.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/4555.stats2.jpg" width="650" height="62" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;You will notice that the above statistics does not show that a new row has been inserted. The reason is that statistics are not automatically updated when one or more rows are inserted. The statistics are updated either using an explicit command to update them or automatically if needed by optimizer assuming the compute threshold has been crossed. Let us now do a query that requires statistics on the T1.C1 and then re-check the statistics as follows&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;--do a simple select and show the query plan&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&lt;i&gt;select&lt;/i&gt;&lt;i&gt; c2 from t1 where c1 between 1 and 20&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;-- show the statistics&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&lt;i&gt;dbcc&lt;/i&gt;&lt;i&gt; show_statistics('t1', 't1_nci')&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;Here is the output. You will notice that the statistics now shows that there is now 1 row&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/7802.stat3.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/7802.stat3.jpg" width="722" height="65" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;Another interesting thing to note here is to see the query plan. Note, that optimizer chooses a table scan because it has determined that if there is only 1 row, it is cheaper to scan the table instead of going through the non-clustered index.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/1134.plan1.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/1134.plan1.jpg" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;So far so good. Now, let us insert 10,000 rows into table T1 and then mark the database as ReadOnly.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&lt;i&gt;declare&lt;/i&gt;&lt;i&gt; @i int = 0&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&lt;i&gt;while &lt;/i&gt;&lt;i&gt;(&lt;/i&gt;&lt;i&gt;@i&lt;/i&gt;&lt;i&gt; &amp;lt; 10000)&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&lt;i&gt;begin&lt;/i&gt;&lt;i&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; insert into t1 values (@i, @i+100000, 'sunil')&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set @i = @i + 1&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;end&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&lt;i&gt;ALTER&lt;/i&gt;&lt;i&gt; DATABASE [test] SET&amp;nbsp; READ_ONLY WITH NO_WAIT&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;GO&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;Now let us do the query and see the statistics. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;--do a simple select and show the query plan&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&lt;i&gt;select&lt;/i&gt;&lt;i&gt; c2 from t1 where c1 between 1 and 20&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;&amp;nbsp;&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;"&gt;&lt;i&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;-- show the statistics&lt;/span&gt;&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&lt;i&gt;dbcc&lt;/i&gt;&lt;i&gt; show_statistics('t1', 't1_nci')&lt;/i&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&amp;nbsp;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/3716.stat3.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/3716.stat3.jpg" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;The statistics still shows that there is only 1 row even though we had inserted 10000 rows before marking the database as read-only. The reason is that before the database was marked read-only, we did not issue any query that would have required statistics on column C1 therefore the statistics &lt;span style="text-decoration: underline;"&gt;could not be &lt;/span&gt;updated. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;If you look at the query plan, it still shows the table scan. Clearly, this would be very inefficient plan as it will require a table scan checking each row that meets the search predicate. This is the key problem with read-only database or for that matter with database snapshot for if the statistics were either stale, as in the case here, or missing, optimizer will not be able to generate an efficient plan. The only recourse will be mark the database as R/W and update/create the statistics before marking it read-only but it is not really practical. You could get away with this limitation if you knew in advance all possible queries that will be run against this read-only database or you create the statistics on all columns of all tables. As you can see that this can take significant time for large databases computing statistics that may never be needed. This becomes even more impractical for database snapshot.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;Just for the kicks, let us now mark the database as R/W and re-issue the same query and look at the query plan. As you might have guessed, in this case, the optimizer chose the non-clustered index.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/2112.plan2.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/2112.plan2.jpg" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;Now that you understand the issue, you will be happy to know that you will never run into stale or missing statistics when running queries on readable secondary. For details, please refer to &lt;a href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-making-upto-date-statistics-available-on-readable-secondary-read-only-database-and-database-snapshot.aspx"&gt;http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-making-upto-date-statistics-available-on-readable-secondary-read-only-database-and-database-snapshot.aspx&lt;/a&gt;. As an added bonus, we have applied the same solution for Read-Only database and database snapshot independent of whether these databases are used in the context of AlwaysOn or not. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;Thanks&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana; font-size: medium;" face="Verdana"&gt;Sunil Agarwal&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10250539" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="High Availability" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/High+Availability/" /></entry><entry><title>AlwaysOn: Impact of mapping reporting workload on Readable Secondary to Snapshot Isolation</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-impact-of-mapping-reporting-workload-to-snapshot-isolation-on-readable-secondary.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-impact-of-mapping-reporting-workload-to-snapshot-isolation-on-readable-secondary.aspx</id><published>2011-12-22T22:07:00Z</published><updated>2011-12-22T22:07:00Z</updated><content type="html">&lt;p style="text-align: left;"&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;In my previous blog &lt;a href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-minimizing-blocking-of-redo-thread-when-running-reporting-workload-on-secondary-replica.aspx"&gt;http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-minimizing-blocking-of-redo-thread-when-running-reporting-workload-on-secondary-replica.aspx&lt;/a&gt;, I described how Readable Secondary eliminates potential REDO thread blocking for DML work running on the primary replica by mapping all isolation levels used in the reporting workloads to Snapshot Isolation. While it was essential that we eliminate REDO thread blocking with concurrent DML on secondary replica, it comes at some overheads as described in this blog.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;First thing to understand is that if you do not enable secondary replica for read workload, there is no Snapshot Isolation mapping needed and therefore no additional overhead. Things get interesting when you enable the secondary replica for read workload. You may recall that both Snapshot Isolation and RCSI are based on row versioning. When a row is modified, its previous version is saved in the version store backed by TempDB and a 14 byte pointer is set from the modified row to the versioned row. If the data row gets modified again, the process is repeated. The key point to note here is that newly inserted or modified data rows will have a 14 byte overhead.&amp;nbsp; There are 4 possible scenarios to consider here&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-size: medium;" size="3"&gt;&amp;nbsp;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;b&gt;Secondary replica is not enabled for read workload: &lt;/b&gt;As shown in the figure below, there is no additional overhead on the primary replica. &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="text-align: center;"&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/2742.RS_2D00_NO.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/2742.RS_2D00_NO.jpg" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/5037.RS_2D00_NO.jpg"&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li style="text-align: left;"&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;b&gt;Secondary replica is enabled for read workload:&lt;/b&gt; As you will note in the figure below, a 14 byte overhead is added to the row on the primary and secondary replica. Additionally, a row version is generated by REDO thread on the secondary replica as it processes the UPDATE/DELETE operation from the primary. There are two interesting points to note here. First, the row version is only generated on the secondary replica. Reason is simple. Since the RCSI or SI has not been enabled on the primary replica, there is really no need to have row versions created there. This also means that apart from adding 14 byte overhead, there is not additional impact (i.e. row version generation and TempDB overhead) on the primary replica. Second, we need to add 14 byte overhead to the new/modified rows on the primary because the primary and secondary replicas must be physically identical.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/1778.RS_2D00_ON.jpg"&gt;&lt;img style="margin-right: auto; margin-left: auto; display: block;" border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/1778.RS_2D00_ON.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;span style="font-size: medium;"&gt;Primary replica already has RCSI or SI enabled but no readable secondary: This case is a bit simpler because in this case, the 14 bytes versioning overhead is already added to the data rows independent of the status of secondary replica&lt;/span&gt;. &lt;span style="font-size: medium;"&gt;As shown in the picture below, if secondary replica is not enabled for read workload, there is still a 14 byte overhead on the rows on secondary replica as it must, but there is not row version generation because the read workload has not been enabled&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="text-align: left;"&gt;&lt;span style="font-size: medium;"&gt;&lt;span style="font-family: Calibri;" size="3" face="Calibri"&gt;&lt;/span&gt;&lt;span size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;/span&gt;&lt;/span&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/3583.RCSION_2D00_1.jpg"&gt;&lt;/a&gt;&amp;nbsp;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/8270.rcsiON.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/8270.rcsiON.jpg" /&gt;&lt;/a&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/0763.RCSION.jpg"&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li style="text-align: left;"&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Primary replica already has RCSI or SI enabled with readable secondary: This case is similar to previous configuration except that row versions will need to be generated on the secondary replica as well.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/7026.rcsi_2D00_RSON.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/7026.rcsi_2D00_RSON.jpg" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;There is no change or additional guidance for managing and provisioning for row versioning in this configuration compared to what we recommend for Snapshot Isolation or RCSI. Please refer to Books Online for details of SI and RCSI.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Thanks&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Sunil Agarwal&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10250526" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="High Availability" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/High+Availability/" /></entry><entry><title>AlwaysOn: Minimizing blocking of REDO thread when running reporting workload on Secondary Replica</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-minimizing-blocking-of-redo-thread-when-running-reporting-workload-on-secondary-replica.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-minimizing-blocking-of-redo-thread-when-running-reporting-workload-on-secondary-replica.aspx</id><published>2011-12-22T21:32:00Z</published><updated>2011-12-22T21:32:00Z</updated><content type="html">&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;In earlier blog &lt;a href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-impact-on-the-primary-workload-when-you-run-reporting-workload-on-the-secondary-replica.aspx"&gt;http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-impact-on-the-primary-workload-when-you-run-reporting-workload-on-the-secondary-replica.aspx&lt;/a&gt;, I discussed the impact on RTO in case the REDO thread gets blocked. While designing this feature, it was one of the key usability constraints we had (i.e. to eliminate REDO blocking for common usage scenario). For the un-initiated, here is the problem&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;table border="1" cellspacing="0" cellpadding="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" width="319"&gt;
&lt;p&gt;&lt;b&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Primary Replica&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="319"&gt;
&lt;p&gt;&lt;b&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Secondary Replica&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="319"&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="319"&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Set Isolation level Repeatable Read&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="319"&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="319"&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Begin Tran&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="319"&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="319"&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Select T1.C1 from T1 where T1.C2 = 10&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;-- this takes a S lock on the qualifying data rows&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="319"&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Begin Tran&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="319"&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="319"&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Update T1 set T1.C3 = &amp;lt;some-value&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Where T1.C2 = 10&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;--This statement will not block because the &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;-- S lock is held on the secondary replica, not on&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;-- primary replica&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="319"&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="319"&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Commit&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="319"&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;REDO applies the UPDATE. To do this update, it needs to acquire an X lock on qualifying rows but it will get blocked because the read transaction holds a S lock on the row&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;As you can guess, this&amp;nbsp;will be a common scenario and we need to ensure that REDO thread is not blocked. A blocked REDO thread can compromise the RTO and/or can prevent cleaning up the log on the primary replica. To avoid this blocking completely, all transaction isolation levels used in an application on the secondary replica are mapped transparently to Snapshot Isolation as shown in the table below including the side effects without requiring any changes to the reporting application. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;table border="1" cellspacing="0" cellpadding="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" width="183"&gt;
&lt;p&gt;&lt;b&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Isolation Level &lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="153"&gt;
&lt;p&gt;&lt;b&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Mapped To&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="247"&gt;
&lt;p&gt;&lt;b&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Impact on workload&lt;/span&gt;&lt;/span&gt;&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="183"&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Read Uncommitted (RU)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="153"&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Snapshot Isolation (SI)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="247"&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;None&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="183"&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Read Committed (RC)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="153"&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Snapshot Isolation (SI)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="247"&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;None. Since SI eliminates blocking, if the read-only application depends on blocking, it will not work as expected.&amp;nbsp; However, we do not think that read-only application that will depend on blocking. If it does, then part of the application logic depends on a DML activity somewhere which by definition means that it is not a read-only application. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="183"&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Repeatable Read (RR)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="153"&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Snapshot Isolation (SI)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="247"&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;SI is a higher isolation level than RR in the sense that it eliminates phantoms. We don&amp;rsquo;t think a read-only application will depend on phantoms.&amp;nbsp; If it does, then part of the application logic depends on a DML activity somewhere which by definition means that it is not a read-only application.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="183"&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Snapshot Isolation (SI)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="153"&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Snapshot Isolation (SI)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="247"&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;None&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="183"&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Serializable (SR)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="153"&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Snapshot Isolation (SI)&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="247"&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Transactions running under SI are not guaranteed to be serializable in its most general form. However, for read-only workload, SI offers the same Serializable guarantee.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;You may ask how about locking hints? Well, all locking hints are ignored. While transparent mapping to Snapshot Isolation level should work for most reporting workloads, we recommend you to test your workload before deploying in production. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: medium;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;One concern that you will have is that is the impact of mapping reporting workload to Snapshot Isolation on the primary replica and also how does it change the space usage in TempDB? This is the topic of my next blog&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-impact-of-mapping-reporting-workload-to-snapshot-isolation-on-readable-secondary.aspx"&gt;http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-impact-of-mapping-reporting-workload-to-snapshot-isolation-on-readable-secondary.aspx&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri; font-size: small;" size="3" face="Calibri"&gt;.&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;While mapping reporting workload to snapshot isolation eliminates blocking between DML workload as applied by the REDO thread on the secondary replica and the read or reporting workload, it does not eliminate the potential blocking of REDO thread when it is executing a DDL operation. I will discuss this in more details in a subsequent blog.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: medium;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Thanks&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Sunil Agarwal&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10250513" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="High Availability" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/High+Availability/" /></entry><entry><title>AlwaysOn: Impact on the primary workload when you run reporting workload on the secondary replica</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-impact-on-the-primary-workload-when-you-run-reporting-workload-on-the-secondary-replica.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-impact-on-the-primary-workload-when-you-run-reporting-workload-on-the-secondary-replica.aspx</id><published>2011-12-22T21:23:00Z</published><updated>2011-12-22T21:23:00Z</updated><content type="html">&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;The primary goal of AlwaysOn technology is to provide High Availability for Tier-1 workloads.&amp;nbsp; The ability to leverage secondary replica(s) to offload reporting workloads and database/transaction log backups is useful, but &lt;span style="text-decoration: underline;"&gt;only if it does not compromise High&lt;/span&gt; Availability. This is one of the very common concern/question that I have heard from many of you. &amp;nbsp;In this context, let us evaluate the impact of Active Secondary on the primary replica and workload and what you can do to minimize its impact.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: Calibri; font-size: medium;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;b&gt;Transaction &lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: medium;"&gt;&lt;span size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;b&gt;response time&lt;/b&gt;&lt;/span&gt;&lt;/span&gt;&lt;span size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;: When a transaction is run on the primary replica, its transaction log records are written to log buffer and at the same time are sent to log pool to be sent to the secondary replica (for now, we will consider only 1 secondary replica but the same logic holds for multiple replicas) as shown in the picture below.&amp;nbsp; If the secondary replica is configured in async mode, there is no impact on the transaction response time on the primary. However, if the secondary replica is configured in &amp;lsquo;sync&amp;rsquo; mode, then the primary replica only commits a transaction when the &amp;lsquo;commit&amp;rsquo; log record has been hardened on the secondary&amp;nbsp; replica (it sends an acknowledgement to primary replica).&amp;nbsp; A delay in the acknowledgement from the secondary replica will add to the latency of the transaction.&amp;nbsp; The question that needs to be answered if read workload running on the secondary replica can impact the ACK for the transaction commit? If you look at the secondary replica in the picture below, there are essentially two background threads, one receives the log record over the network and the other hardens that log record. SQL Server gives priority to background threads over user threads (including the ones that are running read workload). This means that&amp;nbsp; at least from CPU perspective, read workload cannot &amp;lsquo;delay&amp;rsquo; the ACK. Other possibility is the IO bottleneck caused by read workload that can slow down the transaction log write but this can only happen if data and transaction log share the same physical disk. In most production deployments, transaction log disk is not shared with data disk(s) so it is a non-issue. Having said that, a network bottleneck can add to the latency of the transaction but then it is unrelated to read workload. As we will see later in this article, if REDO thread is not able to keep with the transaction log generated, it can potentially lead to log to grow which can to the transaction latency. In a well configured and managed system, it is unlikely that the read workload on the primary will add to the transactional latency.&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="text-align: left;"&gt;&lt;span style="font-size: medium;"&gt;&lt;span size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/7217.data-flow.jpg"&gt;&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/4075.data-flow.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/4075.data-flow.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-size: medium;"&gt;&lt;span style="font-family: Calibri;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;span size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;b&gt;Transaction throughput:&lt;/b&gt;&amp;nbsp; Just like the case of transactional response time discussed earlier, there should not be any impact on the transactional throughput with readable secondary except for the unlikely case when either REDO thread is slowed due to concurrent read workload or blocked which can cause transaction log to grow or run out of space. We will discuss when and how a REDO thread can get blocked and what you can do about it. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;b&gt;Recovery Point Objective (RPO):&lt;/b&gt; RPO refers to data loss in case the primary replica fails over to secondary replica. If the secondary replica chosen as the new primary is configured with &amp;lsquo;Sync&amp;rsquo; mode, there cannot be any data loss regardless of the fact that readable secondary has been enabled or not.&amp;nbsp; You may ask what happens if the secondary replica was set in &amp;lsquo;Async&amp;rsquo;. Interestingly, in this case, there will be no additional impact on the RPO (yes, you can lose data as it is possible if you failover to an &amp;lsquo;Async&amp;rsquo; replica) due to running reporting workload on secondary. The reason is that the reporting workload does not interfere with the log transfer path from primary replica to log buffer and its hardening on the secondary replica assuming you log files are mapped to their own storage.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size: medium;"&gt;&lt;span size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;/span&gt;&lt;/span&gt;&lt;span size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;b&gt;Recovery Time Objective (RTO):&lt;/b&gt; &amp;nbsp;The interesting case for us to know here is the time needed to bring the database ONLINE after a fail over to the secondary replica.&amp;nbsp; When the database restarts after a failover, the REDO thread needs to apply the transaction log records from its current position to the end of the transaction log. The more REDO thread has fallen behind in applying the transaction, the longer (i.e. RTO will be larger) it will take to bring the database ONLINE. Now here, the read workload can potentially impact the RTO negatively for the following two reasons&lt;/span&gt;&lt;/span&gt; &lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p style="padding-left: 60px;"&gt;&lt;span style="font-size: medium;"&gt;&lt;span size="3"&gt;o&lt;/span&gt;&amp;nbsp;&amp;nbsp; &lt;span size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;As part of applying log records on the secondary replica,&amp;nbsp; REDO thread reads log records from the log disk and then for each log record, it access the data page(s) to apply the log record.&amp;nbsp; The page access can cause a physical IO if the page is not already in the buffer pool. Now, if read workload is IO bound, it will compete for IO resources with REDO thread thereby slowing it down. &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p style="padding-left: 60px;"&gt;&lt;span style="font-size: medium;"&gt;&lt;span size="3"&gt;o&lt;/span&gt;&amp;nbsp;&amp;nbsp; &lt;span size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;REDO thread can get blocked by read workload. A blocked REDO cannot apply any log record until it is unblocked which can lead to unbounded impact on the RTO. As described in&amp;nbsp; &lt;a href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-minimizing-blocking-of-redo-thread-when-running-reporting-workload-on-secondary-replica.aspx"&gt;http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-minimizing-blocking-of-redo-thread-when-running-reporting-workload-on-secondary-replica.aspx&lt;/a&gt;, the design center of readable secondary has eliminated blocking in common scenario and in the&amp;nbsp;event there is blocking, it provides users tell-tale signs both in the dash-board and in the form of XEvent to warn the user of the situation so that a corrective action can be taken&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: medium;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;With this, I hope that I have answered most common concerns. I look forward to your questions and suggestions &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" size="3" face="Calibri"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Thanks&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Sunil Agarwal&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10250507" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="High Availability" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/High+Availability/" /></entry><entry><title>AlwaysOn: Readable Secondary and data latency</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson.aspx</id><published>2011-12-22T19:58:00Z</published><updated>2011-12-22T19:58:00Z</updated><content type="html">&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;One question that I often get asked is if there will any data latency if you are using 'Sync' replica for read workload. The short answer is yes. Here is the blog that explains it in detail.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;While the reporting workload running on the secondary replica gets to access the data as it is changing on the primary but there is some data latency, typically of the order of seconds. If your reporting or read work load cannot tolerate data latency then there is no choice but to run it on the primary replica. Most customers whom I interacted with indicated that their reporting workload can indeed tolerate data latency of the order of minutes. This is good news because&amp;nbsp;as offloading&amp;nbsp;reporting workload to secondary replica allows customers to leverage their investment in High Availability configuration and deliver better performance to both the primary and read workloads.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;While this is well and good, but there is some misconception that if you enable readable secondary on a &amp;lsquo;sync&amp;rsquo; replica, then there is no data latency. This confusion is rooted in the fact that &amp;lsquo;sync&amp;rsquo; replica must send an ACK to primary replica for the &amp;lsquo;commit&amp;rsquo; log record. Yes, it is true that &amp;lsquo;sync&amp;rsquo; replica guarantees that there is no data loss (i.e. RPO = 0) but it does not guarantee, at least not in SQL-12, that REDO thread running on the secondary replica will apply commit log record before the ACK is sent to the primary. In fact, the REDO thread runs asynchronously to the log hardening logic. So there is indeed some data latency. You may wonder if this data latency is more when you have configured the secondary replica in &amp;lsquo;Async&amp;rsquo; mode. &amp;nbsp;This is a little tricky question to answer. If the network between primary/secondary replicas is not able to keep up (i.e. not enough bandwidth) with the transaction log traffic, the &amp;lsquo;Async&amp;rsquo; replica can fall further behind leading to higher data latency. In &amp;lsquo;sync&amp;rsquo; replica case, the insufficient network bandwidth does not cause higher data latency on the secondary but it can slow down the transaction response time/throughput on the primary. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Another dimension to data latency is when you have configured two or more secondary replicas for read workload. The primary replica sends log records to each of the secondary replicas independently.&amp;nbsp;&amp;nbsp;Within each secondary replica, the log records are applied by REDO thread asynchronously. As you can imagine, this means that each replica is at different point-in-time, though very likely to be close to each other with the result the same query executed on two different readable secondary may return different result. Note, this is not any different than transaction replication with multiple subscribers. Each subscriber will have data at different point-in-time. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;The more interesting question here is what happens if you have scaled out your reporting applications across multiple readable secondary? Let us take an example where AlwaysOn is configured with three replicas on node N1, N2, and N3 and you have two reporting applications App1 and App2. The primary replica in on node N1 while the readable secondary are on node N2 and N3. As indicated earlier, the node N2 and N3 can be at different point-in-time. In this configuration, there are two interesting cases as follows&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Case-1: You scale out your reporting workload by running App1 on node N2 and App2 on node N3. In this case, App1 does not see the data on node N3 therefore not impacted by the fact that the data on N3 could be at different point-in-time. Similar case holds for App2 as well. The down side of this configuration is, for example, if App2 cannot offload work to node N3 if it hits temporary spike in the workload.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Case-2: You scale out both App1 and App2 on node N2 and N3. In other words, each application accesses data both no node N2 and N3 as shown in the figure below for App1.&amp;nbsp; Here all connections for App1 get distributed to node N2 and N3.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;&amp;nbsp;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/0842.ms.jpg"&gt;&lt;img style="margin-right: auto; margin-left: auto; display: block;" border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/0842.ms.jpg" width="472" height="170" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;It is good to know that &amp;nbsp;you have both options available to you for scale out your read workload. &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;I look forward to your experience with offloading read workload to the secondary replica and any feedback to improve the product in future. &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Happy offloading read workload to the secondary replica&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Thanks&lt;br /&gt;Sunil Agarwal&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10250460" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="High Availability" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/High+Availability/" /></entry><entry><title>AlwaysOn: Why there are two options to enable a secondary replica for read workload?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-why-there-are-two-options-to-enable-a-secondary-replica-for-read-workload.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-why-there-are-two-options-to-enable-a-secondary-replica-for-read-workload.aspx</id><published>2011-12-22T18:26:00Z</published><updated>2011-12-22T18:26:00Z</updated><content type="html">&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;In the previous blog &lt;/span&gt;&lt;a href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-setting-up-readable-seconary-replica.aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/AlwaysOn-setting-up-readable-seconary-replica.aspx&lt;/span&gt;&lt;/a&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt; I mentioned that there are two options to configure secondary replica for running read workload. The first option &amp;lsquo;Read-intent-only&amp;rsquo; is used to provide a directive to AlwaysOn secondary replica to accept connections that have the property &lt;/span&gt;&lt;i&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;ApplicationIntent&lt;/span&gt;&lt;/i&gt;&lt;i&gt;=ReadOnly &lt;/i&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;set. The word &amp;lsquo;intent&amp;rsquo; is important here as there is no application check made to guarantee that there are no DDL/DML operations in the application connecting with &amp;lsquo;ReadOnly&amp;rsquo; but an assumption is made that customer will only connect read workloads. &amp;nbsp;If you connect an R/W application using false claim &lt;i&gt;ApplicationIntent&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;i&gt;=ReadOnly,&lt;/i&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;i&gt; &lt;/i&gt;the application will connect successfully but will fail on the first DML/DDL thereby leading to a surprise to the customer.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Specifically, the benefits of &amp;lsquo;Read_Intent Only&amp;rsquo; are&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;b&gt;Ensuring primary workload is not impacted:&lt;/b&gt; &amp;nbsp;The key scenario here is that you have setup a primary replica and one or more secondary replicas. You want to only allow R/W workload to run on the primary replica and prevent any reporting workload to connect to primary to guarantee that the performance of primary workload is not compromised. If primary is set up not to accept connection for read-only workload, then all connections initiated by read-only applications with option &lt;i&gt;(i.e. &lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;i&gt;ApplicationIntent=ReadOnly)&lt;/i&gt; &lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;to primary node will fail.&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;Read-Only-Routing &lt;/span&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/gg471494(v=SQL.110).aspx"&gt;&lt;span style="color: #0000ff; font-family: Calibri; font-size: small;" face="Calibri" size="3" color="#0000ff"&gt;http://msdn.microsoft.com/en-us/library/gg471494(v=SQL.110).aspx&lt;/span&gt;&lt;/a&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt; &amp;nbsp;uses &amp;lsquo;ReadOnly&amp;rsquo; application intent to route the read workload to the readable secondary transparently without requiring user to know which secondary replica allows read workload.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;b&gt;Allowing older clients to work in AlwaysOn configuration without any changes&lt;/b&gt;: One key scenario of AlwaysOn is to allow DBMirror failover partner based clients/applications to work seamlessly in AlwaysOn configuration. The failover partner based protocol works because the connection to SQL Server only succeeds on the primary. &amp;nbsp;When configuring AlwaysOn, you can set secondary replica to disallow connections or to allow connections with &lt;/span&gt;&lt;/span&gt;&lt;i&gt;ApplicationIntent=ReadOnly&lt;/i&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;. If you have configured &amp;nbsp;allows customers to upgrade to AlwaysOn without any changes to existing DBMirror clients while still allowing new clients to take advantage of readable secondary using option &lt;i&gt;(i.e. &lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;i&gt;ApplicationIntent=ReadOnly)&lt;/i&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;. Customer can choose to migrate the failover based client applications to take full advantage of AlwaysOn functionality like multiple replicas at a later point. &lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;&lt;b&gt;Eliminate surprises:&lt;/b&gt; If an R/W application connects to readable secondary by mistake choosing to connect to the physical node instead of using VNN, the connection will succeed but the application will error out when the DML or DDL operation is executed. This will lead to a surprise to customer if s/he did not know that the application was actually connected to a secondary replica. This can happen if application connected to the primary node using physical node-name, not with VNN, and now there was a failover and the primary/secondary replicas switched roles.&amp;nbsp; Read-Intent option will eliminate such surprises as presumably the R/W application &lt;span style="text-decoration: underline;"&gt;would not have set &lt;/span&gt;&lt;i&gt;ApplicationIntent&lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;i&gt;=ReadOnly&lt;/i&gt; &lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;on the connection string. In fact, for R/W there is no need to set &lt;i&gt;ApplicationIntent&lt;/i&gt;.&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Let us take an example. Suppose you have 2 node AlwaysOn configuration with N1 as primary and N2 as secondary. An R/W workload &lt;span style="text-decoration: underline;"&gt;explicitly&lt;/span&gt; connects, without using VNN, to N1. Now a fail over happens and N1 now becomes the secondary but the application does not know about it. It connects to N1 thinking it is a primary leading to a surprise later on when it attempts a DDL or Insert/Delete/Update operation.&lt;/span&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Note, you can &lt;span style="text-decoration: underline;"&gt;only&lt;/span&gt; specify option &lt;i&gt;(i.e. &lt;/i&gt;&lt;/span&gt;&lt;/span&gt;&lt;i&gt;ApplicationIntent=ReadOnly)&lt;/i&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt; with new clients shipped as part of SQL12. If you have an application that uses older client, then you will need to use &amp;lsquo;Yes&amp;rsquo; option for the secondary replica to allow read workloads. With this setting, secondary replica will allow newer clients as well.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Sunil Agarwal&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10250429" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="High Availability" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/High+Availability/" /></entry><entry><title>AlwaysOn: Setting up Readable Seconary Replica</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-setting-up-readable-seconary-replica.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-setting-up-readable-seconary-replica.aspx</id><published>2011-12-22T18:16:00Z</published><updated>2011-12-22T18:16:00Z</updated><content type="html">&lt;div&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;The easiest way to create an availability group and adding replicas is to use the availability group wizard. You can invoke the wizard by right-clicking on 'Availability Groups'. The picture of the explorer window below shows that I have created 1 availability group 'StockPro' with two replicas 'SUNILA03-6PLHSI' (primary) and&amp;nbsp;'SUNILA03-YLZO1U' (secondary).&amp;nbsp;The&amp;nbsp;availability group StockPro contains one database 'hadr_test' but you&amp;nbsp;can have more databases if you want. For now, let us work with this simple example&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/5621.exp.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/5621.exp.jpg" width="595" height="276" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;While working with the wizard, you will be presented a choice to enable one or more secondary replicas for read work load as shown below in the picture. You can choose either &amp;lsquo;Yes&amp;rsquo; or &amp;lsquo;Read-intent only&amp;rsquo; to get the ability to run the read workload on the secondary replica. In the picture below, I have chosen &amp;lsquo;Yes&amp;rsquo; option for replica running on instance &amp;lsquo;SUNILA03-YLZO1U&amp;rsquo;. A later blog &amp;lt;link&amp;gt; describes the difference between the two options. &lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="http://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/2134.replica_2D00_choices.jpg"&gt;&lt;img border="0" alt="" src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-00-63-96/2134.replica_2D00_choices.jpg" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Once you have configured the availability group, you can connect to the secondary replica either explicitly or using VNN and run your reporting workload. I will talk about VNN in a later blog.&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Calibri; font-size: small;" face="Calibri" size="3"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Thanks&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;" size="3"&gt;&lt;span style="font-family: Calibri;" face="Calibri"&gt;Sunil Agarwal&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10250426" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="High Availability" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/High+Availability/" /></entry><entry><title>AlwaysOn: Value Proposition of Readable Secondary</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-value-proposition-of-readable-secondary.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/12/22/alwayson-value-proposition-of-readable-secondary.aspx</id><published>2011-12-22T17:34:00Z</published><updated>2011-12-22T17:34:00Z</updated><content type="html">&lt;p&gt;This series of blogs is targeting AlwaysON Readable Secondary. Please refer to &lt;a href="http://blogs.msdn.com/b/sqlalwayson/archive/tags/availability+group/"&gt;http://blogs.msdn.com/b/sqlalwayson/archive/tags/availability+group/&lt;/a&gt;for other blogs in the related area&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;Readable Secondary is part of AlwaysOn suite of functionality available in SQL12 release. It allows customers to leverage their investment in High Availability hardware for offloading read workload such as reporting to one or more secondary replicas. Offloading reporting workload to secondary replica frees up resources on the primary node for primary application workload to achieve higher throughput and at the same time allowing resources on secondary replica to reporting workload to deliver higher performance. So it is a win-win situation both for primary and reporting workload.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;Before we proceed further, it will be useful to look at the technology choices available to SQL customers today to offload read workload. This will provide us a good insight into the unique value proposition of Readable Secondary. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;SQL Server 2008 offers following four High Availability choices to customers&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;&lt;b&gt;Failover Clustering&lt;/b&gt;: This is shared disk environment and since only one node can have access to the database at one time, the second node cannot be used offloading read workload. The customers can increase the utilization of the HA hardware by deploying Active-Active cluster but not for offloading the read workload.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;&lt;b&gt;Database Mirroring:&lt;/b&gt; It is used for HA but it also provides read access to the data by creating a database snapshot on the mirror. The read workload can then run against the database snapshot. While many customers have used database snapshot for running reporting workload but it has some challenges as follows &lt;/span&gt;&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;The name of the database in database snapshot is different so if your application has hard coded database name, it will require modifications. &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;It is a static snapshot of the database. If an application needs to access the data that has changed since, a new database snapshot needs to be created with a new name unless you drop the old database snapshot. In other words, customers want accessing data in near real-time but it is hard, if not impossible, to achieve using database snapshot. However, if a reporting workload processes, for example, last week&amp;rsquo;s data, you can create a database snapshot on the weekly boundary and run your reporting workload.&lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;Performance: Database snapshot employs copy on-write technology. When a database page is first modified after creating a database snapshot, a copy of the page made. This can significant overhead if there are multiple database snapshot. Also, during query processing it randomizes IO&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;&lt;b&gt;Log Shipping:&lt;/b&gt; Log shipping can be thought of as manual database mirroring with the fail over time dependent on how frequently log backups are done and restored on the log shipped node. DBAs can open the Log Shipping destination for read workload with the added limitation that log backup cannot be restored while the Log Shipping destination is open for read workload. This can put DBAs into a fix as they need to choose between HA and the read workload. If they reduce the frequency of the log backup restores, it will increase the RTO (recovery time objective) and if the increase the frequency, they will need kill all currently running queries.&amp;nbsp; This does not work for many customers especially if they have long running queries as they may never run to completion due to HA constraints. One can get around this by adding one more log shipping destination (i.e. more hardware and software license cost) where log backups can be restored at a lesser frequency assuming that we will be able to keep up with the log. &lt;/span&gt;&lt;/li&gt;
&lt;li&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;&lt;b&gt;Replication:&lt;/b&gt; This is commonly deployed solution for HA and for offloading read workload. &amp;nbsp;One of the key benefit of replication is that customer can create reporting workload specific indexes on the subscriber node. The challenges here are (a) may require schema changes (e.g. unique key) (b) not very suitable for high transaction throughput.&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;Readable Secondary addresses the challenges outlined with previous High Availability solutions with the exception of the ability to create reporting workload specific index(s) similar to the ones allowed by transaction replication. Readable Secondary allows read workload to run concurrently with the recovery thread that is applying the transactional logs from the primary. &amp;nbsp;This allows reporting workload to access the data changes &amp;ldquo;live&amp;rdquo; as they occur on the primary replica and subsequently applied by the REDO thread on the secondary replica. The reporting workload is run without any changes as it is the same database on secondary replica as it was on the primary.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;In the subsequent blogs I will describe how to setup readable secondary, configure application connectivity and ensuring predictable performance both for primary and secondary workloads&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;&lt;/span&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;Thanks&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-family: Verdana;" face="Verdana"&gt;Sunil Agarwal&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10250408" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="High Availability" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/High+Availability/" /></entry><entry><title>SQL Databases on File Shares - It's time to reconsider the scenario.</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/10/18/sql-databases-on-file-shares-it-s-time-to-reconsider-the-scenario.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/10/18/sql-databases-on-file-shares-it-s-time-to-reconsider-the-scenario.aspx</id><published>2011-10-18T23:06:10Z</published><updated>2011-10-18T23:06:10Z</updated><content type="html">&lt;p style="text-align: left;"&gt;For those who have been around databases for any length of time, the idea of putting a database that you care about from either a reliability or performance perspective on an&amp;nbsp; (SMB &amp;ndash; Server Message Block) file share seems like a crazy idea, but recent developments have made SMB-based file shares a very viable platform for production SQL Server databases with some very interesting advantages.&lt;/p&gt;
&lt;p&gt;Historically, the perspective has been:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;File shares are slow.&lt;/li&gt;
&lt;li&gt;The connections to the share may be unreliable.&lt;/li&gt;
&lt;li&gt;The storage behind the file share may be flaky.&lt;/li&gt;
&lt;li&gt;SMB consumes large amounts of CPU if you can get it running fast enough.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Over the past few years, all of these conditions have changed, and in particular the work which has been done on the 2.2 revision to the SMB protocol has produced some stunning results.&lt;/p&gt;
&lt;p&gt;So let&amp;rsquo;s look at these one by one:&lt;/p&gt;
&lt;h3&gt;&lt;b&gt;File Shares are slow&lt;/b&gt;&lt;/h3&gt;
&lt;p&gt;There are two components to this one:&lt;/p&gt;
&lt;p&gt;The raw speed of Ethernet vs&amp;nbsp; Fibrechannel and the speed/efficiency of the SMB protocol.&lt;/p&gt;
&lt;p&gt;The transport layer has seen a very significant improvement in recent years. &amp;nbsp;Where at one point Ethernet was orders of magnitude slower than Fibrechannel, this is no longer the case.&amp;nbsp; Current commodity Ethernet is running up to 10 gigabit with 40 gigabit being tested, and on the near horizon.&amp;nbsp; This will put Ethernet on par with Fibrechannel from a bit-rate perspective, and the projections are that the two technologies will leap-frog each other from here out with neither one being a clear leader.&lt;/p&gt;
&lt;p&gt;On the protocol front, the original SMB 1.x protocol was chatty, inefficient, and slow.&amp;nbsp; Over the last couple of years, the Windows file server team, while developing the 2.2 version of the protocol, has been using SQL Server, with a TPCC workload, as one of the performance benchmarks.&lt;/p&gt;
&lt;p&gt;The benchmark configuration was to take a fibre-attached array, connect it to a server and run TPCC.&amp;nbsp;&lt;br /&gt;Then add an identical server connected to the first with a single 1Gb link, and run the TPCC database on the new server with the original server functioning as a file server.&lt;/p&gt;
&lt;p&gt;When they started, TPCC over a file server ran at ~ 25% the speed of direct-attach storage.&amp;nbsp; The team discovered several performance&amp;nbsp; problems in the stack, but one particular bug on the client side made a stunning difference.&amp;nbsp; The current results are that TPCC running over an SMB link as described above performs at &lt;b&gt;97% &lt;/b&gt;of the speed of direct-attach.&amp;nbsp; That is a stunning result, and one which is not limited to Windows file servers since the fix is on the client side.&lt;/p&gt;
&lt;p&gt;So now, we have an SMB implementation running at speeds comparable to a fibre-attached array.&lt;/p&gt;
&lt;h3&gt;&lt;b&gt;Connections to the share may be unreliable&lt;/b&gt;&lt;/h3&gt;
&lt;p&gt;Again, there are multiple parts to this one.&amp;nbsp; One aspect of this is that the underlying networking hardware has gotten very much more reliable in recent years.&amp;nbsp; Consumers and enterprises alike just wouldn&amp;rsquo;t put up with flaky network connections these days.&amp;nbsp; The popularity of FCoE (Fibre Channel over Ethernet) is an indicator of how much confidence of Ethernet as a storage transport has grown.&lt;/p&gt;
&lt;p&gt;The second aspect to this one again comes back to the work done in the 2.2 version of the SMB protocol.&amp;nbsp;&lt;br /&gt;With this version, SMB has a number of resiliency features built in.&amp;nbsp; If a link was to momentarily drop, in the past the connection would be lost and the file handle broken.&amp;nbsp; With the 2.2 version of the protocol, the link is automatically re-established and the application never sees the event other than a momentary stall in outstanding IO.&lt;/p&gt;
&lt;p&gt;If we take the configuration a step further, the file server itself can be clustered, and now has the capability to failover a share from one file server to the other without losing handle state.&amp;nbsp; To clarify, SQL Server running an active workload can have the file server hosting the database files fail over, planned or unplanned, and SQL sees only a momentary drop in IO rates.&lt;/p&gt;
&lt;h3&gt;&lt;b&gt;The storage behind the file server may be flaky or unreliable.&lt;/b&gt;&lt;/h3&gt;
&lt;p&gt;While it is always possible to put together an unreliable server, the tools now exist to incorporate very sophisticated reliability features right in the box.&amp;nbsp; Particularly with the advent of Windows 8 features recently announced, we have a pretty good toolset native in the OS.&amp;nbsp; We can create pools of storage which can be dynamically expanded.&amp;nbsp; Pools can be assigned a variety of RAID levels.&amp;nbsp; Many of the features which were previously only available in Fibre-attached arrays are now available with direct-attached storage on a Windows File Server.&amp;nbsp; When you add in the capability for failover and scale-out clustering, the reliability becomes very impressive.&lt;/p&gt;
&lt;h3&gt;&lt;b&gt;SMB consumes large amounts of CPU if you can get it going fast enough.&lt;/b&gt;&lt;/h3&gt;
&lt;p&gt;This is actually a painful aspect of Ethernet which has hurt iSCSI as well as SMB and other protocols.&lt;/p&gt;
&lt;p&gt;A recent transport development is the rDMA transport, which enables data to flow directly from the network wire into user space, without being copied through kernel memory buffers.&amp;nbsp;&lt;br /&gt;This produces a huge reduction in CPU utilization at high data rates.&amp;nbsp; How much?&amp;nbsp;&lt;br /&gt;I&amp;rsquo;ve seen an Infiniband-based SMB connection sustaining&amp;nbsp; &amp;gt; 3 gigaBYTES per second, while consuming around 7% CPU, using SQLIO 512K writes as a workload.&amp;nbsp; We&amp;rsquo;ve seen prototype units performing at twice that rate in the lab.&lt;/p&gt;
&lt;h3&gt;&lt;b&gt;Additional benefits&lt;/b&gt;&lt;/h3&gt;
&lt;p&gt;Now that we&amp;rsquo;ve discussed why the factors which previously were blockers no longer are, let&amp;rsquo;s discuss some of the additional benefits:&lt;/p&gt;
&lt;h3&gt;&lt;b&gt;Manageability&lt;/b&gt;&lt;/h3&gt;
&lt;p&gt;Consider the steps required for a DBA to move a database from one server to another:&lt;/p&gt;
&lt;table style="width: 432px; height: 479px;" border="1" cellspacing="0" cellpadding="0"&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td valign="top" width="213"&gt;
&lt;p align="center"&gt;&lt;b&gt;SAN&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;&lt;b&gt;SMB&lt;/b&gt;&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;Take database offline/detach&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;Take database offline/detach&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;File request to remap LUNs&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;Database is attached to new server using UNC path&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;Meet with storage admin&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;Database is brought online&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;LUNs are unmapped from original server&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;LUNs are mapped to new server&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;LUNs get discovered and mounted on new server&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;Database is attached to new server&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;Database is brought online&lt;/p&gt;
&lt;/td&gt;
&lt;td valign="top" width="213"&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Additionally, you have one set of tools for configuring storage, as opposed to separate tooling for each SAN vendor which you use.&lt;/p&gt;
&lt;h3&gt;&lt;b&gt;Cost&lt;/b&gt;&lt;/h3&gt;
&lt;p&gt;Cost is always a concern, and with the capabilities which this platform brings to bear, we can accomplish what previously has required a much more expensive solution, for a fraction of the cost without sacrificing performance, reliability or manageability.&lt;/p&gt;
&lt;h3&gt;&lt;b&gt;Example&lt;/b&gt;&lt;/h3&gt;
&lt;p&gt;As one example of the whole package, one reference configuration for a SQL deployment had originally been configured with Infiniband for communications, and several small SAN arrays &amp;ndash; one per server in a rack.&amp;nbsp; By converting that configuration to a single clustered file server, the total cost of the solution was dropped dramatically:&amp;nbsp; ~$50,000 in FibreChannel hardware was saved, and the cost savings in moving from multiple FC arrays to the clustered fileserver was very substantial.&amp;nbsp;&lt;br /&gt;The kicker though was that the performance of the solution was better than the original configuration, as previously it had bottlenecked on the&lt;br /&gt;Storage Processors in the arrays.&lt;/p&gt;
&lt;p&gt;So, the overall cost is substantially lower, the required features are delivered, and the performance is improved.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What&amp;rsquo;s not to like?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10227232" width="1" height="1"&gt;</content><author><name>Kevin Farlee [MSFT]</name><uri>http://blogs.msdn.com/kfarlee/ProfileUrlRedirect.ashx</uri></author><category term="SQL Server IO" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/SQL+Server+IO/" /><category term="General" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/General/" /><category term="SMB" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/SMB/" /></entry><entry><title>SQL Server Team is hiring</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/05/17/sql-server-team-is-hiring.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/05/17/sql-server-team-is-hiring.aspx</id><published>2011-05-17T21:16:27Z</published><updated>2011-05-17T21:16:27Z</updated><content type="html">&lt;p&gt;Hello to you all,&lt;/p&gt;
&lt;p&gt;The SQL Server team is hiring arcoss all test, dev and PM discipline. If&amp;nbsp; you or someone you know is interested, please do apply for the job using the&amp;nbsp;link with job postings below. Look forward to hearing from some of you.&lt;/p&gt;
&lt;p&gt;Thanks &lt;/p&gt;
&lt;p&gt;Sunil Agarwal&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;"SQL Server is one of the most important products at Microsoft and is the core on which our future server and storage technology will be built. Over the past decade we have experienced tremendous growth making us one of the largest businesses at Microsoft -- and this is still only the beginning. The importance of data continues to grow. Most applications being built today are data-centric. The ability to efficiently store, query, and share data at a low cost with built-in high-availability and flexible compute/storage capacity is a core competitive advantage for today's businesses. &lt;/p&gt;
&lt;p&gt;The resurgence of Cloud computing is driving a major disruption to technology that is bringing broad changes to the technology landscape. With the &lt;b&gt;current SQL Azure database-as-a-service offering&lt;/b&gt;, the SQL Server group is well positioned to become the dominant database-platform-as-a-service player. Competition is fierce and the time frames are aggressive.&amp;nbsp; SQL Server is uniquely positioned to provide a friction-free and compatible database experience spanning both on-premise and cloud platforms. Our products will be offered as regular box software and also as software-as-a-service through our SQL Azure service.&amp;nbsp;&amp;nbsp; This choice creates a significant competitive advantage as customers can retain their existing skill-set and extend existing applications over SQL Azure to reap the benefits of the cloud platform. If you are excited about being part of this revolution that not only brings full-fledged database technology to the cloud, but also enables new kinds of data-centric application paradigms, then this is just the place for you. See &lt;a target="_blank" href="http://www.microsoft.com/windowsazure/sqlazure"&gt;www.microsoft.com/windowsazure/sqlazure&lt;/a&gt; for more details on the SQL Azure platform.&lt;/p&gt;
&lt;p&gt;Joining SQL Server is a fantastic opportunity to work with some of the best engineers at Microsoft tackling challenging problems in a product that is a key driver to Microsoft's business. SQL Server fosters a supportive and productive work environment. SQL Server is known for providing growth avenues for developers to reach the highest levels. The team culture values engineering quality, technical excellence, and grass roots innovation. Every day you will be working on features that are used by millions of customers to power their businesses.&lt;/p&gt;
&lt;p&gt;The SQL Server team is looking to hire a range of Individual Contributors and Leads across levels, disciplines and focus areas. If this interests you, please check out the job listing at &lt;a href="http://www.microsoft-careers.com/go/SQL-Server-Jobs/194689/?utm_source=emailcampaign&amp;amp;utm_campaign=Blog_Blog_Name_ST_SQL_US_jennav_SSEngine_Blog_Post_Strategy_5.11.11"&gt;here&lt;/a&gt;, and apply to the positions that match your passion and experience."&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10165565" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author></entry><entry><title>Data Compression and Fill Factor</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/05/12/data-compression-and-fill-factor.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/05/12/data-compression-and-fill-factor.aspx</id><published>2011-05-12T19:20:00Z</published><updated>2011-05-12T19:20:00Z</updated><content type="html">&lt;p&gt;Recently, I was asked this question "If I have a compressed index and I rebuild it with fill factor 70%, do I actually get any fill factor? &amp;nbsp;Or does compression take away the empty space?". The answer to this question is 'yes'. In fact all index options listed below available with data compression (both for ROW and PAGE) &lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&amp;lt;relational_index_option&amp;gt; ::=&lt;br /&gt;{&lt;br /&gt;PAD_INDEX = { ON | OFF }&lt;br /&gt;| FILLFACTOR = fillfactor&lt;br /&gt;| SORT_IN_TEMPDB = { ON | OFF }&lt;br /&gt;| IGNORE_DUP_KEY = { ON | OFF } | STATISTICS_NORECOMPUTE = { ON | OFF }&lt;br /&gt;| DROP_EXISTING = { ON | OFF }&lt;br /&gt;| ONLINE = { ON | OFF }&lt;br /&gt;| ALLOW_ROW_LOCKS = { ON | OFF }&lt;br /&gt;| ALLOW_PAGE_LOCKS = { ON | OFF }&lt;br /&gt;| MAXDOP = max_degree_of_parallelism&lt;br /&gt;Here is a simple script to show the 'fill factor" experiment&lt;br /&gt;create table t1 (c1 int, c2 char (1000))&lt;br /&gt;go&lt;/p&gt;
&lt;p&gt;-- load 10000 rows&lt;br /&gt;declare @i int&lt;br /&gt;select @i = 0&lt;br /&gt;while (@i &amp;lt; 10000) &lt;br /&gt;begin&lt;br /&gt;insert into t1 values (@i, REPLICATE ('1', 500))&lt;br /&gt;set @i = @i + 1&lt;br /&gt;end&lt;/p&gt;
&lt;p&gt;-- create index with 40% fill factor&lt;br /&gt;create clustered index ci on t1 (c1) with (fillfactor = 40)&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;-- run this DMV query to get the info on fill factor, number of pages&lt;br /&gt;select max_record_size_in_bytes,page_count, avg_page_space_used_in_percent&lt;br /&gt;from sys.dm_db_index_physical_stats (db_id('foo'),&amp;nbsp;&amp;nbsp;&amp;nbsp;object_id('foo.t1'),&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;null, null, 'DETAILED')&lt;br /&gt;where object_name (object_id) like 't1'&lt;/p&gt;
&lt;p&gt;max_record_size_in_bytes&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; page_count&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; avg_page_space_used_in_percent&lt;br /&gt;------------------------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; --------------------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ------------------------------&lt;br /&gt;1011&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;2500&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; 50.0370644922165&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;-- enable ROW compression.Note, it will maintain the fill factor or 40%&lt;br /&gt;alter index ci on t1 rebuild&amp;nbsp; &lt;br /&gt;&amp;nbsp;with (&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data_compression = ROW)&lt;/p&gt;
&lt;p&gt;-- The output below shows almost &amp;frac12; the page couns but fill factor is around 40%&lt;/p&gt;
&lt;p&gt;max_record_size_in_bytes&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; page_count&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; avg_page_space_used_in_percent&lt;br /&gt;------------------------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;--------------------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -----------------------------&lt;br /&gt;511&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1430&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 44.2960588089943&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;-- enable PAGE compression. Note, it will maintain the fill factor or 40%&lt;br /&gt;alter index ci on t1 rebuild&amp;nbsp; &lt;br /&gt;&amp;nbsp;with (&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; data_compression = PAGE)&lt;/p&gt;
&lt;p&gt;max_record_size_in_bytes&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; page_count&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; avg_page_space_used_in_percent&lt;br /&gt;------------------------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;--------------------&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;------------------------------&lt;br /&gt;9&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; 42&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 38.6835680751174&lt;/p&gt;
&lt;p&gt;Thanks&lt;br /&gt;Sunil Agarwal&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10163948" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="Data Compression" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/Data+Compression/" /></entry><entry><title>Concurrency Series: My application was running fine yesterday but why is it blocking today? </title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/02/20/concurrency-series-my-application-was-running-fine-yesterday-but-why-is-it-blocking-today.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/02/20/concurrency-series-my-application-was-running-fine-yesterday-but-why-is-it-blocking-today.aspx</id><published>2011-02-20T22:40:52Z</published><updated>2011-02-20T22:40:52Z</updated><content type="html">&lt;p&gt;Please refer to &lt;a href="http://blogs.msdn.com/b/sqlcat/archive/2011/02/20/concurrency-series-my-application-was-running-fine-yesterday-buy-why-is-it-blocking-today.aspx"&gt;http://blogs.msdn.com/b/sqlcat/archive/2011/02/20/concurrency-series-my-application-was-running-fine-yesterday-buy-why-is-it-blocking-today.aspx&lt;/a&gt;&amp;nbsp;for details. Cross-referencing here&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Sunil Agarwal&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10131974" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="Concurrency" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/Concurrency/" /></entry><entry><title>Concurrency Series: Minimizing blocking between updaters</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/02/20/concurrency-series-minimizing-blocking-between-updaters.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/02/20/concurrency-series-minimizing-blocking-between-updaters.aspx</id><published>2011-02-20T22:39:19Z</published><updated>2011-02-20T22:39:19Z</updated><content type="html">&lt;p&gt;Please refer to &lt;a href="http://blogs.msdn.com/b/sqlcat/archive/2011/02/20/concurrency-series-minimizing-blocking-between-updaters.aspx"&gt;http://blogs.msdn.com/b/sqlcat/archive/2011/02/20/concurrency-series-minimizing-blocking-between-updaters.aspx&lt;/a&gt;&amp;nbsp;for details. Cross referencing my post.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Sunil Agarwal&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10131973" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="Concurrency" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/Concurrency/" /></entry><entry><title>Concurrency Series: Why do I get blocked when no one has locked the row(s) being queried?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/02/20/concurrency-series-why-do-i-get-block-when-no-one-has-locked-the-row-s-being-queried.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/02/20/concurrency-series-why-do-i-get-block-when-no-one-has-locked-the-row-s-being-queried.aspx</id><published>2011-02-20T22:37:00Z</published><updated>2011-02-20T22:37:00Z</updated><content type="html">&lt;p&gt;Please refer to &lt;a href="http://blogs.msdn.com/b/sqlcat/archive/2011/02/20/concurrency-series-why-do-i-get-block-when-no-one-has-locked-the-row-s-being-queried.aspx"&gt;http://blogs.msdn.com/b/sqlcat/archive/2011/02/20/concurrency-series-why-do-i-get-block-when-no-one-has-locked-the-row-s-being-queried.aspx&lt;/a&gt;&amp;nbsp;for details&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Sunil Agarwal&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10131972" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="Concurrency" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/Concurrency/" /></entry><entry><title>Concurrency Series: Why do I get blocking when I use Read Uncommitted isolation level or use NOLOCK hint?</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/02/20/concurrency-series-why-do-i-get-blocking-when-i-use-read-uncommitted-isolation-level-or-use-nolock-hint.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/02/20/concurrency-series-why-do-i-get-blocking-when-i-use-read-uncommitted-isolation-level-or-use-nolock-hint.aspx</id><published>2011-02-20T22:36:19Z</published><updated>2011-02-20T22:36:19Z</updated><content type="html">&lt;p&gt;I posted this in SQLCAT blog site. This post provides reference to&amp;nbsp;&lt;a href="http://blogs.msdn.com/b/sqlcat/archive/2011/02/20/concurrency-series-why-do-i-get-blocking-when-i-use-read-uncommitted-isolation-level-or-use-nolock-hint.aspx"&gt;http://blogs.msdn.com/b/sqlcat/archive/2011/02/20/concurrency-series-why-do-i-get-blocking-when-i-use-read-uncommitted-isolation-level-or-use-nolock-hint.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Sunil Agarwal&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10131971" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="Concurrency" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/Concurrency/" /></entry><entry><title>Concurrency Series: Basics of Transaction Isolation Levels</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/02/20/concurrency-series-basics-of-transaction-isolation-levels.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2011/02/20/concurrency-series-basics-of-transaction-isolation-levels.aspx</id><published>2011-02-20T22:34:22Z</published><updated>2011-02-20T22:34:22Z</updated><content type="html">&lt;p&gt;Please refer to the blog &lt;a href="http://blogs.msdn.com/b/sqlcat/archive/2011/02/20/concurrency-series-basics-of-transaction-isolation-levels.aspx"&gt;http://blogs.msdn.com/b/sqlcat/archive/2011/02/20/concurrency-series-basics-of-transaction-isolation-levels.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Sunil Agarwal&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10131970" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="Concurrency" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/Concurrency/" /></entry><entry><title>Concurrency Series: Common Concurrency Issues with Applications</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2010/06/04/common-concurrency-issues-with-applications.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2010/06/04/common-concurrency-issues-with-applications.aspx</id><published>2010-06-04T20:13:00Z</published><updated>2010-06-04T20:13:00Z</updated><content type="html">&lt;p&gt;&lt;span style="font-size: small;"&gt;As part of my role as a program manager in SQL Server Engine, one of the areas I am reponsible for&amp;nbsp;is the concurrency related features in SQL Server. If&amp;nbsp;you have been&amp;nbsp;involved with database applications as a develeoper or&amp;nbsp;as a DBA in keeping&amp;nbsp;the application running,&amp;nbsp;I am sure you&amp;nbsp;will agree that blocking is one of the most interesting and challenging problems. I have seen cases where an application was running fine yesterday but it starts blocking suddenly. The culprits can be many such as&amp;nbsp;lock escalation or query plan changes or just increased seasonal&amp;nbsp;user workload. &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;If you look at the concurrency theory, it is actually quite simple for most part. SQL Standard defines 4 isolation levels (read uncommitted, read committed, repeatable read and serializable). While SQL Standard does not dictate how these isolation levels need to be implemented, but most common&amp;nbsp;implementation is to build them using 'Locks'. SQL Server provides you a choice using either the lock based or row versioning based (non blocking)&amp;nbsp;implementation for the 'default' read committed isolation level.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;Each vendor defines&amp;nbsp;different lock types and corresponding lock compatibility matrix. The locking modes/compatibility matrix&amp;nbsp;is intutive in most cases. For example, it is easy to understand&amp;nbsp;that two transactions that need to modify&amp;nbsp;the same row need to be serialized (i.e. one transaction must complete before other is allowed to modify the row).&amp;nbsp;You&amp;nbsp;may&amp;nbsp;ask 'oh really?' what if one transaction is modifying column1 and other&amp;nbsp;transaction is modifying column2, we should allow them to proceeed?&amp;nbsp;This can be possible&amp;nbsp;if locking granularity at a column level is supported but&amp;nbsp;that won't come&amp;nbsp;for&amp;nbsp;free&amp;nbsp;(i.e. takes more resources and complexity). As you can guess, there is trade off betweek concurrrency and resource consumption. If you use lower locking&amp;nbsp;granularity, you will get more concurrency but with more overhead and possibly more deadlocks.&amp;nbsp; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;Before I get buried in these details, I want to spell out the modest goal of my subsequent blog(s) on this topic. I want to take some very simple examples to illustrate the common blocking issues I have seen with customers and suggest some ways how these can be addressed. &lt;span style="text-decoration: underline;"&gt;I will try to propose solutions, when possible, that don't require any application changes&lt;/span&gt;. But clearly, this is not always possible. Hopefully once we are done with the series of blogs on concurrency, I will consolidate the learning into some general guidelines.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;Stay tuned&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;Thanks&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="font-size: small;"&gt;Sunil Agawal&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10020226" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="Concurrency" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/Concurrency/" /></entry><entry><title>Minimal logging and MERGE statement</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2010/06/03/minimal-logging-and-merge-statement.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2010/06/03/minimal-logging-and-merge-statement.aspx</id><published>2010-06-03T17:23:00Z</published><updated>2010-06-03T17:23:00Z</updated><content type="html">&lt;p&gt;In my earlier blog &lt;a href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2008/10/24/new-update-on-minimal-logging-for-sql-server-2008.aspx"&gt;http://blogs.msdn.com/b/sqlserverstorageengine/archive/2008/10/24/new-update-on-minimal-logging-for-sql-server-2008.aspx&lt;/a&gt;, we discussued how we can get minimal logging using TF-610 when using TSQL INSERT statement. Interestingly, you can get minimal logging when using MERGE statement as well. Here is a simple example to illustrate it.&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;use bulktest&lt;br /&gt;go&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;alter database bulktest set recovery SIMPLE&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;-- enable the trace flag 610&lt;br /&gt;dbcc traceon (610, -1)&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;&lt;/span&gt;&lt;span style="color: #0000ff;"&gt;&amp;nbsp;-- create the staging table&lt;br /&gt;create table t_staging (c1 int, c2 int, c3 char (100), c4 char(1000))&lt;br /&gt;go&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;-- load 10000 rows into the staging table&lt;br /&gt;declare @i int&lt;br /&gt;select @i = 0&lt;br /&gt;while (@i &amp;lt; 10000) &lt;br /&gt;begin&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; insert into t_staging values (@i, @i+10000, 'indexkey', 'hello')&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; select @i= @i + 1&lt;br /&gt;end&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;-- create the target table with clustered index&lt;br /&gt;DROP TABLE t_target&lt;br /&gt;GO&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;create table t_target (c1 int,&amp;nbsp; c2 int, c3 char(100), c4 char(1000))&lt;br /&gt;go&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;create clustered index ci on t_target(c1)&lt;br /&gt;go&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;-- clean up the log&lt;br /&gt;while @@trancount &amp;gt; 0 rollback&lt;br /&gt;checkpoint&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;--&amp;nbsp;execute a merge statement under a transaction&lt;br /&gt;BEGIN TRAN&lt;br /&gt;MERGE INTO t_target&amp;nbsp; AS Target using t_staging as Source&lt;br /&gt;ON Target.c1 = Source.c1&lt;br /&gt;when matched then&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; update set c4 = source.c4&lt;br /&gt;when not matched by target then&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; insert (c1, c2, c3, c4) values (c1, c2, c3, c4) ;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;-- Now look at the top 20 log records&lt;br /&gt;select top&amp;nbsp;20 operation,context, [log record fixed length], [log record length], AllocUnitId, AllocUnitName &lt;br /&gt;from fn_dblog(null, null) &lt;br /&gt;where allocunitname='dbo.t_target.ci'&lt;br /&gt;order by [Log Record Length] Desc&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;-- here is the output&lt;/p&gt;
&lt;p&gt;&lt;img src="http://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/CommunityServer-Blogs-Components-WeblogFiles/00-00-00-63-96/0247.minimal_2D00_logging_2D00_merge.jpg" border="0" /&gt;&lt;/p&gt;
&lt;p&gt;You can see that after the first data page worth of rows, the rest of the inserts are minimally logged.&amp;nbsp;&amp;nbsp;The same can be done&amp;nbsp;if the target table was a HEAP but in this case, you will need to use TABLOCK hint as&amp;nbsp;shown here&lt;/p&gt;
&lt;p&gt;&lt;span style="color: #0000ff;"&gt;MERGE INTO t_target with (TABLOCK) AS Target using t_staging as Source&lt;br /&gt;ON Target.c1 = Source.c1&lt;br /&gt;when matched then&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; update set c4 = source.c4&lt;br /&gt;when not matched by target then&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; insert (c1, c2, c3, c4) values (c1, c2, c3, c4) ;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;This will work even when you have non-empty target table when the inserted rows go to newly allocated pages. &lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Sunil Agarwal&lt;br class="_mce_marker" /&gt;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10019564" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="Bulk Import/Export" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/Bulk+Import_2F00_Export/" /></entry><entry><title>Backup compression and Virtual Device Interface (VDI)</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2010/02/21/backup-compression-and-virtual-device-interface-vdi.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2010/02/21/backup-compression-and-virtual-device-interface-vdi.aspx</id><published>2010-02-21T23:07:00Z</published><updated>2010-02-21T23:07:00Z</updated><content type="html">&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 11pt; mso-bidi-font-family: Arial"&gt;People often ask if they can get native SQL Server&amp;nbsp;backup compression using VDI interface. The simple answer is&amp;nbsp;'yes' but there are&amp;nbsp;few things&amp;nbsp;you need&amp;nbsp;to be aware of as described below. You can get details&amp;nbsp;on VDI&amp;nbsp;by clicking&amp;nbsp;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 11pt; mso-bidi-font-family: Arial; mso-ansi-language: EN-US; mso-fareast-font-family: Calibri; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-fareast-theme-font: minor-latin"&gt;&lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=416f8a51-65a3-4e8e-a4c8-adfe15e850fc&amp;amp;DisplayLang=en#Overview" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyID=416f8a51-65a3-4e8e-a4c8-adfe15e850fc&amp;amp;DisplayLang=en#Overview"&gt;&lt;FONT color=#0000ff&gt;link-to-VDI-Specifications&lt;/FONT&gt;&lt;/A&gt;.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 11pt; mso-bidi-font-family: Calibri"&gt;Within the VDI protocol, the backup application specifies a TSQL backup command.&amp;nbsp; This means that the backup application can use any TSQL command line options including the option&amp;nbsp;'WITH COMPRESSION'. In this case, the SQL Server&amp;nbsp;will send a pre-compressed (using SQL&amp;nbsp;native compression algorithm)&amp;nbsp;data stream. However,&amp;nbsp;if the server default is set to always compress,&amp;nbsp;the SQL Server&amp;nbsp;&lt;U&gt;will not send&lt;/U&gt; compressed data stream&amp;nbsp;to&amp;nbsp;VDI initiated&amp;nbsp;backup unless the application specifically requests it. The reason for this logic is that some backup applications depend on reading and interpreting the backup stream, and if&amp;nbsp;SQL Server&amp;nbsp;sends compressed bytes,&amp;nbsp;it can potentially break the backup application.&amp;nbsp;&amp;nbsp;For example, there are 3rd partly&amp;nbsp;backup tools that allow extracting&amp;nbsp;an object (i.e. a table) from the backup and if the backup is compressed in proprietary&amp;nbsp;format, the tool will not be able to extract the&amp;nbsp;object.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 11pt; mso-bidi-font-family: Calibri"&gt;On the other hand,&amp;nbsp;if the backup application explicitly&amp;nbsp;requests the backup compression, then we know that the application is expecting an opaque, compressed stream.&amp;nbsp; Secondarily, some backup applications do their own compression and may prefer to use their own algorithm.&amp;nbsp; That’s perfectly OK too.&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 11pt; mso-bidi-font-family: Arial"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 11pt; mso-bidi-font-family: Calibri"&gt;Thanks&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-FAMILY: 'Verdana','sans-serif'; FONT-SIZE: 11pt; mso-bidi-font-family: Calibri"&gt;Sunil Agarwal and Kevin Farlee&lt;/SPAN&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9967133" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="Backup" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/Backup/" /><category term="Restore" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/Restore/" /></entry><entry><title>Performance improvement by orders of magnitude when merging partitions in SQL Server 2008R2</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2010/02/03/performance-improvement-by-orders-of-magnitude-when-merging-partitions-in-sql-server-2008r2.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2010/02/03/performance-improvement-by-orders-of-magnitude-when-merging-partitions-in-sql-server-2008r2.aspx</id><published>2010-02-03T23:38:00Z</published><updated>2010-02-03T23:38:00Z</updated><content type="html">&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;I am publishing this Blog on&amp;nbsp;behalf&amp;nbsp;of Hermann Daeubler, our SAP expert&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Scenario:&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Let’s assume we have a table consisting of five partitions and the one in the middle needs to &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;be dropped. In SQL Server we need the following steps to accomplish this task &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpFirst&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-ansi-language: EN-US; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;a)&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Create a non-partitioned target table with the same structure and indexes as the partitioned table&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-ansi-language: EN-US; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;b)&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;Use the switch command to move the data from the middle partition to the new target table. Now the original partition is empty but still visible and the old boundary value isn’t removed &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpLast&gt;&lt;SPAN style="mso-bidi-font-family: Calibri; mso-ansi-language: EN-US; mso-bidi-theme-font: minor-latin"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3 face=Calibri&gt;c)&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT face=Calibri&gt;&lt;FONT size=3&gt;Complete the task by altering the partition function by merging the empty partition&lt;BR style="mso-special-character: line-break"&gt;&lt;BR style="mso-special-character: line-break"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3 face=Calibri&gt;Problem:&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;BR&gt;&lt;FONT face=Calibri&gt;&lt;FONT size=3&gt;The partition switch command is a metadata-only operation and is frequently used by customers &lt;BR&gt;to add (assuming staging table has already been populated) or remove partition data almost instantaneously. This is a significant improvement over non-partitioned tables where these operations can take time proportional to the size of the data. &lt;BR&gt;&lt;BR&gt;However, there are issues with partition merging where depending on the hardware and the size &lt;BR&gt;of the partitions, the step “c)” can still take much longer than expected especially when merging partitions in the middle of a table. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT face=Calibri&gt;&lt;FONT size=3&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;For details on partitions, please refer to &lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN lang=DE&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd578580.aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd578580.aspx"&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;http://msdn.microsoft.com/en-us/library/dd578580.aspx&lt;/SPAN&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;SPAN lang=DE&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/ms190787.aspx" mce_href="http://msdn.microsoft.com/en-us/library/ms190787.aspx"&gt;&lt;SPAN style="mso-ansi-language: EN-US" lang=EN-US&gt;&lt;FONT color=#0000ff size=3 face=Calibri&gt;http://msdn.microsoft.com/en-us/library/ms190787.aspx&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/A&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT face=Calibri&gt;&lt;FONT size=3&gt;Why partition merge is slow?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT face=Calibri&gt;&lt;FONT size=3&gt;It is a common scenario to put partitions on different file groups. The decision was made to make the&lt;BR&gt;partition function merge a deterministic function. This means that there is a fixed rule which defines&lt;BR&gt;on which file group the merged partition will end up. As a result the merge will be always in the same&lt;BR&gt;direction corresponding to the type (right or left). This approach has the downside that there is no&lt;BR&gt;optimization related to the size of the partitions. In a scenario where the source partition has 10 million rows and the destination partition has only 1 million rows, SQL Server would therefore move&lt;BR&gt;the 10 million rows of the source partition rather than moving the 1 million rows from the destination partition. The same would happen if the destination partition is completely empty as in&lt;BR&gt;the sample above where one would like to drop a partition. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;BR&gt;&lt;FONT face=Calibri&gt;&lt;FONT size=3&gt;There is a workaround for this when the partitions to be merged are mapped to the same filegroup. In the example above where the intention is to drop a partition it is clear that the destination partition is always empty.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The workaround is to &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo2" class=MsoListParagraphCxSpFirst&gt;&lt;SPAN style="FONT-FAMILY: Symbol; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol; mso-ansi-language: EN-US"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT face=Calibri&gt;&lt;FONT size=3&gt;Switch both partitions out – the source as well as the destination partition&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo2" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="FONT-FAMILY: Symbol; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol; mso-ansi-language: EN-US"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT face=Calibri&gt;&lt;FONT size=3&gt;Merge the partition function&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in; mso-list: l1 level1 lfo2" class=MsoListParagraphCxSpLast&gt;&lt;SPAN style="FONT-FAMILY: Symbol; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol; mso-ansi-language: EN-US"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Switch back in the source partition. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;But this workaround has a side-effect. It temporarily removes data from the table and an application using this approach has to provide a proper cleanup or rollback in case something goes wrong&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Solution with the changes in SQL Server 2008R2:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;CU6 for SQL Server 2008 SP1 includes a fix for this potential issue if all partitions reside on the same&lt;BR&gt;file group. It checks which partition has less rows and moves the data from this one during a partition&lt;BR&gt;function merge. This also covers the special case where one partition is empty.&lt;BR&gt;In case the performance of dropping partitions in the middle of a table is essential for an application&lt;BR&gt;it’s necessary to place all partitions on one single file group to take advantage of the fix in CU6.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Results :&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;The screenshots below and the SQL Script further down use a simple example to show how the &lt;BR&gt;workaround basically could be implemented. It also shows the difference after installing CU6 for&lt;BR&gt;SQL Server 2008 SP1.&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3 face=Calibri&gt;&lt;IMG border=0 src="http://blogs.msdn.com/photos/sqlserverstorageengine/images/9957869/original.aspx"&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT face=Calibri&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;Figure 1 above&amp;nbsp;shows that a test table was created with five partitions and five million rows in each&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;partition.&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;o:p&gt;&lt;A href="http://blogs.msdn.com/photos/sqlserverstorageengine/images/9957896/original.aspx" target=_blank&gt;&lt;IMG style="WIDTH: 689px; HEIGHT: 410px" border=0 src="http://blogs.msdn.com/photos/sqlserverstorageengine/images/9957896/original.aspx" width=768 height=353&gt;&lt;/A&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;Figure 2 above&amp;nbsp;shows that the standard way to get rid of a partition took over 2 minutes on the test system. &lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;There were obviously millions of logical reads involved due to the move of the data during &lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;the partition function merge&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;o:p&gt;&lt;A href="http://blogs.msdn.com/photos/sqlserverstorageengine/images/9957897/original.aspx" target=_blank&gt;&lt;IMG border=0 src="http://blogs.msdn.com/photos/sqlserverstorageengine/images/9957897/original.aspx"&gt;&lt;/A&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;o:p&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 11pt; mso-bidi-font-family: 'Times New Roman'; mso-fareast-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-theme-font: minor-latin"&gt;Figure 3 above&amp;nbsp;shows that afterwards boundary value 3 is missing as expected and four partitions are left&lt;/SPAN&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;o:p&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 11pt; mso-bidi-font-family: 'Times New Roman'; mso-fareast-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-theme-font: minor-latin"&gt;&lt;IMG style="WIDTH: 768px; HEIGHT: 409px" title=Figure-4 alt=Figure-4 align=middle src="http://blogs.msdn.com/photos/sqlserverstorageengine/images/9957898/original.aspx" width=768 height=480 mce_src="http://blogs.msdn.com/photos/sqlserverstorageengine/images/9957898/original.aspx"&gt;&lt;/SPAN&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;o:p&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Calibri','sans-serif'; FONT-SIZE: 11pt; mso-bidi-font-family: 'Times New Roman'; mso-fareast-font-family: Calibri; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-bidi-theme-font: minor-bidi; mso-fareast-theme-font: minor-latin"&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;Figure 4 above&amp;nbsp;shows the result of the workaround. Due to the additional switch more tables are involved.&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;But overall we see just a few logical reads and the whole process is done within a second&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;compared to over 2 minutes before&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;A href="http://blogs.msdn.com/photos/sqlserverstorageengine/images/9957900/original.aspx" target=_blank&gt;&lt;IMG border=0 src="http://blogs.msdn.com/photos/sqlserverstorageengine/images/9957900/original.aspx"&gt;&lt;/A&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Figure 5 above shows the output of the standard method after installing CU6 for SQL Server 2008 SP1. &lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;There is only one switch necessary and it finishes like the workaround before in a second.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT face=Calibri&gt;&lt;FONT size=3&gt;To run the SQL Script below, you need to follow the following steps in this sequence&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpFirst&gt;&lt;SPAN style="FONT-FAMILY: Symbol; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol; mso-ansi-language: EN-US"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT face=Calibri&gt;&lt;FONT size=3&gt;First create the four procedures&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpMiddle&gt;&lt;SPAN style="FONT-FAMILY: Symbol; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol; mso-ansi-language: EN-US"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT face=Calibri&gt;&lt;FONT size=3&gt;Run the procedures one after the other as seen at the end&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraphCxSpLast&gt;&lt;SPAN style="FONT-FAMILY: Symbol; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol; mso-ansi-language: EN-US"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;Create the test table as it’s necessary to specify how many rows should be generated. &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;It’s a &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;very basic algorithm which simply doubles the number of records 10 times. &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;A parameter of &lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;value 25000 results in 25 million rows – five million rows per partition.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;-- Procedure to create a partitioned test table &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;CREATE PROCEDURE create_partition_function_merge_test_tables ( @nr_rows INT )&lt;BR&gt;AS&lt;BR&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;DECLARE @counter int&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;SET NOCOUNT ON&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;IF EXISTS( select * from sys.objects &lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;WHERE name ='partition_function_merge_test_table' and type = 'U' )&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;DROP TABLE partition_function_merge_test_table&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;IF EXISTS( select * from sys.partition_schemes &lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;WHERE name = 'PARTITION_FUNCTION_MERGE_TEST_SCHEME' )&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;DROP PARTITION SCHEME [PARTITION_FUNCTION_MERGE_TEST_SCHEME]&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;IF EXISTS( select * from sys.partition_functions &lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;WHERE name = 'PARTITION_FUNCTION_MERGE_TEST_FUNCTION' )&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;DROP PARTITION FUNCTION [PARTITION_FUNCTION_MERGE_TEST_FUNCTION]&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CREATE PARTITION FUNCTION [PARTITION_FUNCTION_MERGE_TEST_FUNCTION] ( int )&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;AS&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;RANGE RIGHT FOR VALUES ( 1,2,3,4,5 )&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CREATE PARTITION SCHEME [PARTITION_FUNCTION_MERGE_TEST_SCHEME]&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;AS PARTITION [PARTITION_FUNCTION_MERGE_TEST_FUNCTION]&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;ALL TO ( [PRIMARY] )&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CREATE TABLE partition_function_merge_test_table&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;(&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;key_partkey&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;int NOT NULL,&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;key_col1&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;int,&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;key_col2&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;int,&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;data_col1&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;char(15),&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;data_col2&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;char(15),&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;data_col3&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;char(15)&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;) ON [PARTITION_FUNCTION_MERGE_TEST_SCHEME] ( key_partkey )&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CREATE CLUSTERED INDEX PFM_IDX1 on partition_function_merge_test_table ( key_partkey )&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;SET @counter = @nr_rows&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;WHILE ( @counter &amp;gt; 0 )&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;INSERT INTO partition_function_merge_test_table VALUES &lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;( @counter%5,@counter,@counter,&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;'Testdata Col1','Testdata Col2','Testdata Col3' )&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;SET @counter = @counter – 1&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;SET @counter = 10&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;WHILE ( @counter &amp;gt; 0 )&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;INSERT INTO partition_function_merge_test_table &lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;SELECT * from partition_function_merge_test_table&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;SET @counter = @counter – 1&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CREATE INDEX PFM_IDX2 on partition_function_merge_test_table ( key_col1 )&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CREATE INDEX PFM_IDX3 on partition_function_merge_test_table ( key_col2 )&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CHECKPOINT&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;END&lt;BR&gt;GO&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;-- Procedure to drop the partition in the middle via switch and merge command&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;CREATE PROCEDURE drop_partition_3_slow&lt;BR&gt;AS&lt;BR&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;IF ( OBJECT_ID('temp_partition') IS NOT NULL )&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;BEGIN&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;DROP TABLE temp_partition;&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CREATE TABLE temp_partition&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;(&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;key_partkey&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;int NOT NULL,&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;key_col1&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;int,&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;key_col2&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;int,&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;data_col1&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;char(15),&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;data_col2&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;char(15),&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;data_col3&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;char(15)&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CREATE CLUSTERED INDEX PFM_IDX1 on temp_partition ( key_partkey )&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CREATE INDEX PFM_IDX2 on temp_partition ( key_col1 )&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CREATE INDEX PFM_IDX3 on temp_partition ( key_col2 )&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;SET STATISTICS IO ON&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;ALTER TABLE partition_function_merge_test_table switch PARTITION 3 TO temp_partition&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;ALTER PARTITION FUNCTION PARTITION_FUNCTION_MERGE_TEST_FUNCTION () &lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;MERGE RANGE (3)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;SET STATISTICS IO OFF&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;END&lt;BR&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;-- Procedure to drop the partition in the middle via switch and merge command.&lt;BR&gt;-- This time it will also switch out the "neighbor" before the merge and switch&lt;BR&gt;-- it back in after the merge. This will avoid an unnecessary copy of the rows&lt;BR&gt;-- in the neighbor partition &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;CREATE PROCEDURE drop_partition_3_fast&lt;BR&gt;AS&lt;BR&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;IF ( OBJECT_ID('temp_partition') IS NOT NULL )&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;BEGIN&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;DROP TABLE temp_partition;&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;IF ( OBJECT_ID('temp_partition2') IS NOT NULL )&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;BEGIN&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;DROP TABLE temp_partition2;&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;END&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CREATE TABLE temp_partition&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;(&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;key_partkey&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;int NOT NULL,&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;key_col1&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;int,&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;key_col2&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;int,&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;data_col1&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;char(15),&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;data_col2&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;char(15),&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;data_col3&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;char(15)&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CREATE CLUSTERED INDEX PFM_IDX1 on temp_partition ( key_partkey )&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CREATE INDEX PFM_IDX2 on temp_partition ( key_col1 )&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CREATE INDEX PFM_IDX3 on temp_partition ( key_col2 )&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CREATE TABLE temp_partition2&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;(&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;key_partkey&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;int NOT NULL,&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;key_col1&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;int,&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;key_col2&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;int,&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;data_col1&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;char(15),&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;data_col2&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;char(15),&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;data_col3&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;char(15)&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CREATE CLUSTERED INDEX PFM_IDX1 on temp_partition2 ( key_partkey )&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CREATE INDEX PFM_IDX2 on temp_partition2 ( key_col1 )&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;CREATE INDEX PFM_IDX3 on temp_partition2 ( key_col2 )&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;SET STATISTICS IO ON&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;ALTER TABLE partition_function_merge_test_table switch PARTITION 3 TO temp_partition&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;ALTER TABLE partition_function_merge_test_table switch PARTITION 4 TO temp_partition2&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;ALTER PARTITION FUNCTION PARTITION_FUNCTION_MERGE_TEST_FUNCTION () &lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;MERGE RANGE (3)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;ALTER TABLE temp_partition2 ADD CONSTRAINT partCheck_constr CHECK ( key_partkey = 3 )&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;ALTER TABLE temp_partition2 switch TO partition_function_merge_test_table PARTITION 3&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;SET STATISTICS IO OFF&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;END&lt;BR&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;-- Procedure to list the partitions of the test table&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;CREATE PROCEDURE list_partitions&lt;BR&gt;AS&lt;BR&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;DECLARE @nr_partitions int&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;DECLARE @counter int&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;DECLARE @partrows int&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;DECLARE @boundary_value char(10)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;SET @nr_partitions = ( SELECT COUNT(*) FROM sys.partition_range_values prv, &lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;sys.partition_functions pf &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;WHERE pf.function_id = prv.function_id &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;AND &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;pf.name = 'PARTITION_FUNCTION_MERGE_TEST_FUNCTION' )&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;PRINT 'Partitions for table partition_function_merge_test_table :'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;PRINT ''&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;PRINT 'nr | boundary value | # rows in partition'&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;SET @counter = 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;WHILE ( @counter &amp;lt;= @nr_partitions )&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;BEGIN&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;SET @boundary_value = CONVERT(CHAR(10),&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;(SELECT value FROM sys.partition_range_values prv, sys.partition_functions pf&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;WHERE pf.function_id = prv.function_id AND pf.name = 'PARTITION_FUNCTION_MERGE_TEST_FUNCTION' AND&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;boundary_id = @counter ))&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;SET @partrows=(SELECT p.rows FROM sys.partitions p, sys.objects o&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;WHERE p.object_id = o.object_id AND o.name = 'partition_function_merge_test_table' AND&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;p.partition_number = @counter AND index_id IN (0,1) )&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;PRINT ' ' + rtrim(convert(char(5),@counter)) + ' |' +&lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;'&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;' + rtrim(@boundary_value) + ' |' + &lt;BR&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;'&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;' + convert(char(20), @partrows)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;SET @counter = @counter + 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;END&lt;BR&gt;END&lt;BR&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;-- Repro to show the performance impact of different ways to drop a partition.&lt;BR&gt;-- The procedure to drop the partition will turn "statistics io" on to prove&lt;BR&gt;-- by the number of logical reads on the test table that in the first case &lt;BR&gt;-- data will be moved whereas in the second case it won't.&lt;BR&gt;-- This will change by installing CU6 for SQL Server 2008 SP1 which fixes this&lt;BR&gt;-- behavior. While the runtime of the workaround was always the same the standard&lt;BR&gt;-- approach to drop a partition in the middle of a table improved from over 2 minutes&lt;BR&gt;-- to 1 second after installing CU6 for SQL Server 2008 SP1 – as shown on the &lt;BR&gt;-- screenshots above. The difference is of course dependent on the hardware&lt;BR&gt;-- configuration and might be even more or also less on other systems.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;execute create_partition_function_merge_test_tables 25000&lt;BR&gt;execute list_partitions&lt;BR&gt;execute drop_partition_3_slow&lt;BR&gt;execute list_partitions&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;SPAN style="mso-ansi-language: EN-US"&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;execute create_partition_function_merge_test_tables 25000&lt;BR&gt;execute list_partitions&lt;BR&gt;execute drop_partition_3_fast&lt;BR&gt;execute list_partitions &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9957868" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="VLDB Maintenance" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/VLDB+Maintenance/" /></entry><entry><title>Improvement in minimizing lockhash key collisions  in SQL Server 2008R2 and its impact on concurrency</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2010/01/18/improvement-in-minimizing-lockhash-key-collisions-in-sql-server-2008r2-and-its-impact-on-concurrency.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2010/01/18/improvement-in-minimizing-lockhash-key-collisions-in-sql-server-2008r2-and-its-impact-on-concurrency.aspx</id><published>2010-01-18T20:52:00Z</published><updated>2010-01-18T20:52:00Z</updated><content type="html">&lt;H1 style="MARGIN: 24pt 0in 0pt"&gt;&lt;SPAN style="COLOR: windowtext"&gt;&lt;FONT size=5&gt;&lt;FONT face=Calibri&gt;Another improved functionality in SQL Server 2008 R2&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/H1&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;I am posting this on behalf of Juergen Thomas who has been with SQL Server PM team from 12+ years and is an expert in SAP.&amp;nbsp;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Juergen&amp;gt;&amp;gt; In this article I’d like to talk about another improvement we made to SQL Server 2008 R2. The improvement pretty much is not noticed since it is buried deep into the SQL Server Engine. There also is nothing to tune about it. &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;It is about the hash key algorithm which is used by SQL Server in its Lock Manager. So let’s step and explain what SQL Server does and what impact this change in SQL Server 2008 R2 has.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;FONT face=Calibri&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-SIZE: 14pt; mso-bidi-font-size: 11.0pt"&gt;How does the locking work in SQL Server?&lt;/SPAN&gt;&lt;FONT size=3&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT face=Calibri&gt;&lt;FONT size=3&gt;Unlike some other database vendors, there is a logical component to SQL Server’s Lock Manager. SQL Server uses a lockhash value to represent a lock on the lock structure in the SQL Server Lock Manager instead of using the physical description to a row, page or a table. The lockhash value then is kept in memory. This design was driven by major considerations like:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 0pt 0.5in; mso-list: l1 level1 lfo2" class=MsoListParagraphCxSpFirst&gt;&lt;SPAN style="FONT-FAMILY: Symbol; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT face=Calibri&gt;&lt;FONT size=3&gt;No locking information to be stored on the page containing the resource. This eliminates additional IO or any space penalty on the page due to locking.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in; mso-list: l1 level1 lfo2" class=MsoListParagraphCxSpLast&gt;&lt;SPAN style="FONT-FAMILY: Symbol; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Since the key to a row could be as large as 900 bytes, using the real key values would have inflicted larger memory consumption. Especially with applications running long transactions and holding hundreds of thousands of locks. Therefore one needed to seek for a possibility to have a lock value which would not exceed a few bytes and fixed in size for better memory management&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;The solution to this problem was found when designing SQL server 7.0 in 1996 and 1997 by using the key of the row and apply a hash algorithm to it which then results in a 6 byte long lockhash value. This value is stored as resource description. Added to this is HoBT ID (B-Tree ID). If an another row in the same B-Tree needs to be locked, the hash value for the key of the row gets calculated and then compared to the hash values already stored as granted or waiting locks in order to see whether a lock on this row already exists.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;This mechanism worked sufficiently well for many years&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-SIZE: 14pt; mso-bidi-font-size: 11.0pt"&gt;&lt;FONT face=Calibri&gt;Issues appearing on the horizon&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT face=Calibri&gt;&lt;FONT size=3&gt;Using a hash algorithm to calculate a value out of keys &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;does have one small disadvantage:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="TEXT-INDENT: -0.25in; MARGIN: 0in 0in 10pt 0.5in; mso-list: l0 level1 lfo1" class=MsoListParagraph&gt;&lt;SPAN style="FONT-FAMILY: Symbol; mso-bidi-font-family: Symbol; mso-fareast-font-family: Symbol"&gt;&lt;SPAN style="mso-list: Ignore"&gt;&lt;FONT size=3&gt;·&lt;/FONT&gt;&lt;SPAN style="FONT: 7pt 'Times New Roman'"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Depending upon the # of rows, structure of the primary key, the data distribution and the complexity of the hashing algorithm, one can get hash collisions. For example, &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;one calculated lockhash value can lock more than one row within a B-Tree. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-SIZE: 14pt; mso-bidi-font-size: 11.0pt"&gt;&lt;FONT face=Calibri&gt;How can we see what the hash key value for a lock held on a key is?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Let’s demonstrate this with an example.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;CREATE TABLE test &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="COLOR: gray; mso-no-proof: yes"&gt;(&lt;/SPAN&gt;&lt;SPAN style="mso-no-proof: yes"&gt;a VARCHAR&lt;SPAN style="COLOR: gray"&gt;(&lt;/SPAN&gt;3&lt;SPAN style="COLOR: gray"&gt;)&lt;/SPAN&gt; &lt;SPAN style="COLOR: gray"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR: gray"&gt;NULL, &lt;/SPAN&gt;b VARCHAR&lt;SPAN style="COLOR: gray"&gt;(&lt;/SPAN&gt;8&lt;SPAN style="COLOR: gray"&gt;)&lt;/SPAN&gt; &lt;SPAN style="COLOR: gray"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR: gray"&gt;NULL, &lt;/SPAN&gt;c VARCHAR&lt;SPAN style="COLOR: gray"&gt;(&lt;/SPAN&gt;5&lt;SPAN style="COLOR: gray"&gt;)&lt;/SPAN&gt; &lt;SPAN style="COLOR: gray"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR: gray"&gt;NULL,&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/H2&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;d integer &lt;SPAN style="COLOR: gray"&gt;NOT&lt;/SPAN&gt; &lt;SPAN style="COLOR: gray"&gt;NULL)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;FONT size=2 face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;CREATE UNIQUE CLUSTERED INDEX ucl ON test&lt;SPAN style="COLOR: gray"&gt;(&lt;/SPAN&gt;a&lt;SPAN style="COLOR: gray"&gt;,&lt;/SPAN&gt;b&lt;SPAN style="COLOR: gray"&gt;,&lt;/SPAN&gt;c&lt;SPAN style="COLOR: gray"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;GO&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;FONT size=2 face="Courier New"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;begin transaction&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-no-proof: yes"&gt;INSERT test VALUES&lt;SPAN style="COLOR: gray"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-themecolor: text1"&gt;'150','00001082','00345'&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;,&lt;/SPAN&gt;1&lt;SPAN style="COLOR: gray"&gt;)&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/H2&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Now let’s perform this query:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-no-proof: yes"&gt;select resource_type,resource_database_id, resource_description, resource_associated_entity_id,request_mode, request_type, request_status from sys.dm_tran_locks where resource_type = 'KEY'&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/H2&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;The result will look like:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;TABLE style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-COLLAPSE: collapse; BORDER-TOP: medium none; BORDER-RIGHT: medium none; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184; mso-table-layout-alt: fixed; mso-border-alt: solid black .5pt; mso-border-themecolor: text1" class=MsoTableGrid border=1 cellSpacing=0 cellPadding=0 class="MsoTableGrid"&gt;
&lt;TBODY&gt;
&lt;TR style="HEIGHT: 30.75pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes"&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: black 1pt solid; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 55.05pt; PADDING-RIGHT: 5.4pt; HEIGHT: 30.75pt; BORDER-TOP: black 1pt solid; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-alt: solid black .5pt; mso-border-themecolor: text1" vAlign=top width=73&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;resource_type&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 62.85pt; PADDING-RIGHT: 5.4pt; HEIGHT: 30.75pt; BORDER-TOP: black 1pt solid; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1" vAlign=top width=84&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;resource_database_id&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 85.5pt; PADDING-RIGHT: 5.4pt; HEIGHT: 30.75pt; BORDER-TOP: black 1pt solid; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1" vAlign=top width=114&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;resource_description&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 117pt; PADDING-RIGHT: 5.4pt; HEIGHT: 30.75pt; BORDER-TOP: black 1pt solid; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1" vAlign=top width=156&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;resource_associated_entity_id&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 49.95pt; PADDING-RIGHT: 5.4pt; HEIGHT: 30.75pt; BORDER-TOP: black 1pt solid; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1" vAlign=top width=67&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;request_mode&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 51.8pt; PADDING-RIGHT: 5.4pt; HEIGHT: 30.75pt; BORDER-TOP: black 1pt solid; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1" vAlign=top width=69&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;request_type&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 56.65pt; PADDING-RIGHT: 5.4pt; HEIGHT: 30.75pt; BORDER-TOP: black 1pt solid; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1" vAlign=top width=76&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;request_status&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="HEIGHT: 15.75pt; mso-yfti-irow: 1; mso-yfti-lastrow: yes"&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: black 1pt solid; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 55.05pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-top-themecolor: text1" vAlign=top width=73 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;KEY&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 62.85pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=84 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;5&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 85.5pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=114 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;(5c017ccf0cbf)&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 117pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=156 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;72057594038976512&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 49.95pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=67 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;X&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 51.8pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=69 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;LOCK&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 56.65pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=76 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;GRANT&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;As resource_description you can see the value our hash key algorithm did calculate out of the input of the three key values ‘150’, ‘00001082’ and ‘00345’. The column ‘resource_associated_entity_id’ is the id of the B-Tree. It also finds usage in the system views sys.partitions and sys.allocation_units and can be used to get to the object_id or the name of the table the B-Tree belongs to.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Now let’s insert another row into the very same table with another Query Window. We’ll try to insert with this command:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;begin transaction&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;SPAN style="mso-no-proof: yes"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;INSERT test VALUES('150','00024855','00012',4)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/H2&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;To our surprise the insert of this row seems to be blocked and doesn’t come back (please note that the transaction of the first Query Window with the first row inserted still is open). Executing the same query against sys.dm_tran_locks gives us this result:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;TABLE style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-COLLAPSE: collapse; BORDER-TOP: medium none; BORDER-RIGHT: medium none; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184; mso-table-layout-alt: fixed; mso-border-alt: solid black .5pt; mso-border-themecolor: text1" class=MsoTableGrid border=1 cellSpacing=0 cellPadding=0 class="MsoTableGrid"&gt;
&lt;TBODY&gt;
&lt;TR style="HEIGHT: 45.75pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes"&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: black 1pt solid; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 55.05pt; PADDING-RIGHT: 5.4pt; HEIGHT: 45.75pt; BORDER-TOP: black 1pt solid; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-alt: solid black .5pt; mso-border-themecolor: text1" vAlign=top width=73&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;resource_type&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 62.85pt; PADDING-RIGHT: 5.4pt; HEIGHT: 45.75pt; BORDER-TOP: black 1pt solid; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1" vAlign=top width=84&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;resource_database_id&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 85.5pt; PADDING-RIGHT: 5.4pt; HEIGHT: 45.75pt; BORDER-TOP: black 1pt solid; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1" vAlign=top width=114&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;resource_description&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 117pt; PADDING-RIGHT: 5.4pt; HEIGHT: 45.75pt; BORDER-TOP: black 1pt solid; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1" vAlign=top width=156&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;resource_associated_entity_id&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 49.95pt; PADDING-RIGHT: 5.4pt; HEIGHT: 45.75pt; BORDER-TOP: black 1pt solid; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1" vAlign=top width=67&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;request_mode&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 51.8pt; PADDING-RIGHT: 5.4pt; HEIGHT: 45.75pt; BORDER-TOP: black 1pt solid; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1" vAlign=top width=69&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;request_type&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 56.65pt; PADDING-RIGHT: 5.4pt; HEIGHT: 45.75pt; BORDER-TOP: black 1pt solid; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1" vAlign=top width=76&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;request_status&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="HEIGHT: 15pt; mso-yfti-irow: 1"&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: black 1pt solid; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 55.05pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-top-themecolor: text1" vAlign=top width=73 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;KEY&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 62.85pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=84 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;5&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 85.5pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=114 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;(5c017ccf0cbf)&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 117pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=156 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;72057594038845440&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 49.95pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=67 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;X&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 51.8pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=69 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;LOCK&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 56.65pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=76 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;GRANT&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="HEIGHT: 15.75pt; mso-yfti-irow: 2; mso-yfti-lastrow: yes"&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: black 1pt solid; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 55.05pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-top-themecolor: text1" vAlign=top width=73 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;KEY&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 62.85pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=84 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;5&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 85.5pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=114 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;(5c017ccf0cbf)&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 117pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=156 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;72057594038845440&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 49.95pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=67 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;X&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 51.8pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=69 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;LOCK&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 56.65pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=76 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;WAIT&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;As this shows we are basically blocked with inserting the second row. The X-Lock could not be acquired because the hash algorithm used did calculate the very same hash value for the 3 key column values of the second row to be inserted.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;This issue demonstrates an undesired side effect of using hash algorithms to calculate lock values. However fortunately in most customer workloads, we rarely encountered this issue with customers. One of the reasons certainly is that the row colliding under the same hash value usually are far apart. E.g. if we lock a row of a general ledger table out of the current month in the company code of the corporation and there is a collision with a row of last year in the company code of one of the small subsidiaries, there will be no practical effect of such a hash collision. However, where we encountered a negative side effect of this was in large data loads. There it is all about getting tables of sometimes Terabyte in size loaded as fast as possible. Therefore one often splits up the loads in the export phase already. Importing those packages now in parallel (sometimes up to two dozen packages against one table) we did encounter blocking locks as well as deadlocks between those load streams. &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;B style="mso-bidi-font-weight: normal"&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-SIZE: 14pt; mso-bidi-font-size: 11.0pt"&gt;&lt;FONT face=Calibri&gt;How does SQL Server 2008 R2 resolve this issue?&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/B&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;In SQL Server 2008 R2, the hashing algorithm calculating the lockhash value was rewritten. The goals to make it more complex on the one side to avoid collisions without compromising the performance. We analyzed a lot of ISV customer database plus some other other customer databases to come up with a hash algorithm which used comparable CPU cycles but produced a better distribution of hashed values. In all the cases that we tested, &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;we found a dramatic reduction of hash key collisions. For example, &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;in 3 billion row tables where we had more than hundred thousand collisions with the old algorithm. Also, in many cases, we eliminated the hash collisions completely. With all the test data we used, the probability to get hash collisions is further lowered by a factor of 15,000 using the new hashing algorithm. After more than extensive tests for months and months, the new hash algorithm got released with the November CTP of SQL Server 2008 R2. For the example&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;above, we don’t see any hash collision anymore with SQL Server 2008 R2 as the table below proves. This is not to say that collision will not occur but it will be very unlikely.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;Result of running of performing this query against scenario described above:&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;H2 style="MARGIN: 10pt 0in 0pt"&gt;&lt;FONT size=2&gt;&lt;FONT face="Courier New"&gt;&lt;SPAN style="mso-no-proof: yes"&gt;select resource_type,resource_database_id, resource_description, resource_associated_entity_id,request_mode, request_type, request_status from sys.dm_tran_locks where resource_type = 'KEY'&lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/H2&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;TABLE style="BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; BORDER-COLLAPSE: collapse; BORDER-TOP: medium none; BORDER-RIGHT: medium none; mso-padding-alt: 0in 5.4pt 0in 5.4pt; mso-yfti-tbllook: 1184; mso-table-layout-alt: fixed; mso-border-alt: solid black .5pt; mso-border-themecolor: text1" class=MsoTableGrid border=1 cellSpacing=0 cellPadding=0 class="MsoTableGrid"&gt;
&lt;TBODY&gt;
&lt;TR style="HEIGHT: 45.75pt; mso-yfti-irow: 0; mso-yfti-firstrow: yes"&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: black 1pt solid; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 55.05pt; PADDING-RIGHT: 5.4pt; HEIGHT: 45.75pt; BORDER-TOP: black 1pt solid; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-alt: solid black .5pt; mso-border-themecolor: text1" vAlign=top width=73&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;resource_type&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 62.85pt; PADDING-RIGHT: 5.4pt; HEIGHT: 45.75pt; BORDER-TOP: black 1pt solid; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1" vAlign=top width=84&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;resource_database_id&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 85.5pt; PADDING-RIGHT: 5.4pt; HEIGHT: 45.75pt; BORDER-TOP: black 1pt solid; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1" vAlign=top width=114&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;resource_description&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 117pt; PADDING-RIGHT: 5.4pt; HEIGHT: 45.75pt; BORDER-TOP: black 1pt solid; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1" vAlign=top width=156&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;resource_associated_entity_id&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 49.95pt; PADDING-RIGHT: 5.4pt; HEIGHT: 45.75pt; BORDER-TOP: black 1pt solid; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1" vAlign=top width=67&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;request_mode&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 51.8pt; PADDING-RIGHT: 5.4pt; HEIGHT: 45.75pt; BORDER-TOP: black 1pt solid; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1" vAlign=top width=69&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;request_type&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 56.65pt; PADDING-RIGHT: 5.4pt; HEIGHT: 45.75pt; BORDER-TOP: black 1pt solid; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1" vAlign=top width=76&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;request_status&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="HEIGHT: 15pt; mso-yfti-irow: 1"&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: black 1pt solid; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 55.05pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-top-themecolor: text1" vAlign=top width=73 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;KEY&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 62.85pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=84 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;5&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 85.5pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=114 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;(4b729e3b9a50)&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 117pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=156 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;72057594038845440&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 49.95pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=67 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;X&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 51.8pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=69 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;LOCK&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 56.65pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=76 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;GRANT&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR style="HEIGHT: 15.75pt; mso-yfti-irow: 2; mso-yfti-lastrow: yes"&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: black 1pt solid; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 55.05pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-top-themecolor: text1" vAlign=top width=73 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;KEY&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 62.85pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=84 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;5&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 85.5pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=114 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;(7bd75c434bae)&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 117pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=156 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;72057594038845440&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 49.95pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=67 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;X&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 51.8pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=69 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;LOCK&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;
&lt;TD style="BORDER-BOTTOM: black 1pt solid; BORDER-LEFT: #f0f0f0; PADDING-BOTTOM: 0in; BACKGROUND-COLOR: transparent; PADDING-LEFT: 5.4pt; WIDTH: 56.65pt; PADDING-RIGHT: 5.4pt; HEIGHT: 15.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: black 1pt solid; PADDING-TOP: 0in; mso-border-left-alt: solid black .5pt; mso-border-top-alt: solid black .5pt; mso-border-alt: solid black .5pt; mso-border-themecolor: text1; mso-border-left-themecolor: text1; mso-border-top-themecolor: text1; mso-border-bottom-themecolor: text1; mso-border-right-themecolor: text1" vAlign=top width=76 noWrap&gt;
&lt;P style="LINE-HEIGHT: normal; MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;SPAN style="FONT-SIZE: 11pt"&gt;&lt;FONT face=Calibri&gt;GRANT&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;o:p&gt;&lt;FONT size=3 face=Calibri&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 10pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;As one can see, in the case of SQL Server 2008 R2 (November CTP) the second insert didn’t get blocked anymore since the lockhash value in the column resource_description differs.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9949970" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="Concurrency" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/Concurrency/" /></entry><entry><title>Changes to sp_estimate_data_compression_savings stored procedure in SQL2008R2</title><link rel="alternate" type="text/html" href="http://blogs.msdn.com/b/sqlserverstorageengine/archive/2009/09/16/changes-to-sp-estimate-data-compression-savings-stored-procedure-in-sql2008r2.aspx" /><id>http://blogs.msdn.com/b/sqlserverstorageengine/archive/2009/09/16/changes-to-sp-estimate-data-compression-savings-stored-procedure-in-sql2008r2.aspx</id><published>2009-09-16T22:53:00Z</published><updated>2009-09-16T22:53:00Z</updated><content type="html">&lt;P&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: Arial; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin"&gt;When you compress an object (index or table or partition), there are two components of space savings that you get. First&amp;nbsp;component is&amp;nbsp;fragmentaton (i.e. the original object might have been fragmented). The object gets degragmented as part of doing compression so you get some space savings. Second&amp;nbsp;component is actual data&amp;nbsp;compression savings. Many customers have asked the question 'Is there a way to know how much savings do I get from each of the two components?". &lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Calibri','sans-serif'; mso-bidi-font-family: Arial; mso-ascii-theme-font: minor-latin; mso-hansi-theme-font: minor-latin"&gt;Interestingly, starting with SQL2008R2, you indeed have this capability. Here is one example where I create a table t1 and then simulate fragmentation by updating a column. Once the table is fragemented, I can use the sp_estimate_data_compression stored procedure to determine how much space savings I can get by defragmenting it.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#0000ff size=1&gt;&lt;FONT color=#0000ff size=1&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;drop&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;table&lt;/SPAN&gt;&lt;FONT color=#000000&gt; t1&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;-- Create the table&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;create&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;table&lt;/SPAN&gt;&lt;FONT color=#000000&gt; t1&lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;(&lt;/SPAN&gt;&lt;FONT color=#000000&gt;c1 &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;,&lt;/SPAN&gt;&lt;FONT color=#000000&gt; c2 &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;char&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;(&lt;/SPAN&gt;&lt;FONT color=#000000&gt;100&lt;/FONT&gt;&lt;SPAN style="COLOR: gray"&gt;),&lt;/SPAN&gt;&lt;FONT color=#000000&gt; c3 &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;varchar &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;(&lt;/SPAN&gt;&lt;FONT color=#000000&gt;300&lt;/FONT&gt;&lt;SPAN style="COLOR: gray"&gt;))&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;go&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;-- create a clustered index&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;create&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;clustered&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;index&lt;/SPAN&gt;&lt;FONT color=#000000&gt; t1_ci &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;on&lt;/SPAN&gt;&lt;FONT color=#000000&gt; t1&lt;/FONT&gt;&lt;SPAN style="COLOR: gray"&gt;(&lt;/SPAN&gt;&lt;FONT color=#000000&gt;c1&lt;/FONT&gt;&lt;SPAN style="COLOR: gray"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;-- load 10000 rows. Note,&amp;nbsp; that for column C3, I am storing full-values that&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;-- take all 300 characters&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;declare&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt; @i &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;int&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;select&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt; @i &lt;/FONT&gt;&lt;SPAN style="COLOR: gray"&gt;=&lt;/SPAN&gt;&lt;FONT color=#000000&gt; 0&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;while &lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;(&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;@i &lt;/FONT&gt;&lt;SPAN style="COLOR: gray"&gt;&amp;lt;&lt;/SPAN&gt;&lt;FONT color=#000000&gt; 10000&lt;/FONT&gt;&lt;SPAN style="COLOR: gray"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;begin&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;insert&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;into&lt;/SPAN&gt;&lt;FONT color=#000000&gt; t1 &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;values &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;(&lt;/SPAN&gt;&lt;FONT color=#000000&gt;@i&lt;/FONT&gt;&lt;SPAN style="COLOR: gray"&gt;,&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: red"&gt;'hello'&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;,&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: fuchsia"&gt;replicate&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;'1'&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;,&lt;/SPAN&gt;&lt;FONT color=#000000&gt; 300&lt;/FONT&gt;&lt;SPAN style="COLOR: gray"&gt;))&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-tab-count: 1"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;select&lt;/SPAN&gt;&lt;FONT color=#000000&gt; @i &lt;/FONT&gt;&lt;SPAN style="COLOR: gray"&gt;=&lt;/SPAN&gt;&lt;FONT color=#000000&gt; @i &lt;/FONT&gt;&lt;SPAN style="COLOR: gray"&gt;+&lt;/SPAN&gt;&lt;FONT color=#000000&gt; 1&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;end&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;-- Now let us measure the average length of the row. It comes to 417 bytes. &lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;-- This means &lt;/o:p&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;that there are 19 rows per page&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;select&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt; avg_record_size_in_bytes&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;from&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: green"&gt;sys&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;.&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt;dm_db_index_physical_stats&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR: fuchsia"&gt;db_id&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;'TEMPDB'&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;),&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: fuchsia; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;object_id&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;(&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: red; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;'T1'&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;),&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-tab-count: 4"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;null,&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: gray"&gt;null,&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: red"&gt;'SAMPLED'&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;where&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: fuchsia"&gt;object_name&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR: fuchsia"&gt;object_id&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;)&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: gray"&gt;like&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: red"&gt;'t1'&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: gray"&gt;AND&lt;/SPAN&gt;&lt;FONT color=#000000&gt; index_id &lt;/FONT&gt;&lt;SPAN style="COLOR: gray"&gt;=&lt;/SPAN&gt;&lt;FONT color=#000000&gt;1&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;-- check the space usage. This shows the space usage of 4296 KB&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: maroon; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;sp_spaceused&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt; t1&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;-- This update will cause fragmentation because I am&amp;nbsp;changing the column C3 from 300&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;-- chars to 50 chars. With the result, the average row length &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;-- will now become 167 but the SQL Server will still keep 19 rows/page which &lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;-- leaves more that 50% unused space on each page&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;update&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt; t1 &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;set&lt;/SPAN&gt;&lt;FONT color=#000000&gt; c3 &lt;/FONT&gt;&lt;SPAN style="COLOR: gray"&gt;=&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: fuchsia"&gt;REPLICATE&lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;(&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;'2'&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;,&lt;/SPAN&gt;&lt;FONT color=#000000&gt; 50&lt;/FONT&gt;&lt;SPAN style="COLOR: gray"&gt;)&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: gray; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;-- check the space usage. It shows that the allocated or reserved space&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;-- has not changed&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT color=#000000&gt;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: maroon"&gt;sp_spaceused&lt;/SPAN&gt;&lt;FONT color=#000000&gt; t1&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;-- estimate how much space you can save by defragmentation. Note&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;-- here I am executing the stored procedure on an 'uncompressed' table&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;-- with target compression setting is 'NONE',(i.e. no compression).&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;exec&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt; sp_estimate_data_compression_savings&lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;'dbo'&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;,&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: red"&gt;'T1'&lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;,&lt;/SPAN&gt;&lt;FONT color=#000000&gt;1&lt;/FONT&gt;&lt;SPAN style="COLOR: gray"&gt;,&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: gray"&gt;NULL,&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: red"&gt;'none'&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="COLOR: red"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="COLOR: red"&gt;&lt;FONT color=#008000&gt;-- This &lt;/FONT&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;stored proc returns&lt;/SPAN&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="COLOR: red"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;object_name&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;schema_name index_id&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;partition_number &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;------------&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;----------- --------&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;---------------&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;T1 &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;dbo &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;1&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;1&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;size_with_current_compression_setting(KB) size_with_requested_compression_setting(KB)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;---------------------------------------- &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;------------------------------------------&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;4480&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;1720&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: red; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;-- To verify this, I rebuild the index and see the space consumption&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;alter&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;index&lt;/SPAN&gt;&lt;FONT color=#000000&gt; t1_ci &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;on&lt;/SPAN&gt;&lt;FONT color=#000000&gt; t1 &lt;/FONT&gt;&lt;SPAN style="COLOR: blue"&gt;rebuild&lt;/SPAN&gt;&lt;FONT color=#000000&gt; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;-- check the space usage. It shows that the table now takes 1744KB&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; COLOR: green; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;FONT color=#000000&gt;&amp;nbsp; &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: maroon"&gt;sp_spaceused&lt;/SPAN&gt;&lt;FONT color=#000000&gt; t1&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;In SQL2008RTM, the stored procedure did not compute the space savings if the source and target compression settings were same. In otherwords, the stored proc would have returned &lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;the following instead &lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;size_with_current_compression_setting(KB) size_with_requested_compression_setting(KB)&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;---------------------------------------- &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;------------------------------------------&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;4480&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4480&lt;/SPAN&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Calibri','sans-serif'; mso-fareast-font-family: Calibri; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;&lt;SPAN style="COLOR: black; mso-no-proof: yes; mso-bidi-font-family: 'Courier New'"&gt;Interestingly, you can use it to get tell-tale signs to know if ROW compressed table already takes advantage of unicode compression in SQL2008R2. L&lt;/SPAN&gt;&lt;SPAN style="COLOR: black; mso-no-proof: yes"&gt;et us say customer was using ROW compression in SQL2008 and now upgrades to SQL10.5, s/he can use to the sp_estimate_data_compression_savings stored proc by specifying target compression to be ROW as well. Note, in this case, the compression savings will include the potential savings from data defragmentation as well so one can’t easily deduce that the savings are from Unicode compressions or due to both. However, customer can&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;get some clues by referring to the sys.dm_db_index_physical_stats DMV to see if the object in question was fragmented or not.&lt;/SPAN&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Calibri','sans-serif'; mso-fareast-font-family: Calibri; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Calibri','sans-serif'; mso-fareast-font-family: Calibri; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin"&gt;Thanks&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;SPAN style="FONT-SIZE: 11pt; FONT-FAMILY: 'Calibri','sans-serif'; mso-fareast-font-family: Calibri; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-bidi-language: AR-SA; mso-bidi-font-family: 'Times New Roman'; mso-bidi-theme-font: minor-bidi; mso-ascii-theme-font: minor-latin; mso-fareast-theme-font: minor-latin; mso-hansi-theme-font: minor-latin"&gt;Sunil&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;&lt;SPAN style="FONT-SIZE: 9pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;FONT color=#000000&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT size=1&gt;&lt;/FONT&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9896036" width="1" height="1"&gt;</content><author><name>Sunil Agarwal</name><uri>http://blogs.msdn.com/Sunil-Agarwal/ProfileUrlRedirect.ashx</uri></author><category term="Index Fragmentation Series" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/Index+Fragmentation+Series/" /><category term="Data Compression" scheme="http://blogs.msdn.com/b/sqlserverstorageengine/archive/tags/Data+Compression/" /></entry></feed>