Table Indexing for the.NET Developer Denny Cherry twitter.com/mrdenny.

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.
Denny Cherry Manager of Information Systems MVP, MCSA, MCDBA, MCTS, MCITP.
Managing and Maintaining Indexes and Statistics. Table Fragmentation Causes 1 Massive Updates or deletes 2 Frequent Page Splitting 3 Disk space contention.
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.
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
SQL Server Storage and Index Structures Physical Data Organization Indexes B-Trees SQL Server Data Access Clustered and Non-Clustered Creating, Altering,
Indexes Rose-Hulman Institute of Technology Curt Clifton.
DAT702.  Standard Query Language  Ability to access and manipulate databases ◦ Retrieve data ◦ Insert, delete, update records ◦ Create and set permissions.
Denny Cherry twitter.com/mrdenny.
DAY 21: MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Akhila Kondai October 30, 2013.
Module 9: Managing Schema Objects. Overview Naming guidelines for identifiers in schema object definitions Storage and structure of schema objects Implementing.
Introduction to SQL Structured Query Language Martin Egerhill.
Performing Indexing and Full-Text Searching Lesson 21.
Using XML in SQL Server 2005 NameTitleCompany. XML Overview Business Opportunity The majority of all data transmitted electronically between organizations.
Module 8 Improving Performance through Nonclustered Indexes.
 SQL stands for Structured Query Language.  SQL lets you access and manipulate databases.  SQL is an ANSI (American National Standards Institute) standard.
Lecture 8 Index Organized Tables Clusters Index compression
CHAPTER:14 Simple Queries in SQL Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्सजेंड़र ) PGT(CS),KV JHAGRAKHAND.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with MSSQL Server Code:G0-C# Version: 1.0 Author: Pham Trung Hai CTD.
T-sql triger examples.  Öğrenci eklendiğinde mesaj veren triger CREATE TRIGGER trigAddStudents ON Students FOR INSERT AS VARCHAR(100)
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.
Denny Cherry twitter.com/mrdenny.
Denny Cherry twitter.com/mrdenny.
Indexes / Session 2/ 1 of 36 Session 2 Module 3: Types of Indexes Module 4: Maintaining Indexes.
SQL Server 2005 Implementation and Maintenance Chapter 3: Tables and Views.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
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.
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.
Constraints Lesson 8. Skills Matrix Constraints Domain Integrity: A domain refers to a column in a table. Domain integrity includes data types, rules,
SQL Server 2005: Extending the Type System with XML.
Session 1 Module 1: Introduction to Data Integrity
INTRODUCING SQL SERVER 2012 COLUMNSTORE INDEXES Exploring and Managing SQL Server 2012 Database Engine Improvements.
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.
Indexing Fundamentals Steve Hood SimpleSQLServer.com.
Table Structures and Indexing. The concept of indexing If you were asked to search for the name “Adam Wilbert” in a phonebook, you would go directly to.
SQL SERVER DAYS 2011 Indexing Internals Denny Cherry twitter.com/mrdenny.
Retele de senzori Curs 2 - 1st edition UNIVERSITATEA „ TRANSILVANIA ” DIN BRAŞOV FACULTATEA DE INGINERIE ELECTRICĂ ŞI ŞTIINŢA CALCULATOARELOR.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
October 15-18, 2013 Charlotte, NC Accelerating Database Performance Using Compression Joseph D’Antoni, Solutions Architect Anexinet.
--A Gem of SQL Server 2012, particularly for Data Warehousing-- Present By Steven Wang.
Scott Fallen Sales Engineer, SQL Sentry Blog: scottfallen.blogspot.com.
SQL Basics Review Reviewing what we’ve learned so far…….
Database Administration for the Non-DBA Denny Cherry twitter.com/mrdenny.
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.
Chris Index Feng Shui Chris
Indices.
Module 4: Creating and Tuning Indexes
COMP 430 Intro. to Database Systems
Introduction to SQL Server Management for the Non-DBA
Database Administration for the Non-DBA
Table Indexing for the .NET Developer
Lecture 12 Lecture 12: Indexing.
Teaching slides Chapter 8.
Microsoft SQL Server 2014 for Oracle DBAs Module 7
Introduction To Structured Query Language (SQL)
Denny Cherry twitter.com/mrdenny
Introduction To Structured Query Language (SQL)
Clustered Columnstore Indexes (SQL Server 2014)
Chapter 11 Managing Databases with SQL Server 2000
All about Indexes Gail Shaw.
SQL Server Indexing for the Client Developer
XML? What’s this doing in my database? Adam Koehler
Presentation transcript:

Table Indexing for the.NET Developer Denny Cherry twitter.com/mrdenny

About Me  Independent Consultant  Author or Coauthor of 5 books  8+ SQL Mag articles  Dozens of other articles  Microsoft MVP  Microsoft Certified Master  VMware vExpert  Microsoft Certified Trainer 2

Today’s Goals  Introduce the different kinds of indexes  Common Misconceptions about indexes  Downsides to indexes  Introduce advanced index tuning techniques  Q & A

Today’s Goals  Introduce the different kinds of indexes  Common Misconceptions about indexes  Downsides to indexes  Introduce advanced index tuning techniques  Q & A

Different Kinds of Indexes  Five Kinds of Indexes  Clustered  Non-clustered  Full Text  XML  ColumnStore Indexes  There’s new stuff coming in SQL Server 2012  Semantic Search

Clustered Indexes  1 Clustered Index per table  Contain Full Copy of row data within in the index  Up to 16 indexed columns can be part of the index  (15 if the table contains any XML indexes)  Primary Key will by default be the Clustered Index  Must be created on the same filegroup as the table  Clustered Indexes should be as narrow as possible  While not required, they are highly recommended

Non-clustered Index  Up to 999 per table Starting with SQL Server 2008  255 in SQL Server 2005 and below  Up to 16 indexed columns in the index  Non-indexed columns can be included via INCLUDE statement  Non-Clustered indexes always contain the clustered index columns (when table has a clustered index)  When table is a heap, the Row ID is stored in every non- clustered index.  Can be created on any filegroup within the database  Can be filtered indexes to include fewer rows in the index.

Differences between unique and non-unique clustered indexes  Non-Unique clustered indexes have an extra column called the uniqueifier which ensures that values within the index are unique.  Uniqueifier is only used for rows which are not unique. EmpIdUniqufier

Full Text Indexes  Not accessed via normal SELECT statements  Require use of a predicate:  CONTAINS  CONTAINSTABLE  FREETEXT  FREETEXTTABLE  Can be used to search binary values (doc, docx, xls, pdf) stored within the database.  Natural Language Search  Can index XML documents, but only indexes the values, not the tags.

Full Text Indexes (SQL 2005 and below)  Created and managed outside of the database via Microsoft Search Service  Backed up with the database (starting in SQL 2005)  Searches entire index and returns all matches, which you then filter against your normal table to return correct set of rows.

Full Text Indexes (SQL 2008 and up)  Now stored within the database  Command is still parsed via MS Search service, but looking is done natively  Full text search now only searches the required subset of rows  When creating your indexes use an identity field as the key to improve query performance.

XML Indexes  Allows you to index specific nodes of the XML document  249 XML Indexes pre table  Requires a Clustered Index on the table  Each xml column can have a single primary XML index and multiple secondary XML indexes  XML Indexes can only be created on a single XML Column  No online rebuilds  Not available for XML variables. Only used on tables.

Primary XML Index  When created creates a hidden node table  Contains base table primary key and 12 columns of info about every node within the XML value  Effectively the clustered index on the node table  Base Table Clustered Index Value  Node id from the node table  Increases storage %

Secondary XML Indexes  Non-Clustered Indexes on the hidden node table  Three kinds of secondary indexes  PATH index on the node id (path) and the value  VALUE index is on the value and the node id (path)  PROPERTY index is on the base table’s clustered index, node id (path) and the value

What is a ColumnStore Index?  Totally new and different approach to indexing  Data is stored via columns not rows  Each column is stored separately, then compressed using VertiPak compression engine  SQL Server’s first B-Tree less index

How does ColumnStore do that? C1C2C2 C3C5C6C4 Existing Pages Needed Columns

ColumnStore: Use Case  Data continues to grow, but performance requirements stay the same  Many data warehouses approach PB ranges  Data needs to be filtered, aggregated, and grouped despite the size of the dataset

Limitations  Unsupported Data Types include  Uniqueidentifier  Blob  Numeric (19,2) or higher  Read Only  OUTER JOINs using ColumnStore don’t perform well

Column Store

Today’s Goals  Introduce the different kinds of indexes  Common Misconceptions about indexes  Downsides to indexes  Introduce advanced index tuning techniques  Q & A

Common Misconceptions about indexes  Indexes don’t require maintenance  If I create one index for each column in my where clause I’ll be fine  The table is sorted based on the order of the Clustered Index  Clustered Indexes are required

Today’s Goals  Introduce the different kinds of indexes  Common Misconceptions about indexes  Downsides to indexes  Introduce advanced index tuning techniques  Q & A

Downsides to indexes  Indexes take up space  On large complex databases the indexes can take up more space than the table  Data is duplicated in each index which contains the column  Indexes slow down insert, update, delete (especially full text indexes) statements  Using the wrong index can be slower than using no index  Encrypted data can’t be effectively indexed

Today’s Goals  Introduce the different kinds of indexes  Common Misconceptions about indexes  Downsides to indexes  Introduce advanced index tuning techniques  Q & A

Advanced Index Tuning Techniques  Fillfactor  Tells the SQL Server how much free space to leave in the leaf level pages.  Padding  Tells the SQL Server to use the Fillfactor setting to leave free space in the intermediate-level pages.  Online Rebuilds  Data Compression

Using the Advanced Index Tuning Techniques CREATE INDEX MyIndex ON dbo.MyTable ON (Col1, Col5, Col3) INCLUDE (Col4, Col2) WHERE Col6 = ‘Value3’ WITH (FILLFACTOR=70, PAD_INDEX=ON, ONLINE=ON, DATA_COMPRESSION = ROW | PAGE);

Physical Index B-Tree Layout Clustered (BOL 2005 / 2008) Non-Clustered (BOL 2005 / 2008)

How large are my indexes?  SELECT *  FROM sys.dm_db_index_physical_stats (db_id(), object_id(‘table_name’), null, null, ‘detailed’)  Database Id  Object Id  Index Id  Partition Number  Mode (NULL | Limited, Sampled, Detailed)

What Indexes are being used?  INT VARCHAR(100);   = DB_ID() = DB_NAME();   WITH partitionCTE (OBJECT_ID, index_id, row_count, partition_count)  AS  (  SELECT [OBJECT_ID] , index_id , SUM([ROWS]) AS 'row_count' , COUNT(partition_id) AS 'partition_count'  FROM sys.partitions  GROUP BY [OBJECT_ID] , index_id  )   SELECT OBJECT_NAME(i.[OBJECT_ID]) AS objectName , i.name , CASE  WHEN i.is_unique = 1  THEN 'UNIQUE '  ELSE ''  END + i.type_desc AS 'indexType' , ddius.user_seeks , ddius.user_scans , ddius.user_lookups , ddius.user_updates , cte.row_count , CASE WHEN partition_count > 1 THEN 'yes'  ELSE 'no' END AS 'partitioned?' , CASE  WHEN i.type = 2 And i.is_unique = 0  THEN 'Drop Index ' + i.name  + ' On '  + '.dbo.' + OBJECT_NAME(ddius.[OBJECT_ID]) + ';'  WHEN i.type = 2 And i.is_unique = 1  THEN 'Alter Table '  + '.dbo.' + OBJECT_NAME(ddius.[OBJECT_ID])  + ' Drop Constraint ' + i.name + ';'  ELSE ''  END AS 'SQL_DropStatement'  FROM sys.indexes AS i  INNER Join sys.dm_db_index_usage_stats ddius  ON i.OBJECT_ID = ddius.OBJECT_ID  And i.index_id = ddius.index_id  INNER Join partitionCTE AS cte  ON i.OBJECT_ID = cte.OBJECT_ID  And i.index_id = cte.index_id  WHERE ddius.database_id  ORDER BY 1,  (ddius.user_seeks + ddius.user_scans + ddius.user_lookups) ASC , user_updates DESC; Don’t worry, you can download this from my blog, or from sqlfool.com (where I stole it from).

More Reading… 

Q & A

Denny Cherry Please rate my presentation at