Let’s Get Started! Rick Lowe

Slides:



Advertisements
Similar presentations
Enqueue Waits : Locks. #.2 Copyright 2006 Kyle Hailey Wait Tree - Locks Waits Disk I/O Library Cache Enqueue Undo TX 6 Row Lock TX 4 ITL Lock HW Lock.
Advertisements

Big Data Working with Terabytes in SQL Server Andrew Novick
DB Audit Expert v1.1 for Oracle Copyright © SoftTree Technologies, Inc. This presentation is for DB Audit Expert for Oracle version 1.1 which.
Southern California Job Growth Trends Southern California Total San Diego County Orange County Riverside/San Bernardino Counties (The Inland Empire) Los.
Session 1 Module 1: Introduction to Data Integrity
1 Indexes ► Sort data logically to improve the speed of searching and sorting operations. ► Provide rapid retrieval of specified rows from the table without.
Deadlocks 3.0. Final Edition. Everything that developer needs to know Denis Reznik Microsoft SQL Server MVP Director of R&D at Intapp Kyiv.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
Keys and adding, deleting and modifying records in an array ● Record Keys ● Reading and Adding Records ● Partition or Sentinels Marking Space in Use ●
Let’s Get Started! Steve Rezhener SQL Malibu and SQL Saturday in LA
Chris Index Feng Shui Chris
Indexing Structures for Files and Physical Database Design
CHP - 9 File Structures.
David Taylor, Pimp my spreadsheet, FAST LANE BI
Introduction to SQL 2016 Temporal Tables
CS522 Advanced database Systems
Informatica PowerCenter Performance Tuning Tips
SSIS Project Deployment: The T-SQL Way
SQL Server May Let You Do It, But it Doesn’t Mean You Should
Database Code Management with VS 2017 and RedGate
ISC440: Web Programming 2 Server-side Scripting PHP 3
When I Use NOLOCK AND OTHER HINTS
Lecturer: Mukhtar Mohamed Ali “Hakaale”
Save Time & Resources: Job Performance Tuning Strategies
Let’s Get Started! Rick Lowe Why Should I Care About … The Plan Cache
It’s About Time : Temporal Table Support in SQL Server 2016/2017
2008/12/03: Lecture 20 CMSC 104, Section 0101 John Y. Park
Transforming Your Brain with SQL 2017 on Linux
Weird Stuff I Saw While … Working With Heaps
Welcome to SQL Saturday Denmark
Stop Wasting Time & Resources: Performance Tune Your Jobs
SSIS Project Deployment: The T-SQL Way
Indexes: The Basics Kathi Kellenberger.
Statistics: What are they and How do I use them
Transactions, Locking and Query Optimisation
Turbo-Charged Transaction Logs
The Mac DBA, using Docker and SQL Operations Studio
Microsoft SQL Server 2014 for Oracle DBAs Module 7
Microsoft Azure for SQL Server Professionals
Thanks to our platinum sponsors :
The PROCESS of Queries John Deardurff Website: ThatAwesomeTrainer.com
Save Time & Resources: Job Performance Tuning Strategies
Unit I-2.
Indexing For Optimal Performance
Weird Stuff I Saw While … Working With Heaps
CS122 Using Relational Databases and SQL
Clustered Columnstore Indexes (SQL Server 2014)
When I Use NOLOCK AND OTHER HINTS
CS1222 Using Relational Databases and SQL
Welcome to 2018 SQL Saturday in Sacramento Steve Rezhener
Diving into Query Execution Plans
In Memory OLTP Not Just for OLTP.
Weird Stuff I Saw While … Working With Heaps
Why Should I Care About … Partitioned Views?
Chapter 11: Indexing and Hashing
The Fast and Easy Methods to Automate your SQL Server builds
Patrick Partin What just happened?
Welcome to 2019 SQL Saturday in Los Angeles (#891)
SSRS – Thinking Outside the Report
Patrick Partin What just happened? Creating your own real-time dashboard with Grafana, Influx, and Telegraf Congratulations on successfully downloading.
Simplify your daily tasks with DBATools!
CS122 Using Relational Databases and SQL
Power BI Security Fundamentals
Brodie Brickey SSIS Basics.
Do-It-Yourself Performance Monitoring
Simplify your daily tasks with DBATools!
All about Indexes Gail Shaw.
XML? What’s this doing in my database? Adam Koehler
An Introduction to Partitioning
Presentation transcript:

Let’s Get Started! Rick Lowe Weird Stuff I Saw While …Working With Heaps Data Flowe Solutions LLC

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

What Is a Heap Table without a clustered Index Doesn’t automatically have a B tree Disorganized data Table that only supports scans 3/25/2017

Demo Break 1 Creation script System health session Update demo 1 3/25/2017

What’s a Deadlock? has has needs needs 3/25/2017

Modifying a Heap 1 2 3 4 5 6 UPDATE dbo.myHeap SET n = 1 WHERE ID = 4; Is ID 4 here? Is ID 4 here? 1 2 3 4 5 6 3/25/2017

Modifying a Heap (cont’d) UPDATE dbo.myHeap SET n = 1 WHERE ID = 4; Found it 1 2 3 4 5 6 Time to update! 3/25/2017

Modifying a Clustered Index (comparison) UPDATE dbo.myTable SET n = 1 WHERE ID = 4; 1 2 3 4 5 6 Found it Time to update! 1 2 3 4 5 6 3/25/2017

Modifying a Heap – Two Connections UPDATE dbo.myHeap SET n = 1 WHERE ID = 4; It’s Here! Is ID 4 here? Nope. Is ID 4 here? Nope. 1 2 3 4 5 6 UPDATE dbo.myHeap SET n = 1 WHERE ID = 3; 3/25/2017

Modifying With a Heap – Two Connections (Contd) UPDATE dbo.myHeap SET n = 1 WHERE ID = 4; Is 4 here? 1 2 3 4 5 6 Is 3 here? UPDATE dbo.myHeap SET n = 1 WHERE ID = 3; 3/25/2017

Issues With Updating Heaps No seeks (in the absence of NC index) Also no guarantee of uniqueness (scan continues even after record is found) Many update locks, one exclusive lock If multiple connections are doing similar update, connection A may hold an exclusive lock on data that connection B wants to scan and vice versa 3/25/2017

Inserting Into Heaps: Best Case INSERT INTO dbo.myHeap(…) VALUES(…); I’m locking slot 0. 1 2 3 4 5 I’m locking slot 1. INSERT INTO dbo.myHeap(…) VALUES(…); 3/25/2017

Inserting Into Heaps: Reused Space INSERT INTO dbo.myHeap(…) VALUES(…); I’m locking slot 0. 1 2 3 4 5 Oh, there’s space here. INSERT INTO dbo.myHeap(…) VALUES(…); 3/25/2017

Inserting Into Clustered Index (Comparison) INSERT INTO dbo.myTable(…) VALUES(…); 1 2 3 4 5 Found it Time to update! 1 2 3 4 5 3/25/2017

Demo Break 2 SSIS Demo Speed comparison 3/25/2017

One Way to Make Insert Fail SELECT @n = COUNT(*) FROM dbo.myHeap WHERE ClientID = @cust WITH(SERIALIZABLE) Shared lock I’m looking at this. Don’t change. dbo.BigHeap SELECT @n = COUNT(*) FROM dbo.myHeap WHERE ClientID = @cust WITH(SERIALIZABLE) 3/25/2017

One Way to Make Insert Fail (cont’d) INSERT INTO dbo.MyHeap(ID, IsTrial, BigBlobbyData) VALUES(…) Shared lock Convert to IX lock Need to lock a row dbo.BigHeap Convert to IX lock INSERT INTO dbo.MyHeap(ID, IsTrial, BigBlobbyData) VALUES(…) 3/25/2017

Issues With Inserting Into Heaps No order, so new records could go anywhere Reusing space means looking for space Mixing SELECTS and INSERTS are more problematic due to table scans Many believe inserts into heaps are faster. That’s not always true. If table eventually needs a clustered index, how long does it take to convert from heap? 3/25/2017

Demo Break 3 Update demo 2 – heap with NC index 3/25/2017

Indexing Cheat Sheet Heaps are OK for inserting lots of transitory, unsorted data through a single connection. Heaps aren’t ideal for select, update, delete Heaps aren’t ideal for multiple connections Clustered index inserts may outperform heap inserts when data is ordered Usually not difficult to sort data before loading 3/25/2017

Non-Clustered Indexes Adding NC indexes or unique constraints to heaps rarely makes sense Adding NC index to heap often increases frequency of deadlocks (more things to lock) NC indexes also tend to make deadlocks more likely when inserting to clustered index Best case for inserts is often a table with clustered index and no NC indexes. 3/25/2017

Ghost Cleanup http://www.mikefal.net/2012/10/17/a-heap-of-trouble/ Large, partitioned heap Volatile Key Ghost cleanup stopped working 3/25/2017

Please Support Our Sponsors SQL Saturday is made possible with the generous support of these sponsors. You can support them by opting-in and visiting them in the sponsor area. The 1st EVER #SQLSatLA on June 10th 2017 Microsoft Technology Center

Questions? Email me at rick@data-flowe.com Or tweet me DataFLowe Thank you! 24 | The 1st EVER #SQLSatLA on June 10th 2017 Microsoft Technology Center

SoCal Local User Groups Orange County User Group L.A. User Group 3rd Thursday of each odd month sql.la SQL Malibu User Group 3rd Wednesday of each month sqlmalibu.pass.org Los Angeles - Korean Every Other Tuesday sqlangeles.pass.org San Diego User Group 1st & 3rd Thursday of each month meetup.com/sdsqlug meetup.com/sdsqlbig Orange County User Group 2rd Thursday of each month bigpass.pass.org Sacramento User Group 1st Wednesday of each month http://sac.pass.org/ The 1st EVER #SQLSatLA on June 10th 2017 Microsoft Technology Center

California SQL Saturdays SQL Saturday in Sacramento 2017 (#650) When: Saturday, July 15, 2017 SQL Saturday in San Diego 2017 (#661) When: Saturday, September 23, 2017 The 1st EVER #SQLSatLA on June 10th 2017 Microsoft Technology Center