When to use indexing pro Features

Slides:



Advertisements
Similar presentations
Exadata Distinctives Brown Bag New features for tuning Oracle database applications.
Advertisements

Project Management Database and SQL Server Katmai New Features Qingsong Yao
A HEAP OF CLUSTERS A look into heaps vs. clustered tables Ami Levin CTO, DBSophic X.
André Kamman Friday November 20 SQLBITS IV. About Me  André Kamman  > 20 years in IT  Main focus on complex SQL Server environments (or a whole.
Denny Cherry twitter.com/mrdenny.
Module 8 Improving Performance through Nonclustered Indexes.
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
Architecture Rajesh. Components of Database Engine.
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.
Table Indexing for the.NET Developer Denny Cherry twitter.com/mrdenny.
Denny Cherry twitter.com/mrdenny.
Denny Cherry twitter.com/mrdenny.
SQLintersection Putting the "Squeeze" on Large Tables Improve Performance and Save Space with Data Compression Justin Randall Tuesday,
SQL SERVER DAYS 2011 Table Indexing for the.NET Developer Denny Cherry twitter.com/mrdenny.
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.
INTRODUCING SQL SERVER 2012 COLUMNSTORE INDEXES Exploring and Managing SQL Server 2012 Database Engine Improvements.
SQL SERVER DAYS 2011 Indexing Internals Denny Cherry twitter.com/mrdenny.
October 15-18, 2013 Charlotte, NC Accelerating Database Performance Using Compression Joseph D’Antoni, Solutions Architect Anexinet.
APRIL 13 th Introduction About me Duško Mirković 7 years of experience.
Oracle Announced New In- Memory Database G1 Emre Eftelioglu, Fen Liu [09/27/13] 1 [1]
Doing fast! Optimizing Query performance with ColumnStore Indexes in SQL Server 2012 Margarita Naumova | SQL Master Academy.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
Chris Index Feng Shui Chris
Demystifying Data Compression
© 2008 by David T. Olson Baptist, Lutheran, Methodist, Episcopal, Church of Christ, Presbyterian © 2008 by David T. Olson.
Essential Health Benefits Benchmark Plan Selection, as of October 2012
Learning indexing concepts with an analog phone book
Record Storage, File Organization, and Indexes
House Price
CS522 Advanced database Systems
Finding more space for your tight environment
Inside of SQL Server Indexes
House price index for AK
Introduction to SQL Server Management for the Non-DBA
Four Rules For Columnstore Query Performance
Database Administration for the Non-DBA
The Ins and Outs of Indexes
DATABASE MANAGEMENT SYSTEM
Table Indexing for the .NET Developer
Non-Citizen Population, by State, 2011
Steve Hood SimpleSQLServer.com
The Ins and Outs of Indexes
Mobility Update and Discussion as of March 25, 2008
The Five Ws of Columnstore Indexes
Current Status of the Medicaid Expansion Decision, as of May 30, 2013
IAH CONVERSION: ELIGIBLE BENEFICIARIES BY STATE
Current Status of State Medicaid Expansion Decisions
HHGM CASE WEIGHTS Early/Late Mix (Weighted Average)
Adding Lightness Better Performance through Compression
The Physical Design Stage of SDLC (figures 2.4, 2.5 revisited)
Indexing For Optimal Performance
PRACTICA & ONLINE ED AUTHORIZATION STATUS
Denny Cherry twitter.com/mrdenny
CSE 544: Lecture 11 Storing Data, Indexes
Four Rules For Columnstore Query Performance
Sampling Distribution of a Sample Mean
Clustered Columnstore Indexes (SQL Server 2014)
S Co-Sponsors by State – May 23, 2014
Indexing 4/11/2019.
The Ins and Outs of Indexes
United States of America.
Average annual growth rate
Sampling Distribution of a Sample Mean
Current Status of State Medicaid Expansion Decisions
CSE 326: Data Structures Lecture #14
All about Indexes Gail Shaw.
The Ins and Outs of Indexes
XML? What’s this doing in my database? Adam Koehler
Sunil Agarwal | Principal Program Manager
Presentation transcript:

When to use indexing pro Features Andy Mallon

Andy Mallon I sell furniture at the mall Database Architect at Wayfair.com Working with SQL Server since 2003 Background in Tech Support, Database Administration, and Database Architecture Lazy Impatient

Some of the things I love most in life– My husband, my pups, Queery the Diversity Dino. @QueeryTSQLRex

http://AMtwo.lgbt

Contact Andy Andy@AMtwo.co @AMtwo andy@am2.co am2.co

Session Feedback Tell me what you don’t like Tell me what can be better Tell me what you like

Yea…….You apparently didn’t put one of the new coversheets on your TPS reports. I'm also gonna need you to go ahead and silence your phones and devices

Agenda Index flavors – What are they? When to use fancy indexes? How many indexes are enough? This is a high-level talk…We only have an hour. Go see Jeff Moden later today to dive deeper

But first… All data is stored on pages Pages are combined into different structures B+ Trees Clustered indexes Nonclustered indexes Indexed views Heaps

Table Structures: B+ Trees Root Page AK ID Intermediate Level(s) AK CA FL ID KY ME Leaf Pages These are the pages we’re talking about when we talk compression. Only the LEAF PAGES get compressed in a B Tree Index Everything is ordered. It’s easy to find by traversing the tree. You can find any row in just 3 reads. EXAMPLE: MAINE AK AL AR AZ CA CO CT DE FL GA HI IA ID IL IN KS KY LA MA MD ME MI MN MO

Table Structures: Heaps MA MN IL KY AR CO MI DE IN GA HI AZ It’s unordered. It’s harder to find the row you want. But for our purposes today, it’s similar to the leaf level of a B-Tree ID CT MD KS IA LA MO CA ME AK AL FL

Index Flavors

Clustered vs Nonclustered Clustered Index Nonclustered index This is the row data Ordered by the key columns All the columns Except if it’s over 8kb LOB data & wide tables use off-row data The columns explicitly listed in the key or include clause Plus the clustering key Or the RID if it’s a heap Ordered by the key columns Maximum key size is 1700b

Filtered indexes A non-clustered index with a WHERE clause Filters specific rows https://amzn.to/2mLajwX

Filtered Indexes Use equality/inequality operators =, <>, <, >, <=, >=, IS NULL, IS NOT NULL, IN(…) Cannot use BETWEEN or NOT IN Must be deterministic Example: not based on GETDATE()

Filtered Index Sample ON dbo.WidgetQueue (QueueStatus) CREATE INDEX ix_QueueStatus ON dbo.WidgetQueue (QueueStatus) WHERE QueueStatus = 'S';

Compressed indexes A different method of storing data on disk and in memory More efficient use of space Requires slightly more CPU to read/write data https://amzn.to/2nmseKV

Index Compression types ROW PAGE Applied to each individual row Usually makes a row occupy fewer bytes Smaller rows  More rows per page Applies row compression first Then prefix compression Then dictionary compression Essentially dedupes data within the page Notice I say USUALLY takes less space. It’s that whole “It Depends” thing. More on that later

Compression Sample ON dbo.WidgetQueue (QueueStatus) CREATE INDEX ix_QueueStatus ON dbo.WidgetQueue (QueueStatus) WITH (DATA_COMPRESSION = PAGE);

Included Columns Extra columns in the index, not part of the key Can be data types not allowed as key columns Not considered when calculating size limitations Avoids key/RID lookups

Included Column Sample CREATE INDEX ix_QueueStatus ON dbo.WidgetQueue (QueueStatus) INCLUDE (ExternalID);

Included Column Sample CREATE INDEX ix_QueueStatus ON dbo.WidgetQueue (QueueStatus) INCLUDE (ExternalID);

Columnstore Indexes Physically stored in a column-wise data format High compression rates for large data sets with repeated values Turns storage 90 degrees Primarily accesses data by columns, rather than by rows https://amzn.to/2lbcUQj

Columnstore Sample CREATE CLUSTERED COLUMNSTORE INDEX cci ON dbo.ReallyBigTable; CREATE NONCLUSTERED COLUMNSTORE INDEX ncci ON dbo.ReallyBigTable (ProductID, CustomerID, Amount);

Partitioning Breaks up a table into multiple B-Trees A management feature for large tables Not a performance feature https://amzn.to/2lNH8ZW

When to use fancy indexes

Filtered Indexes Queues & status processing are great use cases Queries cannot use the index is the index filter uses a variable or parameter in the predicate WHERE status = ‘a’ WHERE status = @status

Compression Costs & Benefits Pros Cons Less space on disk This benefit multiplies each time you copy data to a different environment More rows per page on disk Fewer physical IO operations More rows per page in memory Cache more data in memory Fewer logical IO operations Small CPU overhead associated with compression Is CPU already a bottleneck? Overall CPU impact likely minimal Data needs to decompressed every time you read a page from memory Enterprise Edition feature (until 2016) $$$$ Impacts database portability Because it’s the SAME PAGE on memory & on disk, these two bullets are really saying the same thing No longer Enterprise only if (only if) you are on 2016 SP1+ The list of cons is pretty short.

When ROW compression can’t compress Variable-length data Varchar Varbinary LOB data types XML n/varchar(max) Fixed-length data that uses full length UNIQUEIDENTIFIER DATE or TIME CHAR(10) that actually contains 10 characters

When PAGE compression can’t compress Rows with highly unique data LOB data types XML n/varchar(max) It also WON’T compress if the savings isn’t significant “I can make more room, but not enough to fit extra rows. Never mind” It still tries every time it writes the page, burning CPU

Columnstore Index usage The preferred data storage format for data warehousing and analytics workloads Non-clustered columnstore indexes can be added to OLTP databases “Real time operational analytics” 🐝🐝

Partitioning Not a performance feature Data management feature Ok, Partition Elimination can help performance Data management feature Partition swapping Truncating or dropping a partition Piecemeal restores

How many indexes are enough?

Not an easy answer Slow inserts aren’t usually a problem Index & Stats maintenance will take longer with more indexes 999 non-clustered indexes on a table is a limitation, not a dare

Filtered indexes Compressed indexes Columnstore Partitioning https://www.sqlpassion.at/archive/2018/11/05/filtered-indexes-in- sql-server/ Compressed indexes https://am2.co/category/data-compression/ Columnstore http://www.nikoport.com/columnstore/ Partitioning https://www.cathrinewilhelmsen.net/2015/04/12/table-partitioning- in-sql-server/