When I Use NOLOCK AND OTHER HINTS

Slides:



Advertisements
Similar presentations
Module 13: Performance Tuning. Overview Performance tuning methodologies Instance level Database level Application level Overview of tools and techniques.
Advertisements

Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
Oracle Locking Michael Messina Principal Database Analyst Indiana University.
1 CS 430 Database Theory Winter 2005 Lecture 16: Inside a DBMS.
SQL Server 2005 Engine Optimistic Concurrency Tony Rogerson, SQL Server MVP Independent Consultant 26 th.
Module 6: Data Protection. Overview What does Data Protection include? Protecting data from unauthorized users and authorized users who are trying to.
SQLintersection Understanding Transaction Isolation Levels Randy Knight Wednesday, 3:45-5:00.
Analysing Indexes SQLBits 6 th October 2007 © Colin Leversuch-Roberts Kelem Consulting Limited September 2007.
1 Chapter 9 Tuning Table Access. 2 Overview Improve performance of access to single table Explain access methods – Full Table Scan – Index – Partition-level.
Copyright Sammamish Software Services All rights reserved. 1 Prog 140  SQL Server Performance Monitoring and Tuning.
Does the Optimistic Concurrency resolve your blocking problems Margarita Naumova, SQL Master Academy.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
Locks, Blocks & Isolation Oh My!. About Me Keith Tate Data Professional for over 14 Years MCITP in both DBA and Dev tracks
Read Dirty to Me: SQL Server Isolation Levels Wendy Pastrick Arrow IT Consulting.
Joe Sack, Principal Program Manager, Microsoft
In-Memory Capabilities
Query Optimization Techniques
Stored Procedures – Facts and Myths
Locks, Blocks, and Deadlocks; Tame the Sibling Rivalry SQL Server Family Management ~ Wolf ~ This template can be used as a starter file for presenting.
Antonio Abalos Castillo
AlwaysOn Readable Secondary
Weird Stuff I Saw While ... Supporting a Java Team
Let Me Finish... Isolating Write Operations
Isolation Levels Understanding Transaction Temper Tantrums
Building Modern Transaction Systems on SQL Server
Weird Stuff I Saw While ... Supporting a Java Team
Database Performance Tuning and Query Optimization
Let Me Finish... Isolating Write Operations
Let Me Finish... Isolating Write Operations
Introduction to Execution Plans
Weird Stuff I Saw While ... Supporting a Java Team
Locks, Blocks, and Deadlocks; Tame the Sibling Rivalry SQL Server Family Management ~ Wolf ~ This template can be used as a starter file for presenting.
When I Use NOLOCK AND OTHER HINTS
Cardinality Estimator 2014/2016
Query Optimization Techniques
Top Tips for Better TSQL Stored Procedures
Batches, Transactions, & Errors
Execution Plans Demystified
Stop Wasting Time & Resources: Performance Tune Your Jobs
Transactions, Locking and Query Optimisation
The PROCESS of Queries John Deardurff
Weird Stuff I Saw While ... Supporting a Java Team
When I Use NOLOCK AND OTHER HINTS
The PROCESS of Queries John Deardurff Website: ThatAwesomeTrainer.com
Understanding Transaction Isolation Levels
Weird Stuff I Saw While … Working With Heaps
Why Is My DBA So Grumpy When I Use NOLOCK?
Parameter Sniffing: the Good, the Bad, and the Ugly
The PROCESS of Queries John Deardurff
Let Me Finish... Isolating Write Operations
Batches, Transactions, & Errors
Replicated data consistency explained through baseball
Introduction to Execution Plans
Let Me Finish... Isolating Write Operations
Parameter Sniffing: the Good,the Bad, and the Ugly
Parameter Sniffing: the Good, the Bad, and the Ugly
Chapter 11 Database Performance Tuning and Query Optimization
Sioux Falls, SD | Hosted by (605) SQL
Diving into Query Execution Plans
Weird Stuff I Saw While … Working With Heaps
A Masters view on Locking and blocking
Jean Joseph DBA\DEVELOPER
Introduction to Execution Plans
Query Optimization Techniques
About Wolf DBA for over 19 years At RDX for nearly 9
Isolation Levels Understanding Transaction Temper Tantrums
Introduction to Execution Plans
Module 13: Creating Highly Concurrent SQL Server 2012 Applications
Performance Tuning ETL Process
A Masters view on Locking and blocking
Presentation transcript:

When I Use NOLOCK AND OTHER HINTS Why Is My DBA So Grumpy? When I Use NOLOCK AND OTHER HINTS

Rick Lowe rick@data-flowe.com DataFLowe http://dataflowe.wordpress.com/

Beginning at the End Hints should be rare Rare is not the same as _never_. Most hints exist for a reason. Best added as a response to verified issues IMO, should always be accompanied by a comment

NOLOCK Is Not Turbo This Photo by Unknown Author is licensed under CC BY-SA

What Is NOLOCK Tells SQL Server we care about a fast response more than we care about a consistent response Specifically, suppresses the shared locks for queries Ignored by insert/update/delete statements (fortunately) More like “running with scissors” mode

Why NOLOCK Is Tempting READ COMMITTED is the default Readers take shared locks Writers take exclusive locks Shared and exclusive locks not compatible Many ways to block Writers block other writers Writers block readers Readers block writers

Contributing Factors Past issues cleared up with NOLOCK Belief NOLOCK means … _NO_ lock Bad code samples / misinformation on internet Lock escalation concerns Belief dirty reads are usually OK

NOLOCK Issues Usually not necessary Possible to read uncommitted data Possible to miss records as they move Possible to double-count records as they move If persisted (e.g. ETL), corruption can spread Unpredictable results when joining

Demo 1: NOLOCK

Eliminating NOLOCK Stop using NOLOCK Consider query tuning instead To mitigate locking in general Read Committed Snapshot Isolation (RCSI) - row versioning by default. SNAPSHOT isolation – row versioning on demand

INDEX Hint Issues Force use of a specific index Why isn’t optimizer choosing index already? Breaks if index dropped or disabled

ROWLOCK Mostly harmless, more annoying than problematic Is concern lock escalation? Not typically effective If escalation is driven by memory, may delay escalation slightly Treating symptom rather than problem Is it a heap? Add clustered index

RECOMPILE Legitimate uses do exist “I think this is going to be hairy” isn’t one Parameter sensitivity is Side effects Interferes with plan cache Increases CPU use Did I mention … interferes with plan cache Query hint better than stored procedure keyword

OPTIMIZE FOR Does help with parameter sensitivity Plan will be cached Change assumptions about parameters Overuse less problematic Equivalent to saying optimizer is wrong Will parameter sniffing give bad result? Will forcing value be better? What if distribution changes?

Thank You