Indexing For Optimal Performance

Slides:



Advertisements
Similar presentations
Tuning: overview Rewrite SQL (Leccotech)Leccotech Create Index Redefine Main memory structures (SGA in Oracle) Change the Block Size Materialized Views,
Advertisements

Module 3: Creating and Tuning Indexes. Planning Indexes Creating Indexes Optimizing Indexes.
SQL Server 2005 Implementation and Maintenance Chapter 10: Maintaining and Automating SQL Server.
Module 6 Implementing Table Structures in SQL Server ®2008 R2.
A HEAP OF CLUSTERS A look into heaps vs. clustered tables Ami Levin CTO, DBSophic X.
SQL Server Storage and Index Structures Physical Data Organization Indexes B-Trees SQL Server Data Access Clustered and Non-Clustered Creating, Altering,
Denny Cherry twitter.com/mrdenny.
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
TEMPDB Capacity Planning. Indexing Advantages – Increases performance – SQL server do not have to search all the rows. – Performance, Concurrency, Required.
Page 1 SQL Server Myths XV ENCONTRO DA COMUNIDADE SQLPORT Rui Ribeiro MCITP 2011/08/16.
Table Indexing for the.NET Developer Denny Cherry twitter.com/mrdenny.
Effective Indexes For Beginners. Performance is slow Let’s add another index!
Denny Cherry twitter.com/mrdenny.
Interpreting DMV’s & practical uses Jannie Muller mullerjannie.wordpress.com.
SQL SERVER DAYS 2011 Table Indexing for the.NET Developer Denny Cherry twitter.com/mrdenny.
Analysing Indexes SQLBits 6 th October 2007 © Colin Leversuch-Roberts Kelem Consulting Limited September 2007.
CS4432: Database Systems II
October 15-18, 2013 Charlotte, NC Accelerating Database Performance Using Compression Joseph D’Antoni, Solutions Architect Anexinet.
How to kill SQL Server Performance Håkan Winther.
October 15-18, 2013 Charlotte, NC SQL Server Index Internals Tim Chapman Premier Field Engineer.
A Lap Around Columstore Martin Catherall SQL Saturday #464, Melbourne 20 th February 2016.
[Automated] TDD with SQL Server and nUnit Daniel de Sousa SQL Saturday #468, Sydney 27 th February 2016.
Are You High? Can You Recover? Robert Douglas SQL Saturday #468, Sydney 27 th February 2016.
Hitting the SQL Server “Go Faster” Button Rob Douglas #509 | Brisbane 2016.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
Chris Index Feng Shui Chris
Get the Most out of SQL Server Standard Edition
CygNet Database Service Diagnostics and Performance Tuning
Module 11: File Structure
How Good Is Your Indexing Strategy?
Indexes By Adrienne Watt.
SQL Server Query and Index Tuning
Indices.
Hitting the SQL Server “Go Faster” Button
[Automated] TDD with SQL Server using nUnit
Inside of SQL Server Indexes
SQL Server Monitoring Overview
Module 4: Creating and Tuning Indexes
26 - File Systems.
Hash-Based Indexes Chapter 11
Database Management Systems (CS 564)
Hustle and Bustle of SQL Pages
The Ins and Outs of Partitioned Tables
Marcos Freccia Stop everything! Top T-SQL tricks to a developer
The Vocabulary of Performance Tuning
The Ins and Outs of Indexes
Getting To Know Your Indexes
Hitting the SQL Server “Go Faster” Button
Table Indexing for the .NET Developer
Re-Indexing - The quest of ultimate automation
Session #, Speaker Name Indexing Chapter 8 11/19/2018.
Example of a page header
Indexes: The Basics Kathi Kellenberger.
Statistics: What are they and How do I use them
Hash-Based Indexes Chapter 10
Turbo-Charged Transaction Logs
Understanding Transaction Isolation Levels
Index Tuning Additional knowledge.
The Vocabulary of Performance Tuning
Transaction Log Internals and Performance David M Maxwell
The Ins and Outs of Indexes
Analyzing Performance Problems Using XEvents, DMVs & Query Store
Chapter 11 Instructor: Xin Zhang
The Vocabulary of Performance Tuning
Sql Saturday Philadelphia
All about Indexes Gail Shaw.
Analyzing Performance Problems Using XEvents, DMVs & Query Store
The Ins and Outs of Indexes
SQL Server Indexing for the Client Developer
XML? What’s this doing in my database? Adam Koehler
Presentation transcript:

Indexing For Optimal Performance Robert Douglas SQL Saturday #464, Melbourne 20th February 2016

Housekeeping Mobile Phones Evaluations Wifi Details please set to “stun” during sessions Evaluations complete online to be in the draw for fantastic prizes Wifi Details Network: Eduroam Login: ext-sqlsat Password: sqlsaturd4y SESSIONS EVENT http://www.sqlsaturday.com/464/ sessions/sessionevaluation.aspx http://www.sqlsaturday.com/464/ eventeval.aspx

Connect with the Community Event staff, volunteers and speakers are here to help and answer questions. Scan the QR code on the speaker badges to connect and network with them. speaker @SQLDropbear I attack SQL challenges by dropping onto them from above.

Thanks to the Sponsors Please make sure you visit our fantastic sponsors:

Robert Douglas Consultant for SQL Services Limited BA(hons),MCTS, MCITP(2005/2008), MCSA(2012) Consultant for SQL Services Limited Christchurch\Nelson SQL Server Users Group

What We Will Cover What is an Index and why should I care? Fragmentation What is it? Why does it effect my queries? How to combat it? Designing Smarter Indexes Indexing Mistakes to Avoid

Types of Indexes Heaps Clustered Index One per table The actual data Non-Clustered Index Many per table Copies ‘bits’ of the table Covering Index?

What is an Index and Why Should I Care? PAGE HEADER DATA PAGE DATA 8K DATA (Index OR Data Rows) SLOT ARRAY

What is an Index and Why Should I Care? DATA 8K Index Pages DATA 8K DATA 8K DATA 8K DATA 8K DATA 8K DATA 8K DATA 8K DATA 8K DATA 8K DATA 8K DATA 8K DATA 8K

What is an Index and Why Should I Care? A-J A - E F-J A B C D E F G H I J

What is an Index and Why Should I Care? A-J A - E F-J A B C D E F G H I J

SELECT * FROM dbo.TABLE WHERE Word=‘Go’ A-J A - E F-J A B C D E F G H I J

SELECT * FROM dbo.TABLE WHERE Word BETWEEN ‘B’ AND ‘G’ A-J A - E F-J A B C D E F G H I J

SELECT * FROM dbo.TABLE WHERE Word BETWEEN ‘B’ AND ‘G’ READAHEAD A-J A - B C-D E-F G-H I-J A B C D E F G H I J

What is Fragmentation? External Fragmentation Referred to as “Logical Fragmentation” in books online. Next logical page is not the next physical page. External Fragmentation reduces Read Ahead Performance. That reduces the efficiency of your range scans. Only refers to pages on disk(pages in memory are always logically contiguous) avg_fragmentation_in_percent in the sys.dm_db_index_physical_stats DMF

What is Fragmentation? Internal Fragmentation Sometimes referred to as physical fragmentation. Empty space on pages. Avg_page_space_used_in_percent in sys.dm_db_index_physical_stats DMF. The effects of internal fragmentation are: More disk space needed to hold the data. More IO to read the same amount of data. More space in memory used to hold the same data.

What Causes Fragmentation? Page Splits Page Splits happen when there is not enough space on a page. SQL has to write in as specific location. Inserts on pages that are already full. Updates which increase the size of a row. Snapshot isolation(makes updated records 14 bytes longer). Page must either be compacted or split. Close to, but not always 50/50.

What happens when you discover fire? F-J FIRE F G H I J

What happens when you discover fire? F-J FIRE G H I J F F2

What happens when you discover fire? A “Good” Page Split A-F FIRE A B C D E F F2

How Do I Remove Fragmentation? REBUILD and REORGANISE Indexes Rebuild Indexes This is an expensive operation It requires the size of the index as additional space It reads and writes the entire index. It takes locks on your pages. Reorganise Indexes Always online Rollback is one page. Doesn’t update stats. Maintenance Plans. Smart scripts

How Do I Remove Fragmentation? Avoid it in the first place Re-Architect your tables Avoid GUIDS or other random keys on highly transactional tables. Be aware of when updates are likely to occur on variable length columns. Keep clustered index narrow if possible. Avoid very wide rows Fill Factor Select * from sys.configurations where name like 'fill factor%‘ select * from sys.indexes order by fill_factor DESC Avoid database shrinks.

How Shrinking Works http://dbareactions.com/

Designing Smarter Indexes Know your workload Query Hints Missing Indexes DMV Sys.dm_db_missing_index_details SYS.dm_db_missing_index_Columns SYS.dm_db_missing_index_groups SYS.dm_db_missing_index_group_stats Prune unwanted Indexes http://thomaslarock.com/2010/08/how-to-find-duplicate-indexes/ Unused Indexes SP_BlitzIndex – BrentOzar.com

Indexing Mistakes to Avoid #1: Blindly Following “Suggested Indexes” Recommendations Query Plan Hints Missing Indexes DMV Sys.dm_db_missing_index_details SYS.dm_db_missing_index_Columns SYS.dm_db_missing_index_groups SYS.dm_db_missing_index_group_stats Database Tuning Adviser 3rd Party Tools The Internet

Indexing Mistakes to Avoid #2: Fill Factor Suicide Fill factor will remove or slow External Fragmentation But it increases internal fragmentation.

Indexing Mistakes to Avoid #3: The Wrong Maintenance If you have regular maintenance in place – do you know what it does? Rebuilding Indexes that don’t need it. Reorganising Indexes without updating stats

Bonus Indexing Mistake: Readable Secondaries If you have a readable secondary (Mirroring or AOAG) it turns on snapshot isolation on the secondary replica. That doesn’t turn on snapshot isolation on the primary, but it will add the 14 byte versioning tag on them. If your pages are built to 100%, this will cause every page you query on the secondary split on the primary.

Questions? Please make sure you visit our fantastic sponsors:

How did we do? Please complete an online Evaluation to be included the draw for a fantastic prize! There is a prize for each session timeslot and for the overall event survey – so the more feedback you provide the more chances you have. Post-Event Survey http://www.sqlsaturday.com/464/ eventeval.aspx Session Surveys http://www.sqlsaturday.com/464/ sessions/sessionevaluation.aspx