All about Indexes Gail Shaw.

Slides:



Advertisements
Similar presentations
Understanding SQL Server Query Execution Plans
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.
Module 14: Analyzing Queries. Overview Queries That Use the AND Operator the OR Operator Join Operations.
Indexes Rose-Hulman Institute of Technology Curt Clifton.
Relational Database Performance CSCI 6442 Copyright 2013, David C. Roberts, all rights reserved.
Denny Cherry Manager of Information Systems MVP, MCSA, MCDBA, MCTS, MCITP.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
Denny Cherry twitter.com/mrdenny.
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
T-SQL: Simple Changes That Go a Long Way DAVE ingeniousSQL.com linkedin.com/in/ingenioussql.
Around the world (of query plan operators) in 50 minutes David Morrison BI Consultant.
Indexes and Views Unit 7.
Session 1 Module 1: Introduction to Data Integrity
Query Processing – Implementing Set Operations and Joins Chap. 19.
Thinking in Sets and SQL Query Logical Processing.
SQL SERVER DAYS 2011 Indexing Internals Denny Cherry twitter.com/mrdenny.
Scott Fallen Sales Engineer, SQL Sentry Blog: scottfallen.blogspot.com.
Execution Plans Detail From Zero to Hero İsmail Adar.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
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.
SQL Server Statistics and its relationship with Query Optimizer
Microsoft SQL Server 2005 Advanced SQL Programming and Optimization
CPS216: Data-intensive Computing Systems
Indexes By Adrienne Watt.
Record Storage, File Organization, and Indexes
CS 540 Database Management Systems
External Sorting Chapter 13
T-SQL: Simple Changes That Go a Long Way
PostgreSQL Conference East 2009 The Art of Indexes Josh Williams
Database Performance Tuning and Query Optimization
Evaluation of Relational Operations
Introduction to Execution Plans
The Ins and Outs of Indexes
The Ins and Outs of Indexes
The Key to the Database Engine
Cardinality Estimator 2014/2016
File Processing : Query Processing
Lecture 12 Lecture 12: Indexing.
Physical Database Design
CS222: Principles of Data Management Notes #09 Indexing Performance
JULIE McLAIN-HARPER LINKEDIN: JM HARPER
Execution Plans Demystified
Indexing Fundamentals
Statistics: What are they and How do I use them
Steve Hood SimpleSQLServer.com
Chapter 4 Indexes.
CH 4 Indexes.
External Sorting Chapter 13
Selected Topics: External Sorting, Join Algorithms, …
SQL Server Query Plans Journeyman and Beyond
CS222P: Principles of Data Management Notes #09 Indexing Performance
Indexing for Beginners
Introduction to reading execution plans
Advance Database Systems
Denny Cherry twitter.com/mrdenny
Introduction to Execution Plans
Chapter 11 Database Performance Tuning and Query Optimization
Execution plans Eugene
Evaluation of Relational Operations: Other Techniques
Diving into Query Execution Plans
Introduction to Execution Plans
Managing and monitoring SQL Server on Linux from the command line
Introduction to Execution Plans
External Sorting Chapter 13
CS222/CS122C: Principles of Data Management UCI, Fall 2018 Notes #08 Comparisons of Indexes and Indexing Performance Instructor: Chen Li.
Welcome!.
The Ins and Outs of Indexes
Presentation transcript:

All about Indexes Gail Shaw

Please Thank & 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. Global Alliance Partner: Venue & Internet Sponsor: Silver Sponsor: Operations Support: Endless Support from: OGMA Consulting Corp. Bronze Sponsor:

Agenda Why index? Index Architecture Non-clustered Indexes Other index types

Overview

Why index? To reduce the number of rows in consideration for a query as early as possible To support operations that require a sort order for rows To enforce uniqueness upon a column, set of columns or subset of values in a column

Index Architecture

Index architecture B-tree (balanced tree) Double-linked list at all levels

Index architecture

Index pages Two types of pages found in indexes Data pages Index pages Data pages found at the leaf level of a clustered index Index pages found at the non-leaf level of a clustered index and all levels of a nonclustered index

Index operations Seek Navigation down the b-tree to find a row or the start/end of a range of rows Scan Read of (potentially) the entire index leaf-level Lookup Single-row seek against the clustered index/heap

Definitions Density – Measure of how unique a column is Selectivity – What % of a table a predicate will return Cardinality – How many rows a query operator will affect Predicate – An expression that evaluates to True or False. Seek predicate – A predicate which SQL can evaluate by traversing an index’s b-tree

Nonclustered Indexes

Architecture Nonclustered indexes are secondary structures They are separate from the table but always in-sync with it One row in the index for each row in the table Each index row has a pointer to the actual data row If the table has a clustered index, this is the clustered index key If the table is a heap, this is the RID (file ID : page number : slot index)

Architecture A, 2 K, 7 A, 2 C, 8 E, 1 E, 8 I, 6 K, 7 M, 6 N, 9 S, 1 F, 7 F, 9 H, 1 I, 6 K, 7 M,6 N,9 S,1 S, 8

Guidelines Indexes should be selective or covering (or both) Wider indexes tend to be more useful Consider covering indexes for frequently run queries Consider indexes to support order by and group by Use INCLUDE for columns that are selected, but not involved in filters/joins

Indexing for equality When all where clause predicates are an equality Order of columns in the index don’t matter for this query SQL does not seek on one, then the second, etc SQL will do a multi-column seek to the beginning or end of the range of rows Order of index columns does matter when trying to support multiple queries with one index Seek only possible on a left-based subset of the index key Don’t put most selective column first by default

Indexing for inequality Columns used for equality matches before those for inequality When dealing with two or more inequality predicates, column order implied by which predicate returns fewer rows Selectivity much less important for inequality predicates, cardinality is more relevant

Indexing for sorts/group by Indexes are logically ordered by the index key columns As such, an index can provide the order needed for an ORDER BY or a stream aggregate Usually should be considered after considering indexes to support the WHERE clause Not always possible to achieve

Indexing for joins Three join types in SQL Server Nested loop Merge join Hash join

Indexing for joins Nested loop can benefit from an index on the inner table Merge requires rows sorted in the join order, so can benefit from indexes on both tables Hash doesn’t require any indexes at all Secondary consideration after indexing for the WHERE clause

Filtered indexes Index on a subset of the table Filter condition should be simple. It cannot reference a computed column, spatial data types or Hierarchy. Very useful for enforcing uniqueness on a subset of the table To be useful for a query, the predicate must match exactly Parameterised queries may not use the filtered index

Include columns Only included at the leaf level of the index Does not count towards the 16 column/900 byte limit for index keys Only TEXT, NTEXT, IMAGE cannot be INCLUDE columns

Thank you