READPAST & Furious: Transactions, Locking and Isolation



Similar documents
W I S E. SQL Server 2008/2008 R2 Advanced DBA Performance & WISE LTD.

Concurrency in SQL Server Kalen Delaney Solid Quality Learning Kalen Delaney

TRANSACÇÕES. PARTE I (Extraído de SQL Server Books Online )

Would-be system and database administrators. PREREQUISITES: At least 6 months experience with a Windows operating system.

Lecture 7: Concurrency control. Rasmus Pagh

Dynamics NAV/SQL Server Configuration Recommendations

SQL Server Performance Tuning and Optimization

Chapter 6 The database Language SQL as a tutorial

Guerrilla Warfare? Guerrilla Tactics - Performance Testing MS SQL Server Applications

Microsoft SQL Server: MS Performance Tuning and Optimization Digital

Module 2: Database Architecture

Transactions and Concurrency Control. Goals. Database Administration. (Manga Guide to DB, Chapter 5, pg , ) Database Administration

Goals. Managing Multi-User Databases. Database Administration. DBA Tasks. (Kroenke, Chapter 9) Database Administration. Concurrency Control

SQL Server 2012 Query. Performance Tuning. Grant Fritchey. Apress*

Inside Microsoft SQL Server 2005: The Storage Engine

SQL Server 2012 Optimization, Performance Tuning and Troubleshooting

"Charting the Course... MOC AC SQL Server 2014 Performance Tuning and Optimization. Course Summary

VirtualCenter Database Performance for Microsoft SQL Server 2005 VirtualCenter 2.5

ODBC Chapter,First Edition

How To Improve Performance In A Database

Microsoft SQL Server for Oracle DBAs Course 40045; 4 Days, Instructor-led

Jason S Wong Sr. DBA IT Applications Manager DBA Developer Programmer M.S. Rice 88, MBA U.H. 94(MIS)

Microsoft SQL Server performance tuning for Microsoft Dynamics NAV

Transaction Management Overview

Using Database Performance Warehouse to Monitor Microsoft SQL Server Report Content

Boost SQL Server Performance Buffer Pool Extensions & Delayed Durability

Solving Performance Problems In SQL Server by Michal Tinthofer

The first time through running an Ad Hoc query or Stored Procedure, SQL Server will go through each of the following steps.

F1: A Distributed SQL Database That Scales. Presentation by: Alex Degtiar (adegtiar@cmu.edu) /21/2013

Course 55144: SQL Server 2014 Performance Tuning and Optimization

Copyright 2014, Oracle and/or its affiliates. All rights reserved.

SQL Server Transaction Log from A to Z

Microsoft SQL Server OLTP Best Practice

SQL Server 2014 In-Memory Tables (Extreme Transaction Processing)

The Oracle Universal Server Buffer Manager

MOC 20462C: Administering Microsoft SQL Server Databases

MOC Administering Microsoft SQL Server 2014 Databases

Introduction. Part I: Finding Bottlenecks when Something s Wrong. Chapter 1: Performance Tuning 3

Performance Tuning and Optimizing SQL Databases 2016

MS-40074: Microsoft SQL Server 2014 for Oracle DBAs

David Dye. Extract, Transform, Load

Administering Microsoft SQL Server 2012 Databases

5. CHANGING STRUCTURE AND DATA

Mind Q Systems Private Limited

A Performance Engineering Story

End the Microsoft Access Chaos - Your simplified path to Oracle Application Express

SQL Server 2008 Designing, Optimizing, and Maintaining a Database Session 1

MOC 20461C: Querying Microsoft SQL Server. Course Overview

SQL Server 2012 Database Administration With AlwaysOn & Clustering Techniques

SSMS Built in Reports for Server and Database Monitoring

Professional SQL Server 2012 Internals and Troubleshooting

Java DB Performance. Olav Sandstå Sun Microsystems, Trondheim, Norway Submission ID: 860

SQL Server Administrator Introduction - 3 Days Objectives

Optimizing SQL Server 2012 for SharePoint SharePoint Saturday/Friday, Honolulu March 27, 2015

Microsoft SQL Server Beginner course content (3-day)

SAP HANA - Main Memory Technology: A Challenge for Development of Business Applications. Jürgen Primsch, SAP AG July 2011

Real-time Data Replication

Enhancing SQL Server Performance

Course 55144B: SQL Server 2014 Performance Tuning and Optimization

VMware vcenter 4.0 Database Performance for Microsoft SQL Server 2008

SQL Server 2014 New Features/In- Memory Store. Juergen Thomas Microsoft Corporation

Oracle Database Development Standards For DNR Staff and Contractors. Table of Contents

Microsoft SQL Database Administrator Certification

SQL Server 2008 Administration

Oracle Architecture. Overview

PHP on IBM i: What s New with Zend Server 5 for IBM i

Module 15: Monitoring

Data Compression in Blackbaud CRM Databases

Physical DB design and tuning: outline

Predicting Change Outcomes Leveraging SQL Server Profiler

SQL Server for developers. murach's TRAINING & REFERENCE. Bryan Syverson. Mike Murach & Associates, Inc. Joel Murach

SQL Server. DMVs in Action. Better Queries with. Dynamic Management Views MANNING IANW. STIRK. Shelter Island

Estimate Performance and Capacity Requirements for Workflow in SharePoint Server 2010

SQL DATABASE PROGRAMMING (PL/SQL AND T-SQL)

10775 Administering Microsoft SQL Server Databases

OTM Performance OTM Users Conference Jim Mooney Vice President, Product Development August 11, 2015

PERFORMANCE TUNING IN MICROSOFT SQL SERVER DBMS

I-Motion SQL Server admin concerns

Monitoring and Diagnosing Oracle RAC Performance with Oracle Enterprise Manager

MS SQL Performance (Tuning) Best Practices:

6231B: Maintaining a Microsoft SQL Server 2008 R2 Database

DirectQuery vs In-Memory in BISM

FHE DEFINITIVE GUIDE. ^phihri^^lv JEFFREY GARBUS. Joe Celko. Alvin Chang. PLAMEN ratchev JONES & BARTLETT LEARN IN G. y ti rvrrtuttnrr i t i r

MS-10775: Administering Microsoft SQL Server 2012 Databases. Course Objectives. Required Exam(s) Price. Duration. Methods of Delivery.

Outline. Failure Types

W I S E. SQL Server 2012 Database Engine Technical Update WISE LTD.

Before attending this course, participants should have:

MS SQL Server 2000 Data Collector. Status: 12/8/2008

Oracle. Brief Course Content This course can be done in modular form as per the detail below. ORA-1 Oracle Database 10g: SQL 4 Weeks 4000/-

SQL Server 2016 New Features!

Oracle to SQL Server 2005 Migration

Microsoft SQL Server 2005 for the Oracle Professional

Optimizing Performance. Training Division New Delhi

6231A - Maintaining a Microsoft SQL Server 2008 Database

What is the BI DBA? Jorge Segarra Sr. DBA Consultant, SQL Server MVP

Transcription:

READPAST & Furious: Locking Blocking and Isolation Mark Broadbent sqlcloud.co.uk READPAST & Furious: Transactions, Locking and Isolation Mark Broadbent SQLCloud

Agenda TRANSACTIONS Structure, Scope and Management LOCKING Compatibility, Multi Granularity and Escalation NOLOCK, READPAST and UPDLOCK ISOLATION Snapshot Isolation and Read Committed Snapshot Rolling Database Snapshots

A bit more about little old me! More than 21 years in IT and more than 15 years using SQL Server. Worked at many large global corporations and SMEs such as Microsoft, Nokia, Hewlett Packard and Encyclopaedia Britannica. Blog: tenbulls.co.uk Cambridgeshire SQL UG Leader sqlcambs.org.uk Presented at SQLBits 7, 8 (and now 9), SQL Rally Orlando Awarded Microsoft Community Contributor Award 2011 MCITP DB Development SQL 2008 MCITP DBA SQL 2008/ 2005 and MCDBA SQL 2000 Microsoft Certified Application Developer (C#.net) Microsoft Certified Systems Engineer + Internet Participate on #sqlhelp, MSDN Forums LinkedIn SQL Server Scripting Group http://linkd.in/pfbkri JOIN US!!!

Transactions basically Provide Atomicity (all or nothing) or does it! Can be defined as Implicit (evil), Explicit (declarative) or Auto-Commit (default) Effect duration of locks Transactions can have batch scope (MARS), be distributed and even be bound across sessions or servers. Can be really confusing!

Transactions are easy-peasy BEGIN TRAN transaction_1 WITH MARK restorepoint BEGIN TRAN --do something COMMIT TRAN SAVE TRAN savepoint BEGIN TRAN transaction_3 BEGIN TRAN --do something else COMMIT Transaction Name Transaction Mark Savepoint Nested Transaction IF {something_wrong} THEN ROLLBACK TRAN savepoint COMMIT COMMIT

READPAST & Furious: Locking Blocking and Isolation Mark Broadbent sqlcloud.co.uk Transactions Demo

Locks, the Lock Manager and Locking Locks are memory structures only and can be converted or escalated have a compatibility or incompatibility with other locks are taken depending upon the Isolation level can cause blocking or deadlocks will wait if they are incompatible Lock Manager compares locks ONLY on same resource and that s why so intent locks are needed (granular) Lock escalation will occur for performance and memory savings and escalate straight to Table by default (not partitions)!!! but you can turn off ALL escalation (TF1211), due to # locks (TF1224) or artificially by taking IS on table or by ALTER statement <table> SET (LOCK_ESCALATION = auto table disable)

NL SCH-S SCH-M S U X IS IU IX SIU SIX UIX BU RS-S RS-U RI-N RI-S RI-U RI-X RX-S RX-U RX-X NL SCH-S SCH-M S U X IS IU IX SIU SIX UIX BU RS-S RS-U RI-N RI-S RI-U RI-X RX-S RX-U RX-X No Conflict Conflict Illegal SQL Server Lock Compatibility Chart NL SCH-S SCH-M S U X IS IU No Lock Schema Stability Lock Schema Modification Lock Shared Update Exclusive Intent Shared Intent Update IX SIU SIX UIX BU RS-S RS-U RI-N Intent Exclusive Share with Intent Update Share with Intent Exclusive Update with Intent Exclusive Bulk Update Shared Range-Shared Shared Range-Update Insert Range-Null RI-S RI-U RI-X RX-S RX-U RX-X Insert Range-Shared Insert Range-Update Insert Range-Exclusive Exclusive Range-Shared Exclusive Range-Update Exclusive Range-Exclusive

Intent Locks Lock must wait! IX X orders Table Data Page IX Free Space X Row

NOLOCK (a Wolf in Sheep s clothing?) Should use READUNCOMMITTED hint instead. Doesn t acquire Shared locks so is able to perform DIRTY READS, NON-REPEATABLE READS, PHANTOMS and I bet you didn t know it can also return DUPLICATE READS! It DOES NOT give Oracle style concurrency When can this ever be acceptable?

Well since you mention it Scalable Shared Database SQL Server Instance B Instance C There is NOLOCK Database Snapshot SQL Server Instance A Filegroup1 Filegroup2 Readonly Database Filegroup3 Readonly Filegroup/s When should you use NOLOCK? http://bit.ly/rdgzow

READPAST & (your boss) may be Furious! Is an alternative to NOLOCK/ READUNCOMMITTED. Skip over resources holding incompatible (to S) locks. Does not therefore cause dirty or duplicate reads. (yay!) But It still DOES NOT give Oracle style concurrency and can return INCOMPLETE DATA SETS! When can this ever be acceptable?

Using READPAST and Table Queues X U orders X U --Get the first record --possible and update UPDATE u SET FROM ( SELECT TOP(1) * FROM orders WITH (READPAST,UPDLOCK) WHERE ) AS U 2 1

READPAST & Furious: Locking Blocking and Isolation Mark Broadbent sqlcloud.co.uk Locking Demo

Read Committed Snapshot vs Snapshot Isolation SI provides isolation at the transaction level, RCS provides isolation at the statement level SI must be explicitly SET in each connection, for RCS it becomes the new default Enabling SI level requires no active transactions in order to transition. Enabling RCS requires Exclusive Transaction Workspace lock (and therefore no other connections to DB). RCS not allowed on master, tempdb and msdb, SI is allowed SI implements automatic update conflict detection

1 Database Snapshots BEGIN TRAN UPDATE orders SET WHERE Buffer Cache COMMIT SELECT * FROM orders o 4 5 2 CHECKPOINT 3 Data FIle Transaction Log

READPAST & Furious: Locking Blocking and Isolation Mark Broadbent sqlcloud.co.uk Snapshots Demo

References and Thanks Professional SQL Server 2008 Internals and Troubleshooting Locking and Latches Chapter - James Rowland Jones Kalen Delaney, SQLPASS Summit 2011 DBA301P - Locking and Blocking and Row Versions, Oh My! DVD Jose Barreto's Blog http://blogs.technet.com/b/josebda/archive/2009/03/19/sql-server-2008- locking.aspx A special thanks to :- Paul White @sql_kiwi http://sqlblog.com/blogs/paul_white Benjamin Neverez @BenjaminNeverez http://www.benjaminnevarez.com/