6

I experimented with various configurations of SQL Server databases and ended up setting READ_COMMITTED_SNAPSHOT to ON while ALLOW_SNAPSHOT_ISOLATION is OFF.

I noticed that when enabling this, many queries got a lot faster. I'm still using the default READ COMMITTED isolation level to connect to the database.

What is actually happening here? I would think that when ALLOW_SNAPSHOT_ISOLATION is OFF, setting READ_COMMITTED_SNAPSHOT to ON wouldn't have any effect... I'm still not actually using the snapshot isolation, or am I? Can anybody please explain? I'm confused.

I tried researching this topic online, but whenever I see READ_COMMITTED_SNAPSHOT being used, it's always together with ALLOW_SNAPSHOT_ISOLATION, which I didn't enable.

0

1 Answer 1

5

I noticed that when enabling this, many queries got a lot faster. I'm still using the default READ COMMITTED isolation level to connect to the database.

Dan noted this:

The options are independent and both do not need to be turned on, although many mistakenly do so. Turning on either incurs the row-versioning overhead. READ_COMMITTED_SNAPSHOT ON causes all READ_COMMITTED sessions to use row-versioning instead of locking so that will avoid blocking and may explain your perceived performance improvement.

In addition, READ_COMMITTED_SNAPSHOT (henceforth called RCSI) will only give you some properties of optimistic concurrency. RCSI and Snapshot (SI) differ in three main ways:

  1. RCSI will be used immediately by all RC isolation queries.
  2. RCSI provides a point-in-time (snapshot) view of the database for a single statement.
  3. SI provides a point-in-time view for an entire transaction.
  4. SI can have write conflicts.

What is actually happening here?

RCSI is turned on, thus all RC isolation queries are being promoted to RCSI where readers don't block writers and writers don't block readers. The "speed up" you're seeing is most likely due to the reduced waits on blocking for those queries as it is now using the optimistic concurrency's version store instead of blocking and waiting. This may or may not be giving you the desired results in your queries.

I would think that when ALLOW_SNAPSHOT_ISOLATION is OFF, setting READ_COMMITTED_SNAPSHOT to ON wouldn't have any effect... I'm still not actually using the snapshot isolation, or am I?

See above. You are using it when RCSI is turned on (which is the one you did in fact turn on) but SI is not automatically used when turned on: You need to explicitly SET TRANSACTION ISOLATION LEVEL SNAPSHOT (or equivalent) to use SI.


For more information, see Row Versioning-based Isolation Levels in the SQL Server Database Engine in the product documentation.

Other useful details relating some gotchas and caveats when using RCSI/SI can be found in these articles:

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.