Weird Stuff I Saw While … Working With Heaps

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

Oracle Data Block Oracle Concepts Manual. Oracle Rows Oracle Concepts Manual.
1 CS 430 Database Theory Winter 2005 Lecture 16: Inside a DBMS.
Tree-Structured Indexes Jianlin Feng School of Software SUN YAT-SEN UNIVERSITY courtesy of Joe Hellerstein for some slides.
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.
# CCNZ What is going on here???
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 ●
Priority Queues and Heaps Tom Przybylinski. Maps ● We have (key,value) pairs, called entries ● We want to store and find/remove arbitrary entries (random.
Storage and File Organization
CS222: Principles of Data Management Lecture #4 Catalogs, Buffer Manager, File Organizations Instructor: Chen Li.
Chris Index Feng Shui Chris
Understanding Data Storage
Concurrency Control Managing Hierarchies of Database Elements (18.6)
Indexing Structures for Files and Physical Database Design
CHP - 9 File Structures.
CS522 Advanced database Systems
Record Storage, File Organization, and Indexes
Indexing and hashing.
Practical Office 2007 Chapter 10
CS522 Advanced database Systems
Tree-Structured Indexes
Informatica PowerCenter Performance Tuning Tips
T-SQL: Simple Changes That Go a Long Way
Session 4 PHP & MySQL.
CSE-291 (Cloud Computing) Fall 2016
Weird Stuff I Saw While ... Supporting a Java Team
SQL Server May Let You Do It, But it Doesn’t Mean You Should
Database Applications (15-415) DBMS Internals- Part III Lecture 15, March 11, 2018 Mohammad Hammoud.
When I Use NOLOCK AND OTHER HINTS
Lecturer: Mukhtar Mohamed Ali “Hakaale”
CS222P: Principles of Data Management Notes #6 Index Overview and ISAM Tree Index Instructor: Chen Li.
Azure SQL Data Warehouse Performance Tuning
Database Implementation Issues
2008/12/03: Lecture 20 CMSC 104, Section 0101 John Y. Park
Weird Stuff I Saw While … Working With Heaps
Introduction to Database Systems File Organization and Indexing
More about Databases.
Indexes: The Basics Kathi Kellenberger.
Tree-Structured Indexes
Index Use Cases.
Weird Stuff I Saw While ... Supporting a Java Team
Let’s Get Started! Rick Lowe
Microsoft SQL Server 2014 for Oracle DBAs Module 7
When I Use NOLOCK AND OTHER HINTS
CS222/CS122C: Principles of Data Management Lecture #4 Catalogs, File Organizations Instructor: Chen Li.
In Memory OLTP Not Just for OLTP.
The PROCESS of Queries John Deardurff Website: ThatAwesomeTrainer.com
Tree-Structured Indexes
Unit I-2.
Chapter 13: Data Storage Structures
DATABASE IMPLEMENTATION ISSUES
Indexing 1.
CS222/CS122C: Principles of Data Management Notes #6 Index Overview and ISAM Tree Index Instructor: Chen Li.
Clustered Columnstore Indexes (SQL Server 2014)
When I Use NOLOCK AND OTHER HINTS
CS222p: Principles of Data Management Lecture #4 Catalogs, File Organizations Instructor: Chen Li.
Diving into Query Execution Plans
In Memory OLTP Not Just for OLTP.
Weird Stuff I Saw While … Working With Heaps
Database Implementation Issues
Tree-Structured Indexes
Indexes and Performance
Chapter 11: Indexing and Hashing
CS222/CS122C: Principles of Data Management UCI, Fall 2018 Notes #05 Index Overview and ISAM Tree Index Instructor: Chen Li.
Database Implementation Issues
Advanced Topics: Indexes & Transactions
All about Indexes Gail Shaw.
Presentation transcript:

Weird Stuff I Saw While … Working With Heaps Really, How Bad Is It to Use Heaps? 7/15/2017

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

Demo Break 1 Creation script System health session Update demo 1 7/15/2017 Demo Break 1 Creation script System health session Update demo 1

What’s a Deadlock? has has needs needs

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

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!

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

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;

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;

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

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(…);

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(…);

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

7/15/2017 Demo Break 2 SSIS Demo Speed comparison

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)

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(…)

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?

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

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

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.

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

Thank You