SQL Server Index and Partition Strategy

15
Index and Partition Strategy By: Hamid J. Fard (Data Platform Specialist)

Transcript of SQL Server Index and Partition Strategy

Page 1: SQL Server Index and Partition Strategy

Index and Partition Strategy

By: Hamid J. Fard (Data Platform Specialist)

Page 2: SQL Server Index and Partition Strategy

Session Outlines:What an Index is.The benefits and overhead of an Index.General recommendation for index design.Recommendation for Clustered and non-

Clustered Index.Index on Partitioned Table

Page 3: SQL Server Index and Partition Strategy

What is an Index?An object in SQL Server Database.Affects I/O Physical and Logical Operations.Affects to Performance of Retrieving Data.There are Two Types of Index.It might Change the Table Structure.Contains Several Levels.

Page 4: SQL Server Index and Partition Strategy

The Benefit of IndexesClustered Index Improves Modification

PerformanceClustered Index Changes the Table StructureClustered Index Sort the Data PhysicallyNon-Clustered Index Improves Query

PerformanceNon-Clustered Index Points at RID or Clustered

IndexNon-Clustered Index can be Stored on Different

I/O Path to Improve the I/O Performance

Page 5: SQL Server Index and Partition Strategy

The Benefit of Indexes (Cont.)Consider single column table with 27 rows.

Initial Layout of 27 Rows

Ordered Layout of 27 Rows

B-Tree Layout of 27 Rows

Page 6: SQL Server Index and Partition Strategy

Index OverheadTable with Index needs more Storage and

MemoryData Manipulation Queries (CRUD) Take LongerMore Processing Time Required to Maintain the

Indexes of Constantly Changing TablesClustered Index has Greater OverheadSQL Server supplies some DMVs for Monitoring

Index Performance and Detail Informationsys.dm_db_index_operational_stats (Low-Level Information)

sys.dm_db_index_usage_stats (Returns Statistics)

Page 7: SQL Server Index and Partition Strategy

Index Design RecommendationExamine the Where and Join criteria clauseUse Narrow IndexesExamine Column UniquenessExamine the Column Data TypeConsider Column OrderConsider the Type of Index (Clustered vs.

NonClustered)

Page 8: SQL Server Index and Partition Strategy

Use Narrow IndexAvoid Wide Data Type such as

CHAR, VARCHAR, NCHAR, NVARCHAR

It can Accumulate more Rows in 8KB Index Page.

Reduces Storage space for Database

Reduces the I/O Operations.

Page 9: SQL Server Index and Partition Strategy

Clustered Index RecommendationsCreate Clustered Index First.Keep the Index Key Narrow.Rebuild the Clustered Index in Single Step.Create Clustered Index with Preorder Sort.Do not Create Clustered Index on Frequently

Updatable Column.Do not Use Wide Key.Prevent Too Many Concurrent Inserts in

Sequential Order.

Page 10: SQL Server Index and Partition Strategy

Non-Clustered Index RecommendationCan be Used with Wide Key.It Can be on Frequently Updatable Columns.Can be Filtered.Can be Used in Join or Where Criteria Clause.Can be on Low Selectivity Column.

Page 11: SQL Server Index and Partition Strategy

Covering IndexesIt can Improve the Query Performance.It Stores the Covering Columns Next to the RID.It does not Required to Read the Base Table.Reduces I/O Operations.Reduces Execution Time.

Page 12: SQL Server Index and Partition Strategy

Index CompressionIntroduced in SQL Server 2008.Available only in Enterprise and Developer

Edition.This can lead to Serious Performance

Improvement.There will be an Overhead of CPU and Memory.Non-Leaf Pages in an Index Receive no

Compression under the Page Type.

Page 13: SQL Server Index and Partition Strategy

Index on Partitioned TableDifferent index will be created on every partition.Each index can be rebuilt or reorganized

separately.It boost up the CRUD operations performance.SQL Server can manage every index separately

on every partition.

Page 14: SQL Server Index and Partition Strategy

DemoCreate Partition TableRetrieve Specific Partition’s Record.Create Index on every Partition.Rebuild the Index on Specific Partition.

Page 15: SQL Server Index and Partition Strategy

Questions and Answers

?(15 Minutes)