Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Read Committed_Snapshot Expand / Collapse
Author
Message
Posted Saturday, March 16, 2013 1:14 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, August 5, 2014 1:46 AM
Points: 265, Visits: 1,715
"Read Committed_Snapshot" isolation level in sql has any negatives or disadvantages?
Post #1431868
Posted Saturday, March 16, 2013 5:45 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 3:39 PM
Points: 15,618, Visits: 27,998
It does put considerable additional load on the tempdb, so be sure you're ready to handle that. The amount depends on the level of data changes you're dealing with. Other than that, I've seen no negatives and quite a few positives.

----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1431880
Posted Monday, March 18, 2013 12:02 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Tuesday, August 5, 2014 1:46 AM
Points: 265, Visits: 1,715
can we estimate required space for tempdb ? and also whether database update speed is reduced ?
Post #1432080
Posted Monday, March 18, 2013 4:48 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 3:39 PM
Points: 15,618, Visits: 27,998
Best suggestion I can make is to measure the number and size of your current transactions. Get a sense of the amount of data that is actively being modified and that will give you an indication of what's going to happen with tempdb.

----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1432133
Posted Monday, March 18, 2013 5:07 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 8:36 AM
Points: 2,836, Visits: 5,066
If you enable READ COMMITTED SNAPSHOT in the database, it becomes the default isolation level.
So, it can break some of your application functionality which would depend on default behavior under READ COMMITTED isolation level. I would see that could be a common problem for many existing "booking" systems...


_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1432138
Posted Monday, March 18, 2013 5:47 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Tuesday, August 12, 2014 4:51 PM
Points: 7,097, Visits: 12,597
Eugene Elutin (3/18/2013)
If you enable READ COMMITTED SNAPSHOT in the database, it becomes the default isolation level.

For clarity READ_COMMITTED_SNAPSHOT is just a mode of the READ_COMMITTED isolation level with versioning, i.e. READ_COMMITTED_SNAPSHOT is not an isolation level unto itself.

So, it can break some of your application functionality which would depend on default behavior under READ COMMITTED isolation level. I would see that could be a common problem for many existing "booking" systems...

Example?


__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Post #1432151
Posted Monday, March 18, 2013 6:21 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 3:39 PM
Points: 15,618, Visits: 27,998
opc.three (3/18/2013)
Eugene Elutin (3/18/2013)
If you enable READ COMMITTED SNAPSHOT in the database, it becomes the default isolation level.

For clarity READ_COMMITTED_SNAPSHOT is just a mode of the READ_COMMITTED isolation level with versioning, i.e. READ_COMMITTED_SNAPSHOT is not an isolation level unto itself.

So, it can break some of your application functionality which would depend on default behavior under READ COMMITTED isolation level. I would see that could be a common problem for many existing "booking" systems...

Example?


Yeah, I'd love to see an example or two as well.


----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of: SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans

Product Evangelist for Red Gate Software
Post #1432165
Posted Monday, March 18, 2013 10:02 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 8:36 AM
Points: 2,836, Visits: 5,066
Grant Fritchey (3/18/2013)
opc.three (3/18/2013)
Eugene Elutin (3/18/2013)
If you enable READ COMMITTED SNAPSHOT in the database, it becomes the default isolation level.

For clarity READ_COMMITTED_SNAPSHOT is just a mode of the READ_COMMITTED isolation level with versioning, i.e. READ_COMMITTED_SNAPSHOT is not an isolation level unto itself.

So, it can break some of your application functionality which would depend on default behavior under READ COMMITTED isolation level. I would see that could be a common problem for many existing "booking" systems...

Example?


Yeah, I'd love to see an example or two as well.


Ok, I'll try to come up with one hypothetical one.
But at first I need to put few sentences:
1. "booking" system could be actually any transactional system. I just held an example in my head which would be relevant for booking or stock management.
2. I guess many will agree that READ_COMMITTED_SNAPSHOT is not a magic bullet against all locking problems in your database! When you design and code you should be aware of locking issues and design/code appropriately.

Now an example. "booking" system...

Let say Customer "A" does want to book one Seat and his highest priority is to book a seat #1. At the same (or almost the same) time Customer "B" wants top do exactly the same!
So small setup:

CREATE TABLE Booking (ID INT IDENTITY(1,1), SeatID INT, CustomerID CHAR(1))
INSERT Booking SELECT 1, NULL
INSERT Booking SELECT 2, NULL

Now let see how booking system will process reservations without READ_COMMITTED_SNAPSHOT:

ALTER DATABASE MyDev
SET ALLOW_SNAPSHOT_ISOLATION OFF;

ALTER DATABASE MyDev
SET READ_COMMITTED_SNAPSHOT OFF;

For a Customer A, started first - hence his transaction begins first (SSMS query window 1):
BEGIN TRANSACTION

-- Book seat 1 if it's not already taken
IF NOT EXISTS (SELECT 1 FROM Booking WHERE SeatID = 1 AND CustomerID IS NOT NULL)
BEGIN
UPDATE Booking SET CustomerID = 'A' WHERE SeatID = 1
END

-- Now let say we need to do something else as part of the booking transaction which
-- takes some considerate amount of time for this Customer
-- do not commit for now!

So, while transaction for Customer "A" is still running Customer "B" presses the "Book" button, so his transaction kick's in (SSMS query window 2):

BEGIN TRANSACTION

-- Book seat 1 if it's not already taken (and it's not as transaction for Customer A is not committed as yet).
IF NOT EXISTS (SELECT 1 FROM Booking WHERE SeatID = 1 AND CustomerID IS NOT NULL)
BEGIN
UPDATE Booking SET CustomerID = 'B' WHERE SeatID = 1
END
-- Now let say that "something else - part" for Customer "B" takes no time and transaction is completed, so:
COMMIT TRANSACTION

Yeah, our second transaction is running as it cannot commit waiting for the first one to release the lock. Lets do it. Add COMMIT TRANSACTION into first query (SSMS window 1) and execute it.
So. All transactions are now committed (you can check window 2). Let see what we have in result?

SELECT * FROM Booking

As expected we have:


ID SeatID CustomerID
1 1 A
2 2 NULL


Now turn is for READ_COMMITTED_SNAPSHOT (make sure that you have only one connection to your database open, otherwise SET READ_COMMITTED_SNAPSHOT OFF will run for ever ):

ALTER DATABASE MyDev
SET ALLOW_SNAPSHOT_ISOLATION ON
ALTER DATABASE MyDev
SET READ_COMMITTED_SNAPSHOT ON

Repeat all steps in exactly the same order as previously.
Check results.
Surprise!!!!
You will have Customer "B" much more lucky this time!
Oops....

Yes, you will tell me that my code is not good enough, and you will be right - it's a crap code.
But that is not a point I wanted to make. What I've tried to say is:
If you have a crap code which did work without READ_COMMITTED_SNAPSHOT, you will still get it working fine with READ_COMMITTED_SNAPSHOT ON, except one caveat: it may produce a bit different results...

So, refer to the point #2 at the beginning of my post.


_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1432244
Posted Monday, March 18, 2013 10:10 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 8:36 AM
Points: 2,836, Visits: 5,066
Grant Fritchey (3/18/2013)
... or two as well.


Googled out the second one (surprisingly to me - based on "stock management":

http://www.jimmcleod.net/blog/index.php/2009/08/27/the-potential-dangers-of-the-read-committed-snapshot-isolation-level/




_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1432250
Posted Monday, March 18, 2013 10:11 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 10:02 PM
Points: 23,210, Visits: 31,892
Eugene Elutin (3/18/2013)
Grant Fritchey (3/18/2013)
opc.three (3/18/2013)
Eugene Elutin (3/18/2013)
If you enable READ COMMITTED SNAPSHOT in the database, it becomes the default isolation level.

For clarity READ_COMMITTED_SNAPSHOT is just a mode of the READ_COMMITTED isolation level with versioning, i.e. READ_COMMITTED_SNAPSHOT is not an isolation level unto itself.

So, it can break some of your application functionality which would depend on default behavior under READ COMMITTED isolation level. I would see that could be a common problem for many existing "booking" systems...

Example?


Yeah, I'd love to see an example or two as well.


Ok, I'll try to come up with one hypothetical one.
But at first I need to put few sentences:
1. "booking" system could be actually any transactional system. I just held an example in my head which would be relevant for booking or stock management.
2. I guess many will agree that READ_COMMITTED_SNAPSHOT is not a magic bullet against all locking problems in your database! When you design and code you should be aware of locking issues and design/code appropriately.

Now an example. "booking" system...

Let say Customer "A" does want to book one Seat and his highest priority is to book a seat #1. At the same (or almost the same) time Customer "B" wants top do exactly the same!
So small setup:

CREATE TABLE Booking (ID INT IDENTITY(1,1), SeatID INT, CustomerID CHAR(1))
INSERT Booking SELECT 1, NULL
INSERT Booking SELECT 2, NULL

Now let see how booking system will process reservations without READ_COMMITTED_SNAPSHOT:

ALTER DATABASE MyDev
SET ALLOW_SNAPSHOT_ISOLATION OFF;

ALTER DATABASE MyDev
SET READ_COMMITTED_SNAPSHOT OFF;

For a Customer A, started first - hence his transaction begins first (SSMS query window 1):
BEGIN TRANSACTION

-- Book seat 1 if it's not already taken
IF NOT EXISTS (SELECT 1 FROM Booking WHERE SeatID = 1 AND CustomerID IS NOT NULL)
BEGIN
UPDATE Booking SET CustomerID = 'A' WHERE SeatID = 1
END

-- Now let say we need to do something else as part of the booking transaction which
-- takes some considerate amount of time for this Customer
-- do not commit for now!

So, while transaction for Customer "A" is still running Customer "B" presses the "Book" button, so his transaction kick's in (SSMS query window 2):

BEGIN TRANSACTION

-- Book seat 1 if it's not already taken (and it's not as transaction for Customer A is not committed as yet).
UPDATE Booking SET SeatNo = 1
WHERE Customer ='B'
AND NOT EXISTS(SELECT 1 FROM Booking WHERE SeatNo = 1) -- seat is not booked yet.

-- Now let say that "something else - part" for Customer "B" takes no time and transaction is completed, so:
COMMIT TRANSACTION

Yeah, our second transaction is running as it cannot commit waiting for the first one to release the lock. Lets do it. Add COMMIT TRANSACTION into first query (SSMS window 1) and execute it.
So. All transactions are now committed (you can check window 2). Let see what we have in result?

SELECT * FROM Booking

As expected we have:


ID SeatID CustomerID
1 1 A
2 2 NULL


Now turn is for READ_COMMITTED_SNAPSHOT (make sure that you have only one connection to your database open, otherwise SET READ_COMMITTED_SNAPSHOT OFF will run for ever ):

ALTER DATABASE MyDev
SET ALLOW_SNAPSHOT_ISOLATION ON
ALTER DATABASE MyDev
SET READ_COMMITTED_SNAPSHOT ON

Repeat all steps in exactly the same order as previously.
Check results.
Surprise!!!!
You will have Customer "B" much more lucky this time!
Oops....

Yes, you will tell me that my code is not good enough, and you will be right - it's a crap code.
But that is not a point I wanted to make. What I've tried to say is:
If you have a crap code which did work without READ_COMMITTED_SNAPSHOT, you will still get it working fine with READ_COMMITTED_SNAPSHOT ON, except one caveat: it may produce a bit different results...

So, refer to the point #2 at the beginning of my post.


Not sure about your setup. You aren't even using the same code between sessions.



Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Post #1432252
« Prev Topic | Next Topic »

Add to briefcase 12»»

Permissions Expand / Collapse