Choosing Your Clustered Index
Introduction
Jason
Strate

e: jstrate@pragmaticworks.com
e: jasonstrate@gmail.com
b: www.jasonstrate.com

t: StrateSQL

Re...
About Pragmatic Works

•
•
•
•
•
•
•

Industry leaders in Microsoft BI and SQL Server
Platform
SQL Server Professionals - ...
Navigation
Challenge of data…
Driving for performance
Check you options!
Agenda

Introduction

Clustered Index
or Heap

Clustered Index
Patterns
MAKING BUSINESS INTELLIGENT

Clustered Index
Quali...
Session Goals
• Define basics related to
clustered indexes
• Explain rules behind
selecting clustering key
• Demonstrate d...
Introduction

Clustered
Index or
Heap

Clustered
Index
Qualities

Clustered
Index
Patterns

Summary

CLUSTERED INDEX OR HE...
Heap Structure
• Pile of data
– Unordered
– First in, first out
– Scan “happy”

MAKING BUSINESS INTELLIGENT

www.pragmatic...
Heap

MAKING BUSINESS INTELLIGENT

www.pragmaticworks.com
Heap

MAKING BUSINESS INTELLIGENT

www.pragmaticworks.com
Clustered Index
• Mechanism for storing data
– Ordered
– Structured
– Accessible
– Direct path

MAKING BUSINESS INTELLIGEN...
Clustered Index

MAKING BUSINESS INTELLIGENT

www.pragmaticworks.com
Clustered Index

MAKING BUSINESS INTELLIGENT

www.pragmaticworks.com
Clustered Index or Heap

DEMO

MAKING BUSINESS INTELLIGENT

www.pragmaticworks.com
Pro Tip: Default
to Clustered
Indexes, unless
heaps are proven
to improve
performance
Introduction

Clustered
Index or
Heap

Clustered
Index
Qualities

Clustered
Index
Patterns

Summary

CLUSTERED INDEX QUALI...
Clustered Index Qualities

Static

Unique

MAKING BUSINESS INTELLIGENT

Narrow

Everincreasing

www.pragmaticworks.com
Clustered Index Qualities

Static

Unique

MAKING BUSINESS INTELLIGENT

Narrow

Everincreasing

www.pragmaticworks.com
Clustered Index Qualities

Static

Unique

MAKING BUSINESS INTELLIGENT

Narrow

Everincreasing

www.pragmaticworks.com
Narrow
Size
Rows

4

8

16

32

64

10,000

0.04

0.08

0.15

0.31

0.61

100,000

0.38

0.76

1.53

3.05

6.10

1,000,000...
Clustered Index Qualities

Static

Unique

MAKING BUSINESS INTELLIGENT

Narrow

Everincreasing

www.pragmaticworks.com
Unique
• Uniqueifier
Size
Rows

4

8

16

32

64

10,000

0.08

0.11

0.19

0.34

0.65

100,000

0.76

1.14

1.91

3.43

6...
Clustered Index Qualities

Static

Unique

MAKING BUSINESS INTELLIGENT

Narrow

Everincreasing

www.pragmaticworks.com
Ever-Increasing

1

2

MAKING BUSINESS INTELLIGENT

3

4

5

6

www.pragmaticworks.com
Ever-Increasing

1

3

MAKING BUSINESS INTELLIGENT

5

6

2

4

www.pragmaticworks.com
Ever-Increasing

1

2

MAKING BUSINESS INTELLIGENT

3

4

5

6

www.pragmaticworks.com
These are not
unbreakable rules!
Introduction

Clustered
Index or
Heap

Clustered
Index
Qualities

Clustered
Index
Patterns

Summary

CLUSTERED INDEX PATTE...
Clustered Index Patterns

Identity
Column

MAKING BUSINESS INTELLIGENT

Surrogate
Key

Foreign Key

MultiColumn

Globally
...
Identity Column
• Non-related value that defines each row
uniquely
• Assigned when data is inserted
• Typically uses:
– In...
Identity Column
Static
Narrow
Unique
Ever-increasing

MAKING BUSINESS INTELLIGENT

www.pragmaticworks.com
Identity Column

DEMO

MAKING BUSINESS INTELLIGENT

www.pragmaticworks.com
Surrogate Key
•
•
•
•

Unique value is a part of the row
Assigned in the source data
Data type dependent on the data
Value...
Surrogate Key
Static
Narrow
Unique
Ever-increasing

MAKING BUSINESS INTELLIGENT

www.pragmaticworks.com
Surrogate Key

DEMO

MAKING BUSINESS INTELLIGENT

www.pragmaticworks.com
Foreign Key
• One-to-many relationships
• Access path in child via parent
• Piggy-backs identity pattern
– Parent left of ...
Foreign Key
Static
Narrow
Unique
Ever-increasing

MAKING BUSINESS INTELLIGENT

www.pragmaticworks.com
Foreign Key

DEMO

MAKING BUSINESS INTELLIGENT

www.pragmaticworks.com
Multi-Column
•
•
•
•

Similar to foreign key pattern
Many-to-many relationships
Highly dependent on selectivity
NOT a coll...
Multi-Column
Static
Narrow
Unique
Ever-increasing

MAKING BUSINESS INTELLIGENT

www.pragmaticworks.com
Multi-Column

DEMO

MAKING BUSINESS INTELLIGENT

www.pragmaticworks.com
Globally Unique Identifier
• Non-related value that defines each row
uniquely
• Assigned when data is inserted
– Or from t...
Globally Unique Identifier
Static
Narrow
Unique
Ever-increasing

MAKING BUSINESS INTELLIGENT

www.pragmaticworks.com
Globally Unique Identifier

DEMO

MAKING BUSINESS INTELLIGENT

www.pragmaticworks.com
Pro Tip: Clustered
indexes should be
Static, Narrow,
Unique, and Everincreasing
Introduction

Clustered
Index or
Heap

Clustered
Index
Qualities

Clustered
Index
Patterns

Summary

SUMMARY

MAKING BUSIN...
Summary
• Clustered indexes are important
• Select clustering keys based on need
• Validate clustered indexes over time

M...
More Information
Expert Performance Indexing
For SQL Server 2012
Jason Strate
Ted Krueger

Overview
Statistics
Maintenance...
For more information…
Name: Jason Strate

Email: jstrate@pragmaticworks.com
Blog: www.jasonstrate.com
Resource: jasonstrat...
Choosing Your Clustered Index
Choosing Your Clustered Index
Upcoming SlideShare
Loading in …5
×

Choosing Your Clustered Index

1,269 views

Published on

We often hear that you should always have clustered indexes on your tables. What's left off of this discussion is the how to choose the columns for this index. Should it be the primary key? Or some other column or set of columns? Having the wrong key column(s) in the clustered index can lead to performance problems, possibly worse than having no clustered index on the table at all. In this session, we'll review common patterns for selecting clustered indexes and how to determine which pattern you need. Also, we'll look at how to analyze tables to help select the best clustered index for every table.

http://www.jasonstrate.com/go/20131010-IX/

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,269
On SlideShare
0
From Embeds
0
Number of Embeds
476
Actions
Shares
0
Downloads
17
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Choosing Your Clustered Index

  1. 1. Choosing Your Clustered Index
  2. 2. Introduction Jason Strate e: jstrate@pragmaticworks.com e: jasonstrate@gmail.com b: www.jasonstrate.com t: StrateSQL Resources jasonstrate.com/go/indexing MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  3. 3. About Pragmatic Works • • • • • • • Industry leaders in Microsoft BI and SQL Server Platform SQL Server Professionals - PASS Board of Directors, Speakers, Authors and MVP’s National Sales Team Divided by Microsoft Territories National System Integrator (NSI) Gold Certified in Business Intelligence and Data Platform Platform Modernization/Safe Passage Premier Partner for PDW SI Partner Program MS PDW Partner of Year FY13 Frontline Partnership Partner of the Year for Big Data Executive sponsor - Andy Mouacdie, WW sales director PDW • • Over 7,200 customers worldwide Over 186,000 people in PW database for demand generation MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  4. 4. Navigation
  5. 5. Challenge of data…
  6. 6. Driving for performance
  7. 7. Check you options!
  8. 8. Agenda Introduction Clustered Index or Heap Clustered Index Patterns MAKING BUSINESS INTELLIGENT Clustered Index Qualities Summary www.pragmaticworks.com
  9. 9. Session Goals • Define basics related to clustered indexes • Explain rules behind selecting clustering key • Demonstrate differences between key column choices MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  10. 10. Introduction Clustered Index or Heap Clustered Index Qualities Clustered Index Patterns Summary CLUSTERED INDEX OR HEAP MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  11. 11. Heap Structure • Pile of data – Unordered – First in, first out – Scan “happy” MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  12. 12. Heap MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  13. 13. Heap MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  14. 14. Clustered Index • Mechanism for storing data – Ordered – Structured – Accessible – Direct path MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  15. 15. Clustered Index MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  16. 16. Clustered Index MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  17. 17. Clustered Index or Heap DEMO MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  18. 18. Pro Tip: Default to Clustered Indexes, unless heaps are proven to improve performance
  19. 19. Introduction Clustered Index or Heap Clustered Index Qualities Clustered Index Patterns Summary CLUSTERED INDEX QUALITIES MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  20. 20. Clustered Index Qualities Static Unique MAKING BUSINESS INTELLIGENT Narrow Everincreasing www.pragmaticworks.com
  21. 21. Clustered Index Qualities Static Unique MAKING BUSINESS INTELLIGENT Narrow Everincreasing www.pragmaticworks.com
  22. 22. Clustered Index Qualities Static Unique MAKING BUSINESS INTELLIGENT Narrow Everincreasing www.pragmaticworks.com
  23. 23. Narrow Size Rows 4 8 16 32 64 10,000 0.04 0.08 0.15 0.31 0.61 100,000 0.38 0.76 1.53 3.05 6.10 1,000,000 3.81 7.63 15.26 30.52 61.04 10,000,000 38.15 76.29 152.59 305.18 610.35 100,000,000 381.47 762.94 1,525.88 3,051.76 6,103.52 1,000,000,000 3,814.70 7,629.39 15,258.79 30,517.58 61,035.16 MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  24. 24. Clustered Index Qualities Static Unique MAKING BUSINESS INTELLIGENT Narrow Everincreasing www.pragmaticworks.com
  25. 25. Unique • Uniqueifier Size Rows 4 8 16 32 64 10,000 0.08 0.11 0.19 0.34 0.65 100,000 0.76 1.14 1.91 3.43 6.48 1,000,000 7.63 11.44 19.07 34.33 64.85 10,000,000 76.29 114.44 190.73 343.32 648.50 100,000,000 762.94 1,144.41 1,907.35 3,433.23 6,484.99 1,000,000,000 7,629.39 11,444.09 19,073.49 34,332.28 64,849.85 MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  26. 26. Clustered Index Qualities Static Unique MAKING BUSINESS INTELLIGENT Narrow Everincreasing www.pragmaticworks.com
  27. 27. Ever-Increasing 1 2 MAKING BUSINESS INTELLIGENT 3 4 5 6 www.pragmaticworks.com
  28. 28. Ever-Increasing 1 3 MAKING BUSINESS INTELLIGENT 5 6 2 4 www.pragmaticworks.com
  29. 29. Ever-Increasing 1 2 MAKING BUSINESS INTELLIGENT 3 4 5 6 www.pragmaticworks.com
  30. 30. These are not unbreakable rules!
  31. 31. Introduction Clustered Index or Heap Clustered Index Qualities Clustered Index Patterns Summary CLUSTERED INDEX PATTERNS MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  32. 32. Clustered Index Patterns Identity Column MAKING BUSINESS INTELLIGENT Surrogate Key Foreign Key MultiColumn Globally Unique Identifier www.pragmaticworks.com
  33. 33. Identity Column • Non-related value that defines each row uniquely • Assigned when data is inserted • Typically uses: – Int or bigint – IDENTITY or SEQUENCE MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  34. 34. Identity Column Static Narrow Unique Ever-increasing MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  35. 35. Identity Column DEMO MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  36. 36. Surrogate Key • • • • Unique value is a part of the row Assigned in the source data Data type dependent on the data Value should be unchanging – Employee ID – Social Security Number – Birthdate MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  37. 37. Surrogate Key Static Narrow Unique Ever-increasing MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  38. 38. Surrogate Key DEMO MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  39. 39. Foreign Key • One-to-many relationships • Access path in child via parent • Piggy-backs identity pattern – Parent left of child identity value • Common in many applications – Order header to details – Hotels to rooms MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  40. 40. Foreign Key Static Narrow Unique Ever-increasing MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  41. 41. Foreign Key DEMO MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  42. 42. Multi-Column • • • • Similar to foreign key pattern Many-to-many relationships Highly dependent on selectivity NOT a collection of dimension keys MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  43. 43. Multi-Column Static Narrow Unique Ever-increasing MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  44. 44. Multi-Column DEMO MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  45. 45. Globally Unique Identifier • Non-related value that defines each row uniquely • Assigned when data is inserted – Or from the application • Typically uses: – uniqueidentifier – NEWID() or NEWSEQUENTIALID() MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  46. 46. Globally Unique Identifier Static Narrow Unique Ever-increasing MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  47. 47. Globally Unique Identifier DEMO MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  48. 48. Pro Tip: Clustered indexes should be Static, Narrow, Unique, and Everincreasing
  49. 49. Introduction Clustered Index or Heap Clustered Index Qualities Clustered Index Patterns Summary SUMMARY MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  50. 50. Summary • Clustered indexes are important • Select clustering keys based on need • Validate clustered indexes over time MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  51. 51. More Information Expert Performance Indexing For SQL Server 2012 Jason Strate Ted Krueger Overview Statistics Maintenance Tools Analysis http://amzn.com/1430237414 MAKING BUSINESS INTELLIGENT www.pragmaticworks.com
  52. 52. For more information… Name: Jason Strate Email: jstrate@pragmaticworks.com Blog: www.jasonstrate.com Resource: jasonstrate.com/go/indexing Products BI products to covert to a Microsoft BI platform and simplify development on the platform. Services Speed development through training, and rapid development services from Pragmatic Works. Foundation Helping those who do not have the means to get into information technology achieve their dreams.

×