Transactions, Locking and Query Optimisation

Slides:



Advertisements
Similar presentations
Transactions - Concurrent access & System failures - Properties of Transactions - Isolation Levels 4/13/2015Databases21.
Advertisements

Chapter 16 Concurrency. Topics in this Chapter Three Concurrency Problems Locking Deadlock Serializability Isolation Levels Intent Locking Dropping ACID.
1 Lecture 11: Transactions: Concurrency. 2 Overview Transactions Concurrency Control Locking Transactions in SQL.
Concurrency Control Amol Deshpande CMSC424. Approach, Assumptions etc.. Approach  Guarantee conflict-serializability by allowing certain types of concurrency.
Concurrency Control II. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Physical Design.
1 Data Concurrency David Konopnicki 1997 Revised by Mordo Shalom 2004.
Transactions and Locking Rose-Hulman Institute of Technology Curt Clifton.
Concurrency Control and Recovery In real life: users access the database concurrently, and systems crash. Concurrent access to the database also improves.
Transactions and Locks
Module 15: Managing Transactions and Locks. Overview Introduction to Transactions and Locks Managing Transactions SQL Server Locking Managing Locks.
Granularity of Locks and Degrees of Consistency in a Shared Data Base John LaFontaine Haixuan Sun.
DBMS Functions Data, Storage, Retrieval, and Update
Dec 15, 2003Murali Mani Transactions and Security B term 2004: lecture 17.
Database Administration Part 1 Chapter Six CSCI260 Database Applications.
Managing Concurrency in Web Applications. DBI 2007 HUJI-CS 2 Intersection of Concurrent Accesses A fundamental property of Web sites: Concurrent accesses.
Chapter 9 Overview  Reasons to monitor SQL Server  Performance Monitoring and Tuning  Tools for Monitoring SQL Server  Common Monitoring and Tuning.
Transaction Management Chapter 9. What is a Transaction? A logical unit of work on a database A logical unit of work on a database An entire program An.
Managing Transaction and Lock Vu Tuyet Trinh Hanoi University of Technology 1.
1 IT420: Database Management and Organization Transactions 31 March 2006 Adina Crăiniceanu
Transactions and Exception Handling Eric Allsop SQLBits 6 th October 2007.
1cs Intersection of Concurrent Accesses A fundamental property of Web sites: Concurrent accesses by multiple users Concurrent accesses intersect.
Transaction processing Book, chapter 6.6. Problem: With a single user…. you run a query, you get the results, you run the next, etc. But database life.
Concurrency and Transaction Processing. Concurrency models 1. Pessimistic –avoids conflicts by acquiring locks on data that is being read, so no other.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 136 Database Systems I SQL Modifications and Transactions.
How transactions work A transaction groups a set of Transact-SQL statements so that they are treated as a unit. Either all statements in the group are.
Module 11 Creating Highly Concurrent SQL Server® 2008 R2 Applications.
Transactions and Locks A Quick Reference and Summary BIT 275.
Random Logic l Forum.NET l Transaction Isolation Levels Forum.NET Meeting ● Nov
XA Transactions.
Giovanni Chierico | May 2012 | Дубна Data Concurrency, Consistency and Integrity.
SQLintersection Understanding Transaction Isolation Levels Randy Knight Wednesday, 3:45-5:00.
CSC 411/511: DBMS Design Dr. Nan WangCSC411_L12_JDBC_MySQL 1 Transations.
1 Advanced Database Concepts Transaction Management and Concurrency Control.
Module 11: Managing Transactions and Locks
Module 14: Managing Transactions and Locks. Overview Introducing Transactions and Locks Managing Transactions Understanding SQL Server Locking Architecture.
In this session, you will learn to: Implement triggers Implement transactions Objectives.

Locks, Blocks & Isolation Oh My!. About Me Keith Tate Data Professional for over 14 Years MCITP in both DBA and Dev tracks
SQLintersection Locks, Blocks, and Deadlocks Oh My! Randy Knight Wednesday, 2:15-3:15.
Database Transactions  Transaction Management and Concurrency Control.
Indexes By Adrienne Watt.
Concurrency Control Managing Hierarchies of Database Elements (18.6)
Transaction Management and Concurrency Control
LAB: Web-scale Data Management on a Cloud
Data Warehousing Group Transaction Processing
Isolation Levels Understanding Transaction Temper Tantrums
Transaction Processing
Locks, Blocks, and Deadlocks; Tame the Sibling Rivalry SQL Server Family Management ~ Wolf ~ This template can be used as a starter file for presenting.
J.N GRAY R.A LORIE IBM RESEARCH LAB, SAN JOSE, CALIFORNIA
Transaction Properties
On transactions, and Atomic Operations
Batches, Transactions, & Errors
March 9th – Transactions
Chapter 10 Transaction Management and Concurrency Control
The PROCESS of Queries John Deardurff Website: ThatAwesomeTrainer.com
Understanding Transaction Isolation Levels
On transactions, and Atomic Operations
Batches, Transactions, & Errors
Introduction of Week 13 Return assignment 11-1 and 3-1-5
Objectives Define and describe transactions
Transactions and Concurrency
Concurrency Control E0 261 Prasad Deshpande, Jayant Haritsa
Sioux Falls, SD | Hosted by (605) SQL
Database Administration
Chapter 11 Managing Databases with SQL Server 2000
About Wolf DBA for over 19 years At RDX for nearly 9
Isolation Levels Understanding Transaction Temper Tantrums
Module 13: Creating Highly Concurrent SQL Server 2012 Applications
-Transactions in SQL -Constraints and Triggers
Advanced Topics: Indexes & Transactions
Presentation transcript:

Transactions, Locking and Query Optimisation Training – 26th July 2010 Zed-Axis Technologies

Transaction Basics provide you with the capability of performing a series of commands in an "all or nothing" fashion Exhibit Four Properties (ACID): Atomicity – either all or none Consistency – leave data in consistent state Isolation – independent of all other transactions Durability – data is in persistent state Autocommit or Explicit

Nesting Transactions Nesting is only possible with Explicit Transactions Successive BEGIN TRAN Statements Increment @@trancount Each COMMIT TRAN Decrements @@trancount When @@trancount reaches 0, COMMIT occurs ROLLBACK Sets @@trancount to 0

Demo 1 Nesting Transactions

Transaction Isolation Level defines the degree to which one transaction must be isolated from resource or data modifications made by other transactions a transaction isolation level does not affect the locks acquired to protect data modifications. It affects the level of protection for read operations True Isolation is expensive Trade off between correctness and concurrency

Isolation Levels and Operation Allowed Dirty read Nonrepeatable read Phantom Read uncommitted Yes Read committed No Repeatable read Serializable

Demo 2 Repeatable Read Isolation

Aspects of Locking Type of Lock Duration of Lock Granularity Shared Exclusive Update Duration of Lock Shared locks held until done reading Exclusive locks held until end of transaction Granularity

Granularity of Locks: Resources Row/Key Page Table Extent Database

Multi Granular Locking To lock a fine level, SQL Server places Intent Locks at higher levels.

Demo 3 Multi granular locking

Locking Granularity Default is row or key lock After optimization, SQL Server may decide to lock pages or the whole table If too much memory is used for locks If optimizer has decided to do a scan Row/key and page locks can be escalated during execution Escalation is always to a table – based on total locks SQL Trace lets you monitor escalations Tradeoff is resources used vs. concurrency

Dynamic Locking Row Locking Is Not Always Best Sometimes Page or Table Locking Is the Optimal Way to Scan SQL Server’s Strategy is Dynamic SQL Server chooses the lowest cost locking strategy (Row, Page, or Table) at run time based upon input from the query optimizer Multiple Row or Page Locks Can Escalate to TABLE lock

Demo 4 Lock Escalation

Lock Compatibility Requested mode Existing granted mode IS S U IX SIX   IS S U IX SIX X Intent shared (IS) Yes No Shared (S) Update (U) Intent exclusive (IX) Shared with intent exclusive (SIX) Exclusive (X)

Avoiding Blocking Keep transactions as short as possible Isolate and Tune Long Running Queries No user interaction during transactions Transactions should not be started until all preliminary data analysis has been done. Rollback when canceling, or on any error or timeout Acess least amount of data possible in transaction Stress test at maximum projected user load Acess heavily used data at the end of transaction

Understanding Query Plan Table scans—Table scans are the slowest way for SQL Server to look up data. Index seek—This type of operation uses a non-clustered index to look up table results. Table Lookup - index’s pointer to find the actual row of data within the table. Clustered index Scan – Similar to table scan, and generally indicate a performance problem in a large table. Clustered Index Seek - Similar to an index seek, this operation runs through a table’s clustered index to locate query results. Joins—SQL Server will include one or more join operations in a query plan when necessary.

Increase Query Performance Use NOCOUNT in SP Reduce network overhead Return only those values which are required Do not use DISTINCT keyword unless required Define all Primary and Foreign Key Relationships Define all unique and check constraints Avoid Like operation with wildcard on both sides ‘%a%’ Use FQDN Objects Do not use sp_ prefix for customer stored procedures Use Union ALL instead of Union wherever possible. Use functions carefully in where clause