The postings on this site are my own and do not represent my Employer's positions, advice or strategies.

LifeAsBob - Blog

 

Home

No Ads ever, except search!
Friday, January 17, 2025 Login
Public

Blog posts for the month of January,2025.
Stop using locking hints in Azure SQL1/17/2025 6:03:08 AM

Once habits are hard to stop.

Teams begin using with (nolock), holdlock and they just keep using.

Mostly leftover if you can believe from sql 2000 based DBAs, yep that long.

Developers don't understand locking, let alone new enhancements to it in azure sql or sql 2025.

There may be a reason to use a lock hint, but usually when I ask, there is no reason given other than "this is the way we have always done it."


Even before the new locking optimizations teams were advocating to STOP with the locking hints.

RCSI configuration is ON by default

SQL Server has many isolation levels to control the integrity of the data.

However, in read-heavy applications, many developers have the terrible habit of using NOLOCK on all statements to avoid the contention of creating lock records on the server. The developers ignore the risk of incorrect results.

Over the years, Microsoft created a solution for SQL Server: Two new isolation levels, RCSI (Read Committed Snapshot Isolation) and Snapshot Isolation; both also called optimistic isolation levels.

RCSI is considered a special isolation level. It’s different from the other isolation levels because RCSI is configured as a database property. There is no need to change the code. Every transaction that arrives on the server using Read Committed isolation (the default) is converted to Snapshot Isolation. I’m using quotes here because it’s not exactly Snapshot Isolation. RCSI has some differences from Snapshot Isolation, and that’s why they are considered two different isolation levels.

The point is: Azure SQL uses RCSI by default. This is a big change for all existing applications. Any use of NOLOCK that you have in existing applications becomes useless and a problem for the application because it brings the usual issues of NOLOCK with no benefit, since the use of RCSI replaces all the possible benefits of NOLOCK.

You can check this default on Azure SQL running the following query:

An image showing the results of checking is_read_committed_snapshot_on

Migrating applications to Azure SQL and using RCSI are great opportunities to eliminate all NOLOCKs still found in your SQL code.




Blog Home