SlideShare a Scribd company logo
DEEP INTO
ISOLATION LEVELS
Boris Hristov
SQLBits, Superheroes, 2015
That’s not a Hekaton Talk!
(In-Memory OLTP)
So who am I?
@BorisHristov
Isolation Levels time
complexity
Fundamentals
?
Session’s Timeline
The Fundamentals
Pessimistic Concurrency Optimistic Concurrency
Locks
Blocking
Versions
Version Store
Update Conflicts
Locks
Locking
Blocking
Deadlocks
Lock Escalations
Common lock types
Intent
Used for: Preventing incompatible locks
Duration: End of the transaction
Shared (S)
Used for: Reading
Duration: Released almost immediately
(depends on the isolation level)
Update (U)
Used for: Preparing to modify
Duration: End of the transaction or until
converted to exclusive (X)
Exclusive (X)
Used for: Modifying
Duration: End of the transaction
Lock Compatibility
Lock Shared Update Exclusive
Shared (S)
  X
Update (U)
 X X
Exclusive (X)
X X X
Lock Hierarchy
Database
Table
Page
Row
Let’s update a row. What do we need?
USE AdventureWorks2012
GO
UPDATE [Person].[Address]
SET AddressLine1=‘London, UK'
WHERE AddressID=2
S
IX
Header
Row
Row
Row
Row
Row
IX
X
A query! 
Methods to View Locking Information
Dynamic
Management
Views
SQL Server
Profiler or
Extended Events
Performance
monitor or Activity
Monitor
DEMO
Locking and Locking Hierarchies
Transaction isolation levels
(pessimistic concurrency)
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED (NOLOCK?)
Transaction 1
Transaction 2
Suggestion: Better offload the reads or go with optimistic level concurrency!
Select
Update
eXclusive lock
Read Uncommitted
(pessimisticconcurrencycontrol)
Dirty read
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
Transaction 1 rows
Non-repeatable reads possible (updates during Transaction 1)
Phantom records possible (inserts during Transaction 1)
What else? (that’s a Pluralsight voucher right here!)
Updates and Inserts
Transaction 2
Read Committed
(pessimisticconcurrencycontrol)
S
S
S
S
SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
Transaction 1 S(hared) lock
select
No non-repeatable reads possible (updates during Transaction 1)
Phantom records still possible (inserts during Transaction 1)
Update
Transaction 2
Repeatable Read
(pessimisticconcurrencycontrol)
Transaction 1 S(hared) lock
select
Even phantom records are not possible!
Highest pessimistic level of isolation, lowest level of concurrency
Oh, yeah, TransactionScope in C# and MSDTC transactions default to this level too
Insert
Transaction 2
Serializable
(pessimisticconcurrencycontrol)
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
DEMO
Playing with Isolation levels (Pessimistic Concurrency)
Transaction isolation levels
(optimistic concurrency)
Read Committed and Snapshot Isolation levels
 RCSI – Read Committed Snapshot Isolation Level
 Statement level versioning
 Requires ALTER DATABASE SET READ_COMMITTED_SNAPSHOT ON
 Snapshot Isolation Level
 Transaction level versioning
 Requires ALTER DATABASE SET ALLOW_SNAPSHOT_ISOLATION ON
 Requires SET TRANSACTION ISOLATION LEVEL SNAPSHOT
V1 V2
Transaction 1
Transaction 2
Select in RCSISelect
Select in SI
DEMO
Playing with Isolation levels (Optimistic Concurrency)
… and Azure DB
too
Just before we end…
Isolation levels can have dramatic impact on your application
As such, isolation levels must also be a business decision
The behavior of the readers changes in the various levels
Writers, though, will always block. No matter what!
And one more thing – please be careful with ORMs 
Summary
Thank you!
Contacts:
brshristov@live.com
www.borishristov.com
@BorisHristov
Ad

More Related Content

What's hot (20)

Database Transactions and SQL Server Concurrency
Database Transactions and SQL Server ConcurrencyDatabase Transactions and SQL Server Concurrency
Database Transactions and SQL Server Concurrency
Boris Hristov
 
The nightmare of locking, blocking and isolation levels!
The nightmare of locking, blocking and isolation levels!The nightmare of locking, blocking and isolation levels!
The nightmare of locking, blocking and isolation levels!
Boris Hristov
 
The nightmare of locking, blocking and isolation levels
The nightmare of locking, blocking and isolation levelsThe nightmare of locking, blocking and isolation levels
The nightmare of locking, blocking and isolation levels
Boris Hristov
 
The nightmare of locking, blocking and isolation levels
The nightmare of locking, blocking and isolation levelsThe nightmare of locking, blocking and isolation levels
The nightmare of locking, blocking and isolation levels
Boris Hristov
 
The Nightmare of Locking, Blocking and Isolation Levels!
The Nightmare of Locking, Blocking and Isolation Levels!The Nightmare of Locking, Blocking and Isolation Levels!
The Nightmare of Locking, Blocking and Isolation Levels!
Boris Hristov
 
Welcome to the nightmare of locking, blocking and isolation levels!
Welcome to the nightmare of locking, blocking and isolation levels!Welcome to the nightmare of locking, blocking and isolation levels!
Welcome to the nightmare of locking, blocking and isolation levels!
Boris Hristov
 
Replay your workload as it is your actual one!
Replay your workload as it is your actual one! Replay your workload as it is your actual one!
Replay your workload as it is your actual one!
Boris Hristov
 
SQL Server Transaction Management
SQL Server Transaction ManagementSQL Server Transaction Management
SQL Server Transaction Management
Denise McInerney
 
11. transaction sql
11. transaction sql11. transaction sql
11. transaction sql
Umang Gupta
 
Welcome to the nightmare of locking, blocking and isolation levels!
Welcome to the nightmare of locking, blocking and isolation levels!Welcome to the nightmare of locking, blocking and isolation levels!
Welcome to the nightmare of locking, blocking and isolation levels!
Boris Hristov
 
Databases: Concurrency Control
Databases: Concurrency ControlDatabases: Concurrency Control
Databases: Concurrency Control
Damian T. Gordon
 
Svetlin Nakov - Database Transactions
Svetlin Nakov - Database TransactionsSvetlin Nakov - Database Transactions
Svetlin Nakov - Database Transactions
Svetlin Nakov
 
Adbms 36 transaction support in sql 2
Adbms 36 transaction support in sql 2Adbms 36 transaction support in sql 2
Adbms 36 transaction support in sql 2
Vaibhav Khanna
 
Databases: Locking Methods
Databases: Locking MethodsDatabases: Locking Methods
Databases: Locking Methods
Damian T. Gordon
 
[Altibase] 6 what is the mvcc
[Altibase] 6 what is the mvcc[Altibase] 6 what is the mvcc
[Altibase] 6 what is the mvcc
altistory
 
[Altibase] 5 durability
[Altibase] 5 durability[Altibase] 5 durability
[Altibase] 5 durability
altistory
 
Concurrency control
Concurrency controlConcurrency control
Concurrency control
Subhasish Pati
 
Concurrency (Distributed computing)
Concurrency (Distributed computing)Concurrency (Distributed computing)
Concurrency (Distributed computing)
Sri Prasanna
 
protocols of concurrency control
protocols of concurrency controlprotocols of concurrency control
protocols of concurrency control
MOHIT DADU
 
2 phase locking protocol DBMS
2 phase locking protocol DBMS2 phase locking protocol DBMS
2 phase locking protocol DBMS
Dhananjaysinh Jhala
 
Database Transactions and SQL Server Concurrency
Database Transactions and SQL Server ConcurrencyDatabase Transactions and SQL Server Concurrency
Database Transactions and SQL Server Concurrency
Boris Hristov
 
The nightmare of locking, blocking and isolation levels!
The nightmare of locking, blocking and isolation levels!The nightmare of locking, blocking and isolation levels!
The nightmare of locking, blocking and isolation levels!
Boris Hristov
 
The nightmare of locking, blocking and isolation levels
The nightmare of locking, blocking and isolation levelsThe nightmare of locking, blocking and isolation levels
The nightmare of locking, blocking and isolation levels
Boris Hristov
 
The nightmare of locking, blocking and isolation levels
The nightmare of locking, blocking and isolation levelsThe nightmare of locking, blocking and isolation levels
The nightmare of locking, blocking and isolation levels
Boris Hristov
 
The Nightmare of Locking, Blocking and Isolation Levels!
The Nightmare of Locking, Blocking and Isolation Levels!The Nightmare of Locking, Blocking and Isolation Levels!
The Nightmare of Locking, Blocking and Isolation Levels!
Boris Hristov
 
Welcome to the nightmare of locking, blocking and isolation levels!
Welcome to the nightmare of locking, blocking and isolation levels!Welcome to the nightmare of locking, blocking and isolation levels!
Welcome to the nightmare of locking, blocking and isolation levels!
Boris Hristov
 
Replay your workload as it is your actual one!
Replay your workload as it is your actual one! Replay your workload as it is your actual one!
Replay your workload as it is your actual one!
Boris Hristov
 
SQL Server Transaction Management
SQL Server Transaction ManagementSQL Server Transaction Management
SQL Server Transaction Management
Denise McInerney
 
11. transaction sql
11. transaction sql11. transaction sql
11. transaction sql
Umang Gupta
 
Welcome to the nightmare of locking, blocking and isolation levels!
Welcome to the nightmare of locking, blocking and isolation levels!Welcome to the nightmare of locking, blocking and isolation levels!
Welcome to the nightmare of locking, blocking and isolation levels!
Boris Hristov
 
Databases: Concurrency Control
Databases: Concurrency ControlDatabases: Concurrency Control
Databases: Concurrency Control
Damian T. Gordon
 
Svetlin Nakov - Database Transactions
Svetlin Nakov - Database TransactionsSvetlin Nakov - Database Transactions
Svetlin Nakov - Database Transactions
Svetlin Nakov
 
Adbms 36 transaction support in sql 2
Adbms 36 transaction support in sql 2Adbms 36 transaction support in sql 2
Adbms 36 transaction support in sql 2
Vaibhav Khanna
 
Databases: Locking Methods
Databases: Locking MethodsDatabases: Locking Methods
Databases: Locking Methods
Damian T. Gordon
 
[Altibase] 6 what is the mvcc
[Altibase] 6 what is the mvcc[Altibase] 6 what is the mvcc
[Altibase] 6 what is the mvcc
altistory
 
[Altibase] 5 durability
[Altibase] 5 durability[Altibase] 5 durability
[Altibase] 5 durability
altistory
 
Concurrency (Distributed computing)
Concurrency (Distributed computing)Concurrency (Distributed computing)
Concurrency (Distributed computing)
Sri Prasanna
 
protocols of concurrency control
protocols of concurrency controlprotocols of concurrency control
protocols of concurrency control
MOHIT DADU
 

Similar to Deep Into Isolation Levels (20)

Database concurrency and transactions - Tal Olier
Database concurrency and transactions - Tal OlierDatabase concurrency and transactions - Tal Olier
Database concurrency and transactions - Tal Olier
sqlserver.co.il
 
Managing Memory & Locks - Series 2 Transactions & Lock management
Managing  Memory & Locks - Series 2 Transactions & Lock managementManaging  Memory & Locks - Series 2 Transactions & Lock management
Managing Memory & Locks - Series 2 Transactions & Lock management
DAGEOP LTD
 
High Availability With InnoDB Clusters
High Availability With InnoDB ClustersHigh Availability With InnoDB Clusters
High Availability With InnoDB Clusters
Mydbops
 
Transactional Memory
Transactional MemoryTransactional Memory
Transactional Memory
Smruti Sarangi
 
Ibm db2 case study
Ibm db2 case studyIbm db2 case study
Ibm db2 case study
Ishvitha Badhri
 
MongoDB World 2019: MongoDB Read Isolation: Making Your Reads Clean, Committe...
MongoDB World 2019: MongoDB Read Isolation: Making Your Reads Clean, Committe...MongoDB World 2019: MongoDB Read Isolation: Making Your Reads Clean, Committe...
MongoDB World 2019: MongoDB Read Isolation: Making Your Reads Clean, Committe...
MongoDB
 
Clustered Architecture Patterns Delivering Scalability And Availability
Clustered Architecture Patterns Delivering Scalability And AvailabilityClustered Architecture Patterns Delivering Scalability And Availability
Clustered Architecture Patterns Delivering Scalability And Availability
ConSanFrancisco123
 
Choosing A Concurrency Model, Optimistic Or Pessimistic
Choosing A Concurrency Model, Optimistic Or PessimisticChoosing A Concurrency Model, Optimistic Or Pessimistic
Choosing A Concurrency Model, Optimistic Or Pessimistic
Vinod Kumar
 
Blazes: coordination analysis for distributed programs
Blazes: coordination analysis for distributed programsBlazes: coordination analysis for distributed programs
Blazes: coordination analysis for distributed programs
palvaro
 
05 Transactions
05 Transactions05 Transactions
05 Transactions
Ranjan Kumar
 
Debugging ZFS: From Illumos to Linux
Debugging ZFS: From Illumos to LinuxDebugging ZFS: From Illumos to Linux
Debugging ZFS: From Illumos to Linux
Serapheim-Nikolaos Dimitropoulos
 
IBM SAN Volume Controller Performance Analysis
IBM SAN Volume Controller Performance AnalysisIBM SAN Volume Controller Performance Analysis
IBM SAN Volume Controller Performance Analysis
brettallison
 
Troubleshooting Deadlocks in SQL Server 2000
Troubleshooting Deadlocks in SQL Server 2000Troubleshooting Deadlocks in SQL Server 2000
Troubleshooting Deadlocks in SQL Server 2000
elliando dias
 
MySQL 5.7 clustering: The developer perspective
MySQL 5.7 clustering: The developer perspectiveMySQL 5.7 clustering: The developer perspective
MySQL 5.7 clustering: The developer perspective
Ulf Wendel
 
The free lunch is over
The free lunch is overThe free lunch is over
The free lunch is over
Thadeu Russo
 
Automatic Loop Parallelization using STM
Automatic Loop Parallelization using STMAutomatic Loop Parallelization using STM
Automatic Loop Parallelization using STM
Amr Abed
 
Kotlin Coroutines and Rx
Kotlin Coroutines and RxKotlin Coroutines and Rx
Kotlin Coroutines and Rx
Shaul Rosenzwieg
 
Specialized Compiler for Hash Cracking
Specialized Compiler for Hash CrackingSpecialized Compiler for Hash Cracking
Specialized Compiler for Hash Cracking
Positive Hack Days
 
Design Patterns for Distributed Non-Relational Databases
Design Patterns for Distributed Non-Relational DatabasesDesign Patterns for Distributed Non-Relational Databases
Design Patterns for Distributed Non-Relational Databases
guestdfd1ec
 
Chronicle accelerate building a digital currency
Chronicle accelerate   building a digital currencyChronicle accelerate   building a digital currency
Chronicle accelerate building a digital currency
Peter Lawrey
 
Database concurrency and transactions - Tal Olier
Database concurrency and transactions - Tal OlierDatabase concurrency and transactions - Tal Olier
Database concurrency and transactions - Tal Olier
sqlserver.co.il
 
Managing Memory & Locks - Series 2 Transactions & Lock management
Managing  Memory & Locks - Series 2 Transactions & Lock managementManaging  Memory & Locks - Series 2 Transactions & Lock management
Managing Memory & Locks - Series 2 Transactions & Lock management
DAGEOP LTD
 
High Availability With InnoDB Clusters
High Availability With InnoDB ClustersHigh Availability With InnoDB Clusters
High Availability With InnoDB Clusters
Mydbops
 
MongoDB World 2019: MongoDB Read Isolation: Making Your Reads Clean, Committe...
MongoDB World 2019: MongoDB Read Isolation: Making Your Reads Clean, Committe...MongoDB World 2019: MongoDB Read Isolation: Making Your Reads Clean, Committe...
MongoDB World 2019: MongoDB Read Isolation: Making Your Reads Clean, Committe...
MongoDB
 
Clustered Architecture Patterns Delivering Scalability And Availability
Clustered Architecture Patterns Delivering Scalability And AvailabilityClustered Architecture Patterns Delivering Scalability And Availability
Clustered Architecture Patterns Delivering Scalability And Availability
ConSanFrancisco123
 
Choosing A Concurrency Model, Optimistic Or Pessimistic
Choosing A Concurrency Model, Optimistic Or PessimisticChoosing A Concurrency Model, Optimistic Or Pessimistic
Choosing A Concurrency Model, Optimistic Or Pessimistic
Vinod Kumar
 
Blazes: coordination analysis for distributed programs
Blazes: coordination analysis for distributed programsBlazes: coordination analysis for distributed programs
Blazes: coordination analysis for distributed programs
palvaro
 
IBM SAN Volume Controller Performance Analysis
IBM SAN Volume Controller Performance AnalysisIBM SAN Volume Controller Performance Analysis
IBM SAN Volume Controller Performance Analysis
brettallison
 
Troubleshooting Deadlocks in SQL Server 2000
Troubleshooting Deadlocks in SQL Server 2000Troubleshooting Deadlocks in SQL Server 2000
Troubleshooting Deadlocks in SQL Server 2000
elliando dias
 
MySQL 5.7 clustering: The developer perspective
MySQL 5.7 clustering: The developer perspectiveMySQL 5.7 clustering: The developer perspective
MySQL 5.7 clustering: The developer perspective
Ulf Wendel
 
The free lunch is over
The free lunch is overThe free lunch is over
The free lunch is over
Thadeu Russo
 
Automatic Loop Parallelization using STM
Automatic Loop Parallelization using STMAutomatic Loop Parallelization using STM
Automatic Loop Parallelization using STM
Amr Abed
 
Specialized Compiler for Hash Cracking
Specialized Compiler for Hash CrackingSpecialized Compiler for Hash Cracking
Specialized Compiler for Hash Cracking
Positive Hack Days
 
Design Patterns for Distributed Non-Relational Databases
Design Patterns for Distributed Non-Relational DatabasesDesign Patterns for Distributed Non-Relational Databases
Design Patterns for Distributed Non-Relational Databases
guestdfd1ec
 
Chronicle accelerate building a digital currency
Chronicle accelerate   building a digital currencyChronicle accelerate   building a digital currency
Chronicle accelerate building a digital currency
Peter Lawrey
 
Ad

More from Boris Hristov (19)

The Secret to Engaging Presentations
The Secret to Engaging PresentationsThe Secret to Engaging Presentations
The Secret to Engaging Presentations
Boris Hristov
 
Presentation Design Fundamentals
Presentation Design FundamentalsPresentation Design Fundamentals
Presentation Design Fundamentals
Boris Hristov
 
The World of Business Intelligence
The World of Business IntelligenceThe World of Business Intelligence
The World of Business Intelligence
Boris Hristov
 
The 5 Hidden Performance Gems of SQL Server 2014
The 5 Hidden Performance Gems of SQL Server 2014The 5 Hidden Performance Gems of SQL Server 2014
The 5 Hidden Performance Gems of SQL Server 2014
Boris Hristov
 
Securing SQL Azure DB? How?
Securing SQL Azure DB? How?Securing SQL Azure DB? How?
Securing SQL Azure DB? How?
Boris Hristov
 
How to Deliver Technical Presentations: The Right Way!
How to Deliver Technical Presentations: The Right Way!How to Deliver Technical Presentations: The Right Way!
How to Deliver Technical Presentations: The Right Way!
Boris Hristov
 
Securing SQL Azure DB? How?
Securing SQL Azure DB? How?Securing SQL Azure DB? How?
Securing SQL Azure DB? How?
Boris Hristov
 
Top 5 T-SQL Improvements in SQL Server 2014
Top 5 T-SQL Improvements in SQL Server 2014Top 5 T-SQL Improvements in SQL Server 2014
Top 5 T-SQL Improvements in SQL Server 2014
Boris Hristov
 
Presentation Skills: The Next Level
Presentation Skills: The Next LevelPresentation Skills: The Next Level
Presentation Skills: The Next Level
Boris Hristov
 
SQL Server 2014: Ready. Steady. Go!
SQL Server 2014: Ready. Steady. Go!SQL Server 2014: Ready. Steady. Go!
SQL Server 2014: Ready. Steady. Go!
Boris Hristov
 
BI PoC for the Telco Industry
BI PoC for the Telco IndustryBI PoC for the Telco Industry
BI PoC for the Telco Industry
Boris Hristov
 
Presentation Design Basics
Presentation Design BasicsPresentation Design Basics
Presentation Design Basics
Boris Hristov
 
Top 5 T-SQL Improvements in SQL Server 2014
Top 5 T-SQL Improvements in SQL Server 2014Top 5 T-SQL Improvements in SQL Server 2014
Top 5 T-SQL Improvements in SQL Server 2014
Boris Hristov
 
Database Performance
Database PerformanceDatabase Performance
Database Performance
Boris Hristov
 
You want rules? You need Policy-Based Management!
You want rules? You need Policy-Based Management!You want rules? You need Policy-Based Management!
You want rules? You need Policy-Based Management!
Boris Hristov
 
The Nightmare of Locking, Blocking and Isolation Levels
The Nightmare of Locking, Blocking and Isolation LevelsThe Nightmare of Locking, Blocking and Isolation Levels
The Nightmare of Locking, Blocking and Isolation Levels
Boris Hristov
 
First Steps with Microsoft SQL Server
First Steps with Microsoft SQL ServerFirst Steps with Microsoft SQL Server
First Steps with Microsoft SQL Server
Boris Hristov
 
Top 5 TSQL Improvements in SQL Server 2014
Top 5 TSQL Improvements in SQL Server 2014Top 5 TSQL Improvements in SQL Server 2014
Top 5 TSQL Improvements in SQL Server 2014
Boris Hristov
 
Replay your workload as it is your actual one!
Replay your workload as it is your actual one! Replay your workload as it is your actual one!
Replay your workload as it is your actual one!
Boris Hristov
 
The Secret to Engaging Presentations
The Secret to Engaging PresentationsThe Secret to Engaging Presentations
The Secret to Engaging Presentations
Boris Hristov
 
Presentation Design Fundamentals
Presentation Design FundamentalsPresentation Design Fundamentals
Presentation Design Fundamentals
Boris Hristov
 
The World of Business Intelligence
The World of Business IntelligenceThe World of Business Intelligence
The World of Business Intelligence
Boris Hristov
 
The 5 Hidden Performance Gems of SQL Server 2014
The 5 Hidden Performance Gems of SQL Server 2014The 5 Hidden Performance Gems of SQL Server 2014
The 5 Hidden Performance Gems of SQL Server 2014
Boris Hristov
 
Securing SQL Azure DB? How?
Securing SQL Azure DB? How?Securing SQL Azure DB? How?
Securing SQL Azure DB? How?
Boris Hristov
 
How to Deliver Technical Presentations: The Right Way!
How to Deliver Technical Presentations: The Right Way!How to Deliver Technical Presentations: The Right Way!
How to Deliver Technical Presentations: The Right Way!
Boris Hristov
 
Securing SQL Azure DB? How?
Securing SQL Azure DB? How?Securing SQL Azure DB? How?
Securing SQL Azure DB? How?
Boris Hristov
 
Top 5 T-SQL Improvements in SQL Server 2014
Top 5 T-SQL Improvements in SQL Server 2014Top 5 T-SQL Improvements in SQL Server 2014
Top 5 T-SQL Improvements in SQL Server 2014
Boris Hristov
 
Presentation Skills: The Next Level
Presentation Skills: The Next LevelPresentation Skills: The Next Level
Presentation Skills: The Next Level
Boris Hristov
 
SQL Server 2014: Ready. Steady. Go!
SQL Server 2014: Ready. Steady. Go!SQL Server 2014: Ready. Steady. Go!
SQL Server 2014: Ready. Steady. Go!
Boris Hristov
 
BI PoC for the Telco Industry
BI PoC for the Telco IndustryBI PoC for the Telco Industry
BI PoC for the Telco Industry
Boris Hristov
 
Presentation Design Basics
Presentation Design BasicsPresentation Design Basics
Presentation Design Basics
Boris Hristov
 
Top 5 T-SQL Improvements in SQL Server 2014
Top 5 T-SQL Improvements in SQL Server 2014Top 5 T-SQL Improvements in SQL Server 2014
Top 5 T-SQL Improvements in SQL Server 2014
Boris Hristov
 
Database Performance
Database PerformanceDatabase Performance
Database Performance
Boris Hristov
 
You want rules? You need Policy-Based Management!
You want rules? You need Policy-Based Management!You want rules? You need Policy-Based Management!
You want rules? You need Policy-Based Management!
Boris Hristov
 
The Nightmare of Locking, Blocking and Isolation Levels
The Nightmare of Locking, Blocking and Isolation LevelsThe Nightmare of Locking, Blocking and Isolation Levels
The Nightmare of Locking, Blocking and Isolation Levels
Boris Hristov
 
First Steps with Microsoft SQL Server
First Steps with Microsoft SQL ServerFirst Steps with Microsoft SQL Server
First Steps with Microsoft SQL Server
Boris Hristov
 
Top 5 TSQL Improvements in SQL Server 2014
Top 5 TSQL Improvements in SQL Server 2014Top 5 TSQL Improvements in SQL Server 2014
Top 5 TSQL Improvements in SQL Server 2014
Boris Hristov
 
Replay your workload as it is your actual one!
Replay your workload as it is your actual one! Replay your workload as it is your actual one!
Replay your workload as it is your actual one!
Boris Hristov
 
Ad

Recently uploaded (20)

Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
Transcript: #StandardsGoals for 2025: Standards & certification roundup - Tec...
BookNet Canada
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdfComplete Guide to Advanced Logistics Management Software in Riyadh.pdf
Complete Guide to Advanced Logistics Management Software in Riyadh.pdf
Software Company
 
Semantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AISemantic Cultivators : The Critical Future Role to Enable AI
Semantic Cultivators : The Critical Future Role to Enable AI
artmondano
 
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
AI Changes Everything – Talk at Cardiff Metropolitan University, 29th April 2...
Alan Dix
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
AI EngineHost Review: Revolutionary USA Datacenter-Based Hosting with NVIDIA ...
SOFTTECHHUB
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In FranceManifest Pre-Seed Update | A Humanoid OEM Deeptech In France
Manifest Pre-Seed Update | A Humanoid OEM Deeptech In France
chb3
 
Cyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of securityCyber Awareness overview for 2025 month of security
Cyber Awareness overview for 2025 month of security
riccardosl1
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
Rusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond SparkRusty Waters: Elevating Lakehouses Beyond Spark
Rusty Waters: Elevating Lakehouses Beyond Spark
carlyakerly1
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptxIncreasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Increasing Retail Store Efficiency How can Planograms Save Time and Money.pptx
Anoop Ashok
 

Deep Into Isolation Levels

  • 1. DEEP INTO ISOLATION LEVELS Boris Hristov SQLBits, Superheroes, 2015
  • 2. That’s not a Hekaton Talk! (In-Memory OLTP)
  • 3. So who am I? @BorisHristov
  • 6. Pessimistic Concurrency Optimistic Concurrency Locks Blocking Versions Version Store Update Conflicts Locks Locking Blocking Deadlocks Lock Escalations
  • 7. Common lock types Intent Used for: Preventing incompatible locks Duration: End of the transaction Shared (S) Used for: Reading Duration: Released almost immediately (depends on the isolation level) Update (U) Used for: Preparing to modify Duration: End of the transaction or until converted to exclusive (X) Exclusive (X) Used for: Modifying Duration: End of the transaction
  • 8. Lock Compatibility Lock Shared Update Exclusive Shared (S)   X Update (U)  X X Exclusive (X) X X X
  • 10. Let’s update a row. What do we need? USE AdventureWorks2012 GO UPDATE [Person].[Address] SET AddressLine1=‘London, UK' WHERE AddressID=2 S IX Header Row Row Row Row Row IX X A query! 
  • 11. Methods to View Locking Information Dynamic Management Views SQL Server Profiler or Extended Events Performance monitor or Activity Monitor
  • 14. SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED (NOLOCK?) Transaction 1 Transaction 2 Suggestion: Better offload the reads or go with optimistic level concurrency! Select Update eXclusive lock Read Uncommitted (pessimisticconcurrencycontrol) Dirty read
  • 15. SET TRANSACTION ISOLATION LEVEL READ COMMITTED Transaction 1 rows Non-repeatable reads possible (updates during Transaction 1) Phantom records possible (inserts during Transaction 1) What else? (that’s a Pluralsight voucher right here!) Updates and Inserts Transaction 2 Read Committed (pessimisticconcurrencycontrol) S S S S
  • 16. SET TRANSACTION ISOLATION LEVEL REPEATABLE READ Transaction 1 S(hared) lock select No non-repeatable reads possible (updates during Transaction 1) Phantom records still possible (inserts during Transaction 1) Update Transaction 2 Repeatable Read (pessimisticconcurrencycontrol)
  • 17. Transaction 1 S(hared) lock select Even phantom records are not possible! Highest pessimistic level of isolation, lowest level of concurrency Oh, yeah, TransactionScope in C# and MSDTC transactions default to this level too Insert Transaction 2 Serializable (pessimisticconcurrencycontrol) SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
  • 18. DEMO Playing with Isolation levels (Pessimistic Concurrency)
  • 20. Read Committed and Snapshot Isolation levels  RCSI – Read Committed Snapshot Isolation Level  Statement level versioning  Requires ALTER DATABASE SET READ_COMMITTED_SNAPSHOT ON  Snapshot Isolation Level  Transaction level versioning  Requires ALTER DATABASE SET ALLOW_SNAPSHOT_ISOLATION ON  Requires SET TRANSACTION ISOLATION LEVEL SNAPSHOT V1 V2 Transaction 1 Transaction 2 Select in RCSISelect Select in SI
  • 21. DEMO Playing with Isolation levels (Optimistic Concurrency) … and Azure DB too
  • 22. Just before we end…
  • 23. Isolation levels can have dramatic impact on your application As such, isolation levels must also be a business decision The behavior of the readers changes in the various levels Writers, though, will always block. No matter what! And one more thing – please be careful with ORMs  Summary