<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx</link><description>In a multi-process/multi-thread system, locking is central to maintain data consistency and keep things in order. It is inevitably at the root of almost all the concurrency and scalability problems. To understand the behavior of such a system and to troubleshoot</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13078</link><pubDate>Fri, 03 Apr 2009 01:38:15 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13078</guid><dc:creator>Mike Walsh</dc:creator><description>&lt;p&gt;It's a lot to wish for but too much? &amp;nbsp;I don't think so. I would like to see that for some of the operations at least.&lt;/p&gt;
&lt;p&gt;They put the permissions required for various operations into Books Online and that was a useful addition (whenever it was added, I forget when but it's been there awhile now)&lt;/p&gt;
&lt;p&gt;Open a connect item and get folks replying/blogging about it :)&lt;/p&gt;
</description></item><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13079</link><pubDate>Fri, 03 Apr 2009 01:39:05 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13079</guid><dc:creator>Mike Walsh</dc:creator><description>&lt;p&gt;And like the heel that I am, I just re-read your post and noticed you already mentioned the permissions :)&lt;/p&gt;
</description></item><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13080</link><pubDate>Fri, 03 Apr 2009 05:54:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13080</guid><dc:creator>Greg Linwood</dc:creator><description>&lt;p&gt;I wish SQL Server used a multi version concurrency model by default (rather than the old Read Committed) b/c then we'd see fewer blocking problems to begin with..&lt;/p&gt;
</description></item><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13081</link><pubDate>Fri, 03 Apr 2009 11:14:23 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13081</guid><dc:creator>Paul White</dc:creator><description>&lt;p&gt;Definitely yes. &amp;nbsp;Even if a comprehensive description is too optimistic, some basic information on locking behaviour would be nice.&lt;/p&gt;
&lt;p&gt;&amp;lt;mini-rant&amp;gt;&lt;/p&gt;
&lt;p&gt;On the subject of wish lists for documentation, could we also please have some definitive information of the effect of various commands and features on the ability of the QO to generate a parallel plan?&lt;/p&gt;
&lt;p&gt;Discovering for oneself which things (e.g. encryption functions, CLR UDFs passed a MAX datatype...) force a fully serial plan, and which require a serial zone with a parallel plan (e.g. backward scans) is frustrating. &amp;nbsp;Especially when testing a new design only to find some undocumented restriction forces a serial plan where parallelism is absolutely required!&lt;/p&gt;
&lt;p&gt;&amp;lt;/mini-rant&amp;gt;&lt;/p&gt;
&lt;p&gt;[Craig Freedman's article at &lt;a rel="nofollow" target="_new" href="http://blogs.msdn.com/craigfr/attachment/2167013.ashx"&gt;http://blogs.msdn.com/craigfr/attachment/2167013.ashx&lt;/a&gt; is a good start - but doesn't cover everything, sadly.]&lt;/p&gt;
</description></item><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13082</link><pubDate>Fri, 03 Apr 2009 11:41:56 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13082</guid><dc:creator>Linchi Shea</dc:creator><description>&lt;p&gt;&amp;gt; I wish SQL Server used a multi version concurrency model by default&lt;/p&gt;
&lt;p&gt;That is probably too much to wish for because the default locking behavior is so fundamental to the SQL Server engine.&lt;/p&gt;
</description></item><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13083</link><pubDate>Fri, 03 Apr 2009 13:13:07 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13083</guid><dc:creator>Andrew Kelly</dc:creator><description>&lt;p&gt;&amp;gt; I wish SQL Server used a multi version concurrency model by default&lt;/p&gt;
&lt;p&gt;The problem with that is like Linchi stated too many people don't understand how locking works. &amp;nbsp;Too often they would wrte apps that make important decisions when relying on old data. I know Oracle uses that model for its default but I can't even begin to count how many developers that switched from Oracle to SQL and only when they started getting blocked did they find out all that time they were potentially reading old data.&lt;/p&gt;
</description></item><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13084</link><pubDate>Fri, 03 Apr 2009 13:13:39 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13084</guid><dc:creator>Alexander Kuznetsov</dc:creator><description>&lt;p&gt;&amp;gt;I wish SQL Server used a multi version concurrency model by default &lt;/p&gt;
&lt;p&gt;What about READ COMMITTED SNAPSHOT? It is used by default if set up as such.&lt;/p&gt;
</description></item><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13085</link><pubDate>Fri, 03 Apr 2009 13:31:04 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13085</guid><dc:creator>Paul White</dc:creator><description>&lt;p&gt;Andrew,&lt;/p&gt;
&lt;p&gt;That's true but seeing how few people notice/complain about reading statement-level consistent committed data (the entire Oracle user base for example) should tell us something. &amp;nbsp;Anything requiring better isolation than provided by READ_COMMITTED_SNAPSHOT should probably be running at REPEATABLE READ or higher anyway. &amp;nbsp;Recall that READ COMMITTED can read the same row twice, or one row not at all...and so on. &amp;nbsp;Most business people (the guys paying the bills) are delighted by SNAPSHOT for the readers-don't-block-writers thing and vice-versa. &amp;nbsp;Reading the most recently committed data seems eminently sensible! &amp;nbsp;Also bear in mind that many OLTP shops go READ UNCOMMITTED to avoid the blocking and deadlocking associated with READ COMMITTED. &amp;nbsp;Pure OLTP is rare, rare, rare. &amp;nbsp;Pretty much everyone runs some reports or other non-trivial selects concurrently with write operations. &amp;nbsp;/Paul&lt;/p&gt;
</description></item><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13086</link><pubDate>Fri, 03 Apr 2009 13:39:40 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13086</guid><dc:creator>Greg Linwood</dc:creator><description>&lt;p&gt;Linchi - what do you mean by &amp;quot;fundamental to the SQL Server engine&amp;quot;? Do you mean that the engine isn't capable of working well with READ COMMITTED SNAPSHOT?&lt;/p&gt;
&lt;p&gt;I think a bigger challenge is as Andy says - SQL devs tend not to undersstand MVCC, probably b/c they don't have a long history of using it. Perhaps its time to change &amp;amp; head down that path as a default behaviour.&lt;/p&gt;
&lt;p&gt;The NOLOCK hint is used on such a widespread basis that chaos pretty much rules already - shifting the default to READ COMMITTED SNAPSHOT has to be a step in the right direction imo..&lt;/p&gt;
</description></item><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13088</link><pubDate>Fri, 03 Apr 2009 16:11:14 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13088</guid><dc:creator>Linchi Shea</dc:creator><description>&lt;p&gt;Greg;&lt;/p&gt;
&lt;p&gt;I was referring to the fact that if you look at how READ COMMITTED SNAPSHOT is implemented, it is an 'add on' to the engine. In other words, they need to find ways or build new mechanisms on top of what is already there to get that to work. There were issues. I blogged about an issue a while back when it was observed to have adverse performance impact by just turning it on without actually maintaining any multiple versions. That particular issue may have been resolved(haven't checked it for a while now to be sure). &lt;/p&gt;
&lt;p&gt;Let me know if we see READ COMMITTED SNAPSHOT is used in producing database benchmark scores.&lt;/p&gt;
</description></item><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13089</link><pubDate>Fri, 03 Apr 2009 16:21:48 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13089</guid><dc:creator>Alexander Kuznetsov</dc:creator><description>&lt;p&gt;Linchi,&lt;/p&gt;
&lt;p&gt;Where is the Connect item I could vote for?&lt;/p&gt;
</description></item><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13090</link><pubDate>Fri, 03 Apr 2009 16:22:46 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13090</guid><dc:creator>RussellH</dc:creator><description>&lt;p&gt;I have to agree with everyone saying that READ COMMITTED SNAPSHOT should be the default locking behavior going forward. &amp;nbsp;The only drawback I see is that it could break old code that depends on the old behavior and the new code written by developers who expect the old behavior.&lt;/p&gt;
&lt;p&gt;I agree with Andrew that a lot of Oracle developers don't understand that their query is reading old data, but I think a lot of SQL Server developers don't understand the consequences of readers being blocked by writers, and start throwing around NOLOCK hints like crazy (as Greg Linwood said). &amp;nbsp;I'm dealing with code now that had mandated NOLOCK on query. &amp;nbsp;They are reading aggregations that never existed at all.&lt;/p&gt;
&lt;p&gt;The bottom line for me is that it easier to write code that is both fast (highly concurrent and scalable) and correct with READ COMMITTED SNAPSHOT. &amp;nbsp;But you still have to know what you are doing.&lt;/p&gt;
</description></item><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13092</link><pubDate>Fri, 03 Apr 2009 17:33:59 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13092</guid><dc:creator>Alexander Kuznetsov</dc:creator><description>&lt;p&gt;Hi Russell,&lt;/p&gt;
&lt;p&gt;&amp;gt;I'm dealing with code now that had mandated NOLOCK on query. &lt;/p&gt;
&lt;p&gt;&amp;gt;They are reading aggregations that never existed at all.&lt;/p&gt;
&lt;p&gt;You can get incorrect totals under READ COMMITTED just as well:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://www.simple-talk.com/sql/t-sql-programming/the-case-of-the-skewed-totals/"&gt;http://www.simple-talk.com/sql/t-sql-programming/the-case-of-the-skewed-totals/&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13093</link><pubDate>Fri, 03 Apr 2009 17:43:45 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13093</guid><dc:creator>Linchi Shea</dc:creator><description>&lt;p&gt;Okay Alex, I submitted a connect item with text from here almost verbatim, though I didn't ask the rhetorical question whether it's too much to ask :-)&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=430251"&gt;https://connect.microsoft.com/SQLServer/feedback/ViewFeedback.aspx?FeedbackID=430251&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13094</link><pubDate>Fri, 03 Apr 2009 18:04:17 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13094</guid><dc:creator>Alexander Kuznetsov</dc:creator><description>&lt;p&gt;Voted. Thank you Linchi!&lt;/p&gt;
</description></item><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13095</link><pubDate>Fri, 03 Apr 2009 21:53:17 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13095</guid><dc:creator>Greg Linwood</dc:creator><description>&lt;p&gt;I agree it would be very helpful if this was better documented Linchi, so I've also voted a 5.&lt;/p&gt;
</description></item><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13097</link><pubDate>Fri, 03 Apr 2009 22:41:43 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13097</guid><dc:creator>Alexander Kuznetsov</dc:creator><description>&lt;p&gt;How comes we two both voted 5 and:&lt;/p&gt;
&lt;p&gt;Rating: 4.6 after 2 ratings &amp;nbsp;[?] &lt;/p&gt;
</description></item><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13098</link><pubDate>Fri, 03 Apr 2009 23:10:07 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13098</guid><dc:creator>Linchi Shea</dc:creator><description>&lt;p&gt;I clicked on the five, and that bumped the rating up to 4.7. Curious math???&lt;/p&gt;
</description></item><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13099</link><pubDate>Sat, 04 Apr 2009 02:31:50 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13099</guid><dc:creator>Greg Linwood</dc:creator><description>&lt;p&gt;I think this is a known issue - I recall some discussion on it in the MVP forum a while back but can't remember the reason. I'm sure the first vote was 5 , but said 4.6 before I lodged my vote.&lt;/p&gt;
</description></item><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13101</link><pubDate>Sat, 04 Apr 2009 03:40:20 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13101</guid><dc:creator>Paul White</dc:creator><description>&lt;p&gt;Having thought about this some more, I'm not sure that BOL is the place for this. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;BOL is an excellent resource, but that doesn't mean that it should contain everything. &amp;nbsp;BOL works well at the level of detail it is currently targeted to. &amp;nbsp;The place for the detailed locking documentation is probably MSDN/TechNet.&lt;/p&gt;
&lt;p&gt;An example article on MSDN that seems to cover locking very well at the same time as expanding on the documentation in BOL is &lt;a rel="nofollow" target="_new" href="&lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/ms191261"&gt;http://msdn.microsoft.com/en-us/library/ms191261&lt;/a&gt;.aspx"&gt;&lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/ms191261"&gt;http://msdn.microsoft.com/en-us/library/ms191261&lt;/a&gt;.aspx&lt;/a&gt; and the 2005 version &lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/ms191261"&gt;http://msdn.microsoft.com/en-us/library/ms191261&lt;/a&gt;(SQL90).aspx &lt;/p&gt;
&lt;p&gt;I have voted 4 for the connect article, for the above reasons.&lt;/p&gt;
&lt;p&gt;Note that the average rating on Connect is computed using an aggregate at READ UNCOMMITTED ;)&lt;/p&gt;
</description></item><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13103</link><pubDate>Sat, 04 Apr 2009 04:25:50 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13103</guid><dc:creator>RussellH</dc:creator><description>&lt;p&gt;Alex,&lt;/p&gt;
&lt;p&gt;Thank you for the link to your article, I'm forwarding it to our DBA and developer groups. &lt;/p&gt;
</description></item><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13107</link><pubDate>Sat, 04 Apr 2009 16:03:46 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13107</guid><dc:creator>James Luetkehoelter</dc:creator><description>&lt;p&gt;Ok, a late comment to the discussion, but I think Linchi has it on the head why SNAPSHOT_READ_COMMITTED in SQL Server is no where near comparable to the row versioning used in other systems. The whole snapshot approach in SQL Server is a shell game - instead of having to design around readers/blocking writers, SQL Server just shifts the management of it to TempDB (poor Tempdb...it gets so much abuse now). It's a systemic problem due to the transaction log combining the concepts or rollforward/rollback.&lt;/p&gt;
&lt;p&gt;So, yes, SNAPSHOT_READ_COMMITTED might be a good solution for any given environment, but keep in mind that the cost (size and load on Tempdb) might outway the benefits.&lt;/p&gt;
&lt;p&gt;I think (and if I have mistated correct me Linchi) that is what you were referring to with the comment &amp;quot;That is probably too much to wish for because the default locking behavior is so fundamental to the SQL Server engine&amp;quot;. I agree 100%. First and formost for any DBA is to know thy engine.&lt;/p&gt;
</description></item><item><title>re: Document the locking behavior</title><link>http://sqlblog.com/blogs/linchi_shea/archive/2009/04/02/document-the-locking-behavior.aspx#13136</link><pubDate>Tue, 07 Apr 2009 17:27:36 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:13136</guid><dc:creator>John Paul Cook</dc:creator><description>&lt;p&gt;Voted, thanks for opening it on Connect!&lt;/p&gt;
</description></item></channel></rss>