You should hire Richie Rump. Here's why.

Category: Locking, Blocking, and Isolation Levels

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
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
Performance Tuning

When You’re Troubleshooting Blocking, Look at Query #2, Too.

When I'm troubleshooting a blocking emergency, the culprit is usually the query at the head of a blocking chain. Somebody did something ill-advised like starting a transaction and then locking a whole bunch of tables.

But sometimes, the lead blocker isn't the real problem. It's query #2.

Read more about When You’re Troubleshooting Blocking, Look at Query #2, Too. 2 comments — Join the discussion
Performance Tuning

Free Webcast on Thursday: Avoiding Deadlocks with Query Tuning

To fix blocking & deadlocks, you have 3 tools:

Have enough indexes to make your queries fast, but not so many that they slow down delete/update/insert operations. (I cover that in the Mastering Index Tuning class.)
Use the right isolation level for your app's needs. (I cover that in the Mastering Server Tuning class.)
Tuning your T-SQL to work through tables in a consistent order and touch them as few times as possible.

Read more about Free Webcast on Thursday: Avoiding Deadlocks with Query Tuning 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
Performance Tuning

Using NOLOCK? Here’s How You’ll Get the Wrong Query Results.

Slapping WITH (NOLOCK) on your query seems to make it go faster - but what's the drawback? Let's take a look.

We'll start with the free StackOverflow.com public database - any one of them will do, even the 10GB mini one - and run this query:
[crayon-6a697e17ddc0b947552865/]
We're just setting everyone's web page to ours. Then in a separate window, while that update is running, run this:
[crayon-6a697e17ddc16669938385/]
The results? A picture is worth a thousand words:

Read more about Using NOLOCK? Here’s How You’ll Get the Wrong Query Results. 10 comments — Join the discussion
Performance Tuning

Locks Taken During Indexed View Modifications

Frankenblog
This post has been nagging at me for a while, because I had seen it hinted about in several other places, but never written about beyond passing comments.

A long while back, Conor Cunningham wrote:
This same condition applies to indexed view maintenance, but I’ll save that for another day :).
AFAIK he hasn't written about it or typed an emoji since then.

Read more about Locks Taken During Indexed View Modifications 8 comments — Join the discussion
Performance Tuning

How to Delete Just Some Rows from a Really Big Table: Fast Ordered Deletes

Say you've got a table with millions or billions of rows, and you need to delete some rows. Deleting ALL of them is fast and easy - just do TRUNCATE TABLE - but things get much harder when you need to delete a small percentage of them, say 5%.

It's especially painful if you need to do regular archiving jobs, like deleting the oldest 30 days of data from a table with 10 years of data in it.

Read more about How to Delete Just Some Rows from a Really Big Table: Fast Ordered Deletes 78 comments — Join the discussion