Download presentation
Presentation is loading. Please wait.
Published byDarcy Dawson Modified over 8 years ago
1
Read Dirty to Me: SQL Server Isolation Levels Wendy Pastrick Arrow IT Consulting
2
About me SQL Server DBA since 2000 PASS Women In Technology PASS Board of Directors SQL Server MVP @wendy_dance Wendyverse.blogspot.com
3
Agenda Transaction Isolation Dirty Reads and Other Phenomena Isolation Levels Management Views Lock Manager Transaction Control The Bottom Line
4
Transaction Isolation The level at which a transaction is prepared to accept inconsistent data Concurrency Consistency ConcurrencyConsistency
5
Who Cares? Just “Set It” and “Forget It” Locking & Blocking
6
Dirty Reads and… Dirty Read ◦ Cheating on a Test
7
…Other Phenomena Non-Repeatable Read ◦ It was there a second ago!
8
…Other Phenomena Phantom Read ◦ Now, where did THAT come from?
9
Isolation Levels Transaction Based Defines the degree to which one transaction must be isolated from resource or data modifications made by other transactions Area of Impact ◦ Transaction (Query) ◦ Database
10
Half Full or Half Empty?
11
Isolation Levels Read UnCommitted ◦ The Dirty Read ◦ Okay sometimes Data that does not change often Concurrency Consistency
12
Isolation Levels Read Committed ◦ Pessimistic ◦ Default SQL Server Isolation Level ◦ Rows only locked when being accessed ◦ Demo Time! Concurrency Consistency
13
Isolation Levels Repeatable Read ◦ Pessimistic ◦ Rows locked as they are read ◦ Rows remain locked until transaction completes ◦ Phantom Rows possible ◦ Demo Time! Concurrency Consistency
14
Isolation Levels Serializable ◦ Key Range Locks ◦ Pessimistic ◦ All data locked until Transaction completes Locking & Blocking ◦ Only one transaction at a time ◦ Marbles in a bag Concurrency Consistency
15
Serializable Tran #1: Change all White to RED Tran #2: Change all RED to White Who Wins?
16
Isolation Levels Snapshot Isolation (2005+) ◦ Row Versioning ◦ Uses Tempdb ◦ Optimistic ◦ Possible to have two transactions update the EXACT SAME DATA But wait, there’s Conflict Detection! ◦ Marbles in a bag again Concurrency Consistency
17
Snapshot Who Wins? Tran #1: Change all RED to White Tran #2: Change all White to RED
18
Snapshot Merge Results: Tran #2: Change all White to RED Tran #1: Change all RED to White
19
Isolation Levels Read Committed Snapshot Isolation (2005+) ◦ Row Versioning ◦ Optimistic Concurrency Consistency
20
Management Views sys.dm_trans_locks ◦ View locks set by isolation sys.dm_tran_version_store ◦ Shows versions in the ‘store’ sys.dm_os_waiting_tasks ◦ Join with sys.dm_trans_locks to see blocking
21
Lock Manager ResourceDescription RIDA row identifier used to lock a single row within a heap. KEYA row lock within an index used to protect key ranges in serializable transactions. PAGEAn 8-kilobyte (KB) page in a database, such as data or index pages. EXTENTA contiguous group of eight pages, such as data or index pages. HoBT A heap or B-tree. A lock protecting a B-tree (index) or the heap data pages in a table that does not have a clustered index. TABLEThe entire table, including all data and indexes. FILEA database file. APPLICATIONAn application-specified resource. METADATAMetadata locks. ALLOCATION_UNITAn allocation unit. DATABASEThe entire database.
22
Transaction Control SET TRANSACTION ISOLATION LEVEL Table Hints override ◦ With NO LOCK – not as good as it sounds
23
The Bottom Line Transaction Processing ◦ CLOSE Transactions Choose Wisely ◦ Concurrency vs. Consistency Hidden Impact ◦ Query Plans ◦ Indexing Choices
24
Many MANY Thanks MSDN Kendra Little Craig Freedman Michael J Swart Grant Fritchey Itzik Ben-Gan http://wendyverse.blogspot.com/p/presentat ions-links.html
25
Cool Links (NOLOCK) for YESFUN by Kendra Little Itzik Ben-Gan Michael J Swart …and MORE! Wendyverse.blogspot.com
26
Contact me wendy.pastrick@gmail.com @wendy_dance on Twitter wendyverse.blogspot.com
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.