October 15-18, 2013 Charlotte, NC SQL Server Index Internals Tim Chapman Premier Field Engineer.

Slides:



Advertisements
Similar presentations
Yukon – What is New Rajesh Gala. Yukon – What is new.NET Framework Programming Data Types Exception Handling Batches Databases Database Engine Administration.
Advertisements

EXECUTION PLANS By Nimesh Shah, Amit Bhawnani. Outline  What is execution plan  How are execution plans created  How to get an execution plan  Graphical.
SQL Server 2005 features for VLDBs. SQL Server 2005 features for VLDBs aka (it’s fixed in the next release)
Working with SQL Server Database Objects
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.
1 Lecture 20: Indexes Friday, February 25, Outline Representing data elements (12) Index structures (13.1, 13.2) B-trees (13.3)
Indexes Rose-Hulman Institute of Technology Curt Clifton.
Module 7: Creating and Maintaining Indexes. Overview Creating Indexes Creating Index Options Maintaining Indexes Introduction to Statistics Querying the.
Architecting a Large-Scale Data Warehouse with SQL Server 2005 Mark Morton Senior Technical Consultant IT Training Solutions DAT313.
Using Excel, Excel Service and PerformancePoint
Module 8 Improving Performance through Nonclustered Indexes.
Sofia, Bulgaria | 9-10 October SQL Server 2005 High Availability for developers Vladimir Tchalkov Crossroad Ltd. Vladimir Tchalkov Crossroad Ltd.
Architecture Rajesh. Components of Database Engine.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
Top Free Tools for Tuning SQL Statements Kevin Kline & Aaron Bertrand SQL Sentry, Inc.
Module 5 Planning for SQL Server® 2008 R2 Indexing.
SQL Server Indexes Indexes. Overview Indexes are used to help speed search results in a database. A careful use of indexes can greatly improve search.
Module 16: Performing Ongoing Database Maintenance
Denny Cherry twitter.com/mrdenny.
Indexes / Session 2/ 1 of 36 Session 2 Module 3: Types of Indexes Module 4: Maintaining Indexes.
How to Use Parameters Like a Pro …and Boost Performance Guy Glantser, CEO, Madeira.
SQL/Lesson 7/Slide 1 of 32 Implementing Indexes Objectives In this lesson, you will learn to: * Create a clustered index * Create a nonclustered index.
Maciej Pilecki | Project Botticelli Ltd.. SELECT Bio FROM Speakers WHERE FullName=‘Maciej Pilecki’;  Microsoft Certified Trainer since 2001  SQL Server.
SQLintersection Putting the "Squeeze" on Large Tables Improve Performance and Save Space with Data Compression Justin Randall Tuesday,
Chapter 4 Indexes. Index Architecture  By default data is inserted on a first-come, first-serve basis  Indexes bring order to this chaos  Once you.
Session 1 Module 1: Introduction to Data Integrity
Creating Indexes on Tables An index provides quick access to data in a table, based on the values in specified columns. A table can have more than one.
SQL SERVER DAYS 2011 Indexing Internals Denny Cherry twitter.com/mrdenny.
October 15-18, 2013 Charlotte, NC Being the DBA of the Future A World of On-Premises and Cloud Dandy Weyn, Snr. Technical Marketing Product Manager Microsoft.
October 15-18, 2013 Charlotte, NC Accelerating Database Performance Using Compression Joseph D’Antoni, Solutions Architect Anexinet.
Query Performance Tuning in SQL Server 2014 #devconnections.
How to kill SQL Server Performance Håkan Winther.
SQL Server Statistics DEMO SQL Server Statistics SREENI JULAKANTI,MCTS.MCITP,MCP. SQL SERVER Database Administration.
Execution Plans for Mere Mortals A beginners look at execution plans. Mike Lawell, Teammate, Linchpin People.
SQL Server Deep Dive Denis Reznik Data Architect at Intapp.
Scott Fallen Sales Engineer, SQL Sentry Blog: scottfallen.blogspot.com.
Module 6: Creating and Maintaining Indexes. Overview Creating Indexes Understanding Index Creation Options Maintaining Indexes Introducing Statistics.
SQL Server Statistics DEMO SQL Server Statistics SREENI JULAKANTI,MCTS.MCITP SQL SERVER Database Administration.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
Views / Session 3/ 1 of 40 Session 3 Module 5: Implementing Views Module 6: Managing Views.
Doing fast! Optimizing Query performance with ColumnStore Indexes in SQL Server 2012 Margarita Naumova | SQL Master Academy.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
Date Dimension: Past & Future in One Script Steve Wake, BI Developer, Chipotle.
SQL Server Statistics and its relationship with Query Optimizer
Chris Index Feng Shui Chris
R; One Ring to Rule Them All
How Good Is Your Indexing Strategy?
Solving the Hard Problems
Finding more space for your tight environment
Module 4: Creating and Tuning Indexes
Designing Database Solutions for SQL Server
Introduction to SQL Server Management for the Non-DBA
Hustle and Bustle of SQL Pages
Database Administration for the Non-DBA
Blazing-Fast Performance:
Introduction to partitioning
TechEd /24/2018 8:21 PM © 2013 Microsoft Corporation. All rights reserved. Microsoft, Windows, and other product names are or may be registered.
JULIE McLAIN-HARPER LINKEDIN: JM HARPER
Statistics: What are they and How do I use them
Database systems Lecture 6 – Indexes
SQL Server Security For Everyone
Indexing For Optimal Performance
In-Memory OLTP for Database Developers
Denny Cherry twitter.com/mrdenny
Four Rules For Columnstore Query Performance
Indexing 4/11/2019.
Using Columnstore indexes in Azure DevOps Services. Lessons learned
Using Columnstore indexes in Azure DevOps Services. Lessons learned
All about Indexes Gail Shaw.
Presentation transcript:

October 15-18, 2013 Charlotte, NC SQL Server Index Internals Tim Chapman Premier Field Engineer

October 15-18, 2013 | Charlotte, NC Please silence cell phones

Explore Everything PASS Has to Offer Free SQL Server and BI Web Events Free 1-day Training Events Regional Event Local User Groups Around the World Free Online Technical Training This is Community 3 Business Analytics Training Session Recordings PASS Newsletter

Session Evaluations ways to access Go to passsummit/evals Download the GuideBook App and search: PASS Summit 2013 Follow the QR code link displayed on session signage throughout the conference venue and in the program guide Submit by 5pm Friday Oct. 18 to WIN prizes Your feedback is important and valuable. 4

About Me Tim Chapman Dedicated Premier Field Engineer at Microsoft Contributing author SQL Server 2012 Bible SQL Server MVP Deep Dives

Session Goals Index structure familiarity I won’t break out a debugger  But, I will show you some neat tools for viewing indexes Have some fun talking about indexes!

Heaps Tables without a clustered index Unordered masses of data Data rows fit where they can – PFS pages used Great for quickly importing large sets of data Not great for most production environments Use ALTER TABLE…REBUILD to “rebuild”

Index Structures Clustered Indexes Non-Clustered Indexes

Clustered Indexes Implemented as a B-Tree data structure Logical order must always be maintained The leaf level of the index contains all table columns Why there is only one per table – the index IS the table We always implement these as unique

Clustered Index Structure

Non-clustered Indexes Also a B-Tree structure data structure Is NOT part of the table it is defined on It MUST point to the base table somehow Only a subset of the table columns A skinny table for fast searching and sorting

Non-clustered Index Structure

Included Columns Added columns of data in the leaf level of an NC index Used for covering queries Not restricted to the NC index 900 byte size restriction You can use (n)varchar(max), but not (n)text or image data types

Included Columns

Statistics A sampling of the data in a given table/index column The optimizer relies on these for decision making Out of date or skewed statistics can lead to sub-optimal execution plans

Showing Statistics…

Database Statistics Options (1) AUTO_CREATE_STATISTICS AUTO_UPDATE_STATISTICS AUTO_UPDATE_STATISTICS_ASYNC

Database Statistics Options – Best Practices Use the defaults unless you NEED to do otherwise Often large DW workloads are the exception Note: Trace Flag 2371 can help with RT issues.

Index Maintenance Reviewing fragmentation Affects of fragmentation Rebuild vs Reorganization

Page Splits A record must always be placed on a specific page We must maintain the index logical order If the record doesn’t fit, we must do some rearranging This is resource intensive - causes logical fragmentation

Logical Fragmentation Index/Data pages not physically and logically aligned Can hurt scan performance, but not seek operations

Page Density How full a page is upon a (re)build/reorganization More full pages can cause page splits Less full pages can waste Buffer Pool space

When does fragmentation matter? Negligible for singleton lookup seek operations Matters most for scanning purposes Note: If your index is highly fragmented, there is a good chance your statistics are skewed or out of date.

Rebuilding an index (1) Very few uses for DROP INDEX…CREATE INDEX All NC indexes rebuilt twice if you do this with the clustered index You must know the exact index structure for recreation ALTER INDEX…REBUILD NC indexes not automatically rebuilt if done on a clustered index ALTER TABLE…REBUILD Use for Heap tables – will always rebuild all NC indexes too

Rebuilding an Index (2) Offline rebuilds locks the index during the operation NOT the entire table – though that can certainly be the case ALTER INDEX ALL Rebuilds all indexes on the table in index_id order DROP_EXISTING Part of the CREATE INDEX syntax Great for changing the index definition

Index Reorganization Exclusively locks, compacts and reorders 8 pages at a time Removes leaf level fragmentation Tries to establish the original fill factor Always: single threaded, Online

Rebuild vs. Reorganize Strategy (1) When to do what? Common wisdom is: If <= 30% logical fragmentation THEN Reorganize If > 30% logical fragmentation THEN Rebuild …your mileage will vary. Choose what works for you.

Rebuild vs. Reorganize Strategy (2) Reorganize… Is always an online operation Can be stopped and you won’t lose the work accomplished Generates a LOT more t-log records than Rebuild Typically will not remove as much fragmentation as Rebuild Never updates Statistics

Rebuild vs. Reorganize Strategy (3) Rebuild… Is an atomic operation – all happens or none happens Will update statistics with FULLSCAN One caveat to this in 2012 Will involve some blocking – even Online operations Can be minimally logged

SQL Server 2012 Index Changes Rebuild indexes with (B)LOB columns online Online rebuilds of partitioned tables do not always result in a 100% sample rate

SQL 2014 Index Changes Online operation lock priority Hash and Bw-tree Indexes in Hekaton Create an index in table definition

Questions?

Resources 37