sql server 2005 engine optimistic concurrency tony rogerson, sql server mvp independent consultant ...

10
SQL Server 2005 Engine Optimistic Concurrency Tony Rogerson, SQL Server MVP Independent Consultant http://sqlserverfaq.com [email protected] 26 th January 2006 12:45 – 13:15 Lunch n Learn webcast series

Upload: cori-flynn

Post on 17-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SQL Server 2005 Engine Optimistic Concurrency Tony Rogerson, SQL Server MVP Independent Consultant  tonyrogerson@torver.net 26 th

SQL Server 2005 Engine

Optimistic Concurrency

Tony Rogerson, SQL Server MVPIndependent Consultanthttp://sqlserverfaq.com [email protected]

26th January 200612:45 – 13:15

Lunch n Learn webcast series

Page 2: SQL Server 2005 Engine Optimistic Concurrency Tony Rogerson, SQL Server MVP Independent Consultant  tonyrogerson@torver.net 26 th

Agenda

• Isolations– Pessimistic

• Default Isolation – Writers block Readers

– Optimistic• READ_COMMITTED_SNAPSHOT

(statement level read consistency)• ALLOW_SNAPSHOT_ISOLATION

(transaction level read consistency)

• Architecture: Row Versioning• Monitoring

Page 3: SQL Server 2005 Engine Optimistic Concurrency Tony Rogerson, SQL Server MVP Independent Consultant  tonyrogerson@torver.net 26 th

Uses

• Anything to reduce locking contention

• Near real-time statistics page (call centre, stock ticker)

• Anywhere using NOLOCK hint• Extraction from OLTP into DW/MIS• Not an answer for deadlocking but

will reduce locking and may help

Page 4: SQL Server 2005 Engine Optimistic Concurrency Tony Rogerson, SQL Server MVP Independent Consultant  tonyrogerson@torver.net 26 th

Demo

Page 5: SQL Server 2005 Engine Optimistic Concurrency Tony Rogerson, SQL Server MVP Independent Consultant  tonyrogerson@torver.net 26 th

Row Versioning

Sess A: UPDATE -> ‘START’

Sess B: XACT ISO – SNAPSHOTBEGIN TRAN SELECT…

Store old row ‘START’Sess A: UPDATE -> ‘UPD 1’

Sess C: XACT ISO – SNAPSHOTBEGIN TRAN SELECT…

Mark active

Mark active

Remove by clean up

Store old row ‘UPD 1’Sess A: UPDATE -> ‘UPD 2’

Page 6: SQL Server 2005 Engine Optimistic Concurrency Tony Rogerson, SQL Server MVP Independent Consultant  tonyrogerson@torver.net 26 th

READ_COMMITTED_SNAPSHOT

• Statement level isolation (gives value of last committed row at time of query)

• Writer no longer blocks reader• Possibly reduced deadlocking

because of reduced locking contention

Page 7: SQL Server 2005 Engine Optimistic Concurrency Tony Rogerson, SQL Server MVP Independent Consultant  tonyrogerson@torver.net 26 th

ALLOW_SNAPSHOT_ISOLATION

• Transaction level isolation (gives last committed row at start of transaction)

• Snapshot of values taken on select and held in version store in tempdb

• Stores full row (changed fragment for lob)

• Queries require SET TRANSACTION ISOLATION LEVEL SNAPSHOT

• Update fails if update on a value changed outside your snapshot

Page 8: SQL Server 2005 Engine Optimistic Concurrency Tony Rogerson, SQL Server MVP Independent Consultant  tonyrogerson@torver.net 26 th

Architecture: Row Versioning

• Used by other stuff…– inserted and deleted tables in triggers– MARS (Multiple Active Result Sets)– Index operations using the ONLINE feature– Transaction Isolations

• Versions held in tempdb (the version store)• Changed row or changed fragment for LOB stored

in tempdb• Background thread runs every minute to remove

versions no longer required.• Short lived transactions will not require a disk IO

on tempdb

Page 9: SQL Server 2005 Engine Optimistic Concurrency Tony Rogerson, SQL Server MVP Independent Consultant  tonyrogerson@torver.net 26 th

Monitoring

• sys.dm_tran_active_snapshot_database_transactions

• sys.dm_tran_version_store• sys.dm_tran_current_transaction

• sys.dm_tran_transactions_snapshot• sys.dm_tran_top_version_generators

• sys.dm_tran_locks

Page 10: SQL Server 2005 Engine Optimistic Concurrency Tony Rogerson, SQL Server MVP Independent Consultant  tonyrogerson@torver.net 26 th

Thanks for Listening

Q & A

Tony Rogerson, SQL Server MVPIndependent Consultanthttp://sqlserverfaq.com [email protected]