Hot answers tagged

14

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 ...


13

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 ...


13

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 ...


13

It is terrible, that you learned it that way (sorry!). READ UNCOMMITTED let's you read every row, yes. Even those who are currently used in an INSERT, UPDATE, DELETE operation. This is very useful if you need to take a quick look at some Data or in mission critical SELECT-Statements where a block would be very harmful. In fact, you risk your integrity. It ...


11

What is HOBT lock? A lock protecting a B-tree (index) or the heap data pages in a table that does not have a clustered index. Why would I still get a S lock? This happens on heaps. Example SET NOCOUNT ON; DECLARE @Query nvarchar(max) = N'DECLARE @C INT; SELECT @C = COUNT(*) FROM master.dbo.MSreplication_options'; /*Run once so ...


10

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 ...


10

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

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 ...


9

"Where is uncommitted data stored, such that a READ_UNCOMMITTED transaction can read uncommitted data from another transaction?" The new uncommitted record (clustered PK) versions are treated as the "current" version of the record on page. So they can be stored in the buffer pool and/or in the tablespace (e.g. tablename.ibd). Transactions that then need to ...


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 ...


8

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 ...


8

Lock hints are orthogonal to isolation level. While they address similar concerns, adding a lock hint does not change the isolation level. Your transaction will still be a 'serializable' transaction. Of course, the lock hint make the query operation itself violate the transaction serializability, but you are looking at a property of the transaction.


8

Your query is reporting the session-level setting of transaction isolation level, which is set to serializable. Using a NOLOCK hint (or its synonym READUNCOMMITTED) overrides the session isolation level for access to the specific object (table in this case) the hint is specified against. So, the transaction is still running under serializable isolation, ...


7

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.


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

Do I need to make the "unlock" SERIALIZABLE as well? Despite the name, the serializable isolation level does not guarantee transactions will be executed sequentially, or in the order received. Rather, serializable guarantees transactions will have the same persistent effects on the database as if they had executed sequentially, in some undefined order ...


6

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. ...


6

Knowing this, why does sql server need to issue U locks (when using RCSI)? It seems to me that sql server could simply read the rows, and request a X lock directly if an update must be performed. Unlike SI, RCSI does not detect update conflicts. As documented in Books Online, modifying data under RCSI reads currently-committed data, not a possibly ...


6

You will find the chapter Read Committed Isolation Level of the Postgres 9.5 manual instructive: Read Committed is the default isolation level in PostgreSQL. When a transaction uses this isolation level, a SELECT query (without a FOR UPDATE/SHARE clause) sees only data committed before the query began; it never sees either uncommitted data or ...


5

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 ...


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

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 ...


5

If you post schema and query etc, that would be useful, in addition to the other 3 answers. Some links anyway, from Simple-Talk. Good stuff. Execution Plan Basics Graphical Execution Plans for Simple SQL Queries Understanding More Complex Query Plans


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 ...


5

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 ...


5

ReadUncommitted isolation level does acquire locks. Schema stability locks prevent the objects being queries from being altered while the query executes. This locks are acquired under all isolation leveles, including snapshot and read_committed_snapshot (RCSI). From Lock Modes: Schema Locks The Database Engine uses schema modification (Sch-M) locks ...


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 ...


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

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 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 ...



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