Nope, this is not a clickbait title (ok, well sort of). Blocking is good….otherwise SQL Server (and all the other database platforms would eliminate it for good. And before you say something about a pure MVCC implementation like SQL Server implemented with in-memory OLTP… there is no blocking, but in place of blocking you can do a lot of work, perhaps hours, and when you go to commit, it fails… blocking is better than that in any case where you are doing large transactions.
Many are unconvinced
I won’t lie, getting this idea of blocking being somehow beneficial into your brain is not easy. A lot of DBAs get their start optimizing performance without being reminded constantly that speed is less important than the data being stored. So they seek out ways to eliminate blocking however they can.
And SQL Server obliges for the most part. There is an isolation level (READ UNCOMMITTED) and several table hints (NOLOCK,READUNCOMMITTED) that can be used to used to ignore and not place most locks. (Schema locks are still created/honored so structures don’t change.)
And anyone who has realized what they do knows… There is one universal thing said about these hints.
DON’T USE THESE HINTS (you know, unless you really understand the consequences and can truly accept them).
The generally accepted only reason to use hints like this is to see the effects of some operation you are watching where uncommitted data has no way of causing confusion. Like if you are loading a lot of data, this may be the only way to see the progress of that operation adding (or subtracting) rows and you don’t want to impede processing unnecessarily.
I may also use these when looking at an active production database trying to solve some issue and I want to be sure I have minimal impact.
But when any relational programmer/DBA worth their salary sees these hints in production code, they shudder at what they are going to be up against. Because ignoring locks should never be used as a performance tool.
Blocking is good, but unnecessary blocking is the worst performance issue
While blocking as a concept is good, unnecessary blocking is generally the first thing you need to work on eliminating when tuning a query/system where the queries themselves have clearly optimum query plans and execute perfectly most of the time.
Unnecessary blocking generally means that something in a query is touching rows it needn’t. For example, in many cases:
UPDATE Table SET ColumnFROM Table;
May have the same effect on locks as:
UPDATE Table SET ColumnFROM Table WHERE unindexedColumn = ‘value’
Because every single row in that table will be locked (and possibly the entire table.) Now, any reader of this table will be stuck until they commit the transaction (either by the fact that the UPDATE statement ends, or any explicit transaction started with BEGIN TRANSACTION. If you add an index to the unindexedColumn, it will only touch a few (possibly only one) row.
If you are reading this just to see what I had to say and you haven’t heard about SQL Server’s new Optimized Locking feature in 2025, it is really cool. Along with the documentation link, I wrote this a while about it too.
Don’t just use NOLOCK to ignore locks
One of the main reasons that is commonly stated to not use NOLOCK is that users (or queries) can see data that may never be committed. So if a user enters 10000 when they thought it would add a decimal and actually enter 100.00, they could review that and roll that back it. Or maybe a constraint or trigger says no to some data. It is really hard to demonstrate, but even if a trigger/constraint fails, data may appear to exist momentarily. Easier to demonstrate is the effects of a large update, but no matter how unlikely something is, over time these issues frequently occur and then cost days to try to figure out what might have happened.
Say a process is executing to update all the data in the table, and the very last row in this query fails. Ignoring locks could mean you see all that data and a user might make a decision based on bad data.
You have choices when it comes to isolation
This is on my mind as I am adjusting a presentation about concurrency, and it is wild just how many choices you have, all based on what your data quality needs are. If your database has any critical information in it, not only do you need locks, but you probably need more than the default. But most databases need way less than they take by default.
I will expound on this in the future, but there are a few ways to isolate databases that are common and used in SQL Server’s on-disk structures.
- Locks – Any resource that someone needs to ensure that external changes wouldn’t affect your operation are held fast until you finish. Making sure your code that causes locks touches the least amount of physical resources is important.
- Versions Each connection can see what rows looked like when they started a transaction or operation. For only reading data, this is usually ideal and greatly reduces unneeded blocking.
There is no one size fits all solution, but the versions method is generally considered the best default method of them all for isolating changes between connections when there aren’t critical concerns between users modifying or creating data.
But when things are critical, versioning is not necessarily the best. One of my typical examples is a hospital database. If you are recording meds given to a patient, you want to be 100% sure that anyone else reading that chart sees it before making any decisions based on the data.
You will also want to make sure that the version of the data you were looking at when you started to record an order for meds is the same, because what if someone else is also giving an order, or gave an order before you started.
But if your needs aren’t as critical, you might be more lax with your isolation needs. Like if you are calling someone who is currently being called, because they were recording the incoming call while you were deciding to make an outbound call… well that might be weird, but no one will be hurt. And if it doesn’t happen all the time, it might be something you and your client can laugh about.
Summary
Blocking is good. Unneeded blocking is awful. Required data integrity always trumps performance.
Part of being a database tuning expert is knowing what is required, and what isn’t. And it is often said that understanding all the requirements is a very easy task, though it is rarely written as such because biting satire is really hard to express in writing unlike speaking.



Leave a Reply