Locking, Isolation, and Read Consistency

Isolation levels, NOLOCK, row versioning, RCSI, and lock behavior.

36 associated posts36 primary posts

Performance Tuning

And Then There Was The Time RCSI Actually Made Query Results More Accurate.

Normally when I tell people about SQL Server's optimistic concurrency isolation levels, Read Committed Snapshot Isolation (RCSI) and Snapshot Isolation (SI), I have to give them a little speech about how they need to test their queries because the results can change. Recently, though, I was working with a client who was getting the wrong query…

Read more about And Then There Was The Time RCSI Actually Made Query Results More Accurate. 11 comments — Join the discussion

[Video] Office Hours: Black Friday Edition

My Black Friday sale is in its last days, so most of my time at the moment is spent keeping an eye on the site and answering customer questions. I'm happy to say it's our best year so far, too! Y'all really like the new access-for-life options.

I took a break from the online frenzy to check in on the questions you posted at https://pollgab.com/room/brento and answer the highest-voted ones:

Read more about [Video] Office Hours: Black Friday Edition Be the first to comment

Lock Escalation Sucks on Columnstore Indexes.

If you've got a regular rowstore table and you need to modify thousands of rows, you can use the fast ordered delete technique to delete rows in batches without hitting the lock escalation threshold. That's great for rowstore indexes, but...columnstore indexes are different.

To demo this technique, I'm going to use the setup from my Fundamentals of Columnstore class:

Read more about Lock Escalation Sucks on Columnstore Indexes. 1 comment — Join the discussion
Performance Tuning

“But Surely NOLOCK Is Okay If No One’s Changing Data, Right?”

Some of y'all, bless your hearts, are really, really, really in love with NOLOCK.

I've shown you how you get incorrect results when someone's updating the rows, and I've shown how you get wrong-o results when someone's updating unrelated rows. It doesn't matter - there's always one of you out there who believes NOLOCK is okay in their special situation.

Read more about “But Surely NOLOCK Is Okay If No One’s Changing Data, Right?” 40 comments — Join the discussion
Production DBA

Research Paper Week: Constant Time Recovery in Azure SQL DB

Let's finish up Research Paper Week with something we're all going to need to read over the next year or two. I know, it says Azure SQL DB, but you boxed-product folks will be interested in this one too: Constant Time Recovery in Azure SQL DB by Panagiotis Antonopoulos, Peter Byrne, Wayne Chen, Cristian Diaconu, Raghavendra Thallam Kodandaramaih, Hanuma Kodavalla, Prashanth Purnananda, Adrian-Leonard Radu, Chaitanya Sreenivas Ravella, and Girish Mittur Venkataramanappa (2019).

Read more about Research Paper Week: Constant Time Recovery in Azure SQL DB 10 comments — Join the discussion

Research Paper Week: In-Memory Multi-Version Concurrency Control

If you've been doing performance tuning for several years, or graduated from my Mastering Server Tuning class, you've come across Read Committed Snapshot Isolation, aka RCSI, aka multi-version concurrency control, aka MVCC, aka optimistic concurrency. It's not the way SQL Server ships by default, although it is the default for Azure SQL DB, and it's part of the magic in how you can query an Availability Group readable secondary even when it's applying updates to the tables behind the scenes.

Read more about Research Paper Week: In-Memory Multi-Version Concurrency Control 3 comments — Join the discussion
Performance Tuning

“But NOLOCK Is Okay When My Data Isn’t Changing, Right?”

I've already covered how NOLOCK gives you random results when you're querying data that's changing, and that's a really powerful demo to show folks who think NOLOCK is safe to use in production. However, I've gotten a question from several users: But I'm querying data that isn't changing - sure, OTHER rows in the table…

Read more about “But NOLOCK Is Okay When My Data Isn’t Changing, Right?” 115 comments — Join the discussion
Performance Tuning

Using Implicit Transactions? You *Really* Need RCSI.

Implicit transactions are a hell of a bad idea in SQL Server: they require you to micromanage your transactions, staying on top of every single thing in code. If you miss just one little DELETE/UPDATE/INSERT operation and don't commit it quickly enough, you can have a blocking firestorm.

The ideal answer is to stop using implicit transactions, and only ask for transactions when you truly need 'em. (Odds are, you don't really need 'em.)

Read more about Using Implicit Transactions? You *Really* Need RCSI. 8 comments — Join the discussion