Tag Info

Hot answers tagged

12

is because it has to write to cache and then to the TempDb (row version) and then it can return to the caller. No, this is incorrect. It somehow implies that writes in the presence of versioning have higher latency as each write has to touch the disk (for tempdb) which is not true. The write into the tempdb is also a write into 'cache'. The only ...


10

A connection from the pool will have the isolation level set by the last client to use that connection. Yes, it really is that scary. The long and the short of it is that if you change the isolation level of a connection you must explicitly set it back to READ COMMITTED before closing. Better is to explicitly declare your required isolation level at the ...


9

I think the best approach for you would be to actually expose your module to high concurrency and see for yourself. Sometimes UPDLOCK alone is enough, and there is no need for HOLDLOCK. Sometimes sp_getapplock works out very well. I would not make any blanket statement here - sometimes adding one more index, trigger, or indexed view changes the outcome. We ...


9

Just addressing the SERIALIZABLE isolation level aspect. Yes this will work but with deadlock risk. Two transactions will both be able to read the row concurrently. They will not block each other as they will either take an object S lock or index RangeS-S locks dependant on table structure and these locks are compatible. But they will block each other when ...


8

The setting to disable page locking applies per index, so applying this change to the clustered index only affects execution plans that access the data via that index. If there are nonclustered indexes on the table, you may have to disable page locking for them as well. The following script demonstrates this: CREATE TABLE dbo.LockTest ( col1 ...


8

In this particular case the addition of a UPDLOCK lock to the SELECT would indeed prevent anomalies. The addition of HOLDLOCK isn't necessary as an update lock is held for the duration of the transaction, but I confess to including it myself as a (possibly bad) habit in the past. Imagine doing something more legitimate than an ID update, some ...


7

In an ideal world you would have two choices, SNAPSHOT and READ COMMITTED SNAPSHOT (RCSI). Make sure you understand the basics of transaction isolation levels before you decide which is appropriate for your workload. Specifically be aware of the different results you may see as a result of moving to RCSI. This sounds like it's not an ideal world as you ...


6

Correct, use SNAPSHOT isolation to get consistent, commited data from before the transaction started. The READ UNCOMMITTED isolation (aka NOLOCK hint) will read dirtz, inconsistent data When you enable SNAPSHOT isolation, then it takes effect for all SELECTs going forward. You run ALTER DATABASE with READ_COMMITTED_SNAPSHOT in this case Edit: added link ...


6

TRUNCATE table will take a SCH-M lock on the table. Even at READ UNCOMMITTED level the SELECT query will need to take a SCH-S lock. This won't be possible until the TRUNCATE transaction has ended and the conflicting SCH-M lock has been released.


5

As the SELECT is uncommitted, does it start executing before the DELETE is committed? No, T-SQL statements always execute sequentially in SQL Server. The point is the SELECT may read uncommitted changes made by other concurrently-executing transactions. Would this mean that removing NOLOCK should stop the error? Yes, but only because error 601 is ...


5

Setting the isolation level to SERIALIZABLE would have the same effect: The highest isolation level, serializable, guarantees that a transaction will retrieve exactly the same data every time it repeats a read operation, but it does this by performing a level of locking that is likely to impact other users in multi-user systems. TABLOCK will ...


5

As @AlexKuznetsov noted, SNAPSHOT and READ_COMMITTED_SNAPSHOT are two different isolation levels. As such, snapshot_isolation_state indicates the former, while is_read_committed_snapshot_on the latter. Here are a few comments that I found that summarize the differences between the two: READ COMMITTED SNAPSHOT does optimistic reads and pessimistic writes. ...


5

No. It doesn't affect anything regarding the internal management within SQL Server. You're setting that connection for you, for your queries. SQL Server manages it's own locking it's own way. Why would you turn off page and row locking on an index? You're more likely to see more severe locking than if you let SQL Server manage that index as it sees fit. By ...


4

I believe it will mean the same thing for DDL as it does for DML. The msdn article on the topic actually gives you a pretty clear idea under the SERIALIZABLE section: This option has the same effect as setting HOLDLOCK on all tables in all SELECT statements in a transaction. Basically as long as your transaction is running, no DDL can be performed on ...


4

The difference lies between a query and a transaction. A transaction can contain any number of queries. To illustrate the difference, I set up a small example: CREATE TABLE table_to_be_updated ( id serial PRIMARY KEY, other_column text, column_changing text ); INSERT INTO table_to_be_updated (other_column, column_changing) VALUES ('value', ...


4

On the flip side read committed snapshot will give only the latest committed version of data Incorrect. Snapshot will give you the data that was committed at the moment the snapshot was taken. This moment means either when you issued BEGIN TRAN if you use true SNAPSHOT isolation level, or the moment your statement started if you use ...


4

Your understanding is correct. It does get a little confusing. Kim Tripp (one of the programmers of SQL Server and a integral part of SQLSkills) goes through exactly what you stated in the MCM videos on Snapshot Isolation. Fast fwd to 41:45 in the video to get to the part where she answers your question. If you use ALLOW_SNAPSHOT_ISOLATION make sure you ...


4

You need to try SET tx_isolation = 'READ-UNCOMMITTED'; or SET SESSION tx_isolation = 'READ-UNCOMMITTED'; You could also declare it at the start of the transaction SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; Give it a Try !!! CAVEAT Please note that you misspelled READ-UNCOMMITED (Missing T). It should be READ-UNCOMMITTED You cannot change ...


4

Isn't it self-contradictory paragraph ("until" vs. "retained")? Not to me, but I can see there are other ways to read it. If you want the documentation updated to make it clearer, the proper place to request this is on Microsoft Connect. The people here do not maintain Microsoft documentation. that the default isolation level will have arbitrary ...


3

OK, went back home and tested. Here is the observation. CREATE DATABASE TEST; GO CREATE TABLE TABLE1 ( ID tinyint, Details varchar(10) ); GO INSERT INTO TABLE1 VALUES (1, 'Original'); GO SELECT name, snapshot_isolation_state_desc, is_read_committed_snapshot_on FROM sys.databases WHERE name = 'TEST'; GO First test with both settings ...


3

What if some other transaction updates a record so that it would match with my WHERE clause in the UPDATE statement, thereby violating the REPEATABLE READ. That would be SERIALIZABLE READ, not REPEATABLE. REPEATABLE only guarantees that the rows that qualified for the WHERE clause the first time will not disappear or be modified. It doesn't say anything ...


3

Snapshot isolation is robust. It does work. I have been using it in my system for several years, and it does reduce the amount of deadlocks. However, snapshot isolation adds more workload to your tempdb, so you need a skilled DBA who can ensure that your system withstands the load. Before you start using snashot isolation in production, make sure you have a ...


3

I'd suggest you read the following question and its answers: Database locking issues?. Finding the right isolation level to use at the db level is the fastest thing that you can do right now to help you fix this issue, because it's difficult now to change all applications that touch the database and change their code. Since you said "I don't have any ...


3

For most databases including Data Warehouses Read Committed is a sufficient isolation level. I wouldn't use Read Uncommitted due to the possibility of incorrect answers. On SQL Server we can also add Read Committed Snapshot Isolation. This versions rows and avoids queries being blocked by updates. Don't know if you have something similar on DB2.


3

The following behavior may be caused by missing indexes on referring side of your FKs: "the price changes take approx 1 hour to process (vs. 1-2 minutes) and sys.dm_tran_locks shows the transaction taking almost 90,000 different locks, compared to around 100-150 when foreign keys were being dropped/recreated" When a row is deleted or its PK/Unique is ...


3

Per Mark's determination, this isn't possible using locking hints or isolation level. If all the INSERTs you care about go through predetermined code paths, you can use a sp_getapplock-based mechanism to serialize them while still allowing normal access to the table during the operation. It would be preferable to simply use an IDENTITY column for this ...


3

If your goal is to ensure that at the end of procedure dbo.data contains only records you inserted in the body of procedure, then you move DELETE to the very end (I assume you have primary key in data table, data_id: --DELETE FROM dbo.data WHERE user = @user -- do it at the end DECLARE @captainsTable TABLE (captainId INT); DECLARE @newData TABLE ...


2

NEW ANSWER (MySQL-style dynamic SQL): Ok, this one tackles the problem in the way one of the other poster's described - reversing the order in which mutually incompatible exclusive locks are acquired so that regardless of how many occur, they occur only for the least amount of time at the end of transaction execution. This is accomplished by separating the ...


2

When you set the transaction level without the way you do it applies the Read Committed to the next transaction only, thus (set auto commit). This mean after autocommit=0, you're not in Read Committed anymore . I would write it this way: SET TRANSACTION ISOLATION LEVEL READ COMMITTED; START TRANSACTION; DELETE c FROM child c INNER JOIN parent p ON p.id ...


2

I can see how READ_COMMITTED can cause this situation. READ_COMMITTED allows for three things: Visibility of committed changes by other transactions using READ_COMMITTED isolation level. Non-Repeatable Reads : Transaction performing same retrieval with the possibility of getting a different result each time. Phantoms : Transactions may have rows appear ...



Only top voted, non community-wiki answers of a minimum length are eligible