Download presentation
Presentation is loading. Please wait.
1
Welcome!
2
Forrest McDaniel www.forrestmcdaniel.com tsqladdict@gmail.com
3
NERD
7
California Vehicle Code 665.5
A “U-turn” is the turning of a vehicle upon a highway so as to proceed in the opposite direction whether accomplished by one continuous movement or not.
10
Roadmap Basic ideas Operators Tips for reading
11
BasicS
12
BasicS How would you store data?
13
Seek and scan Organized data is easier to search
14
B-Tree
17
B-Tree Navigation Pages Data Pages
18
B-Tree Root Page Leaf Pages
19
B-Tree 1≤N<4 4≤N Left Right
20
SEEK SCAN
21
Seek and scan
22
Clustered and Nonclustered Indexes
23
Clustered and Nonclustered Indexes
24
Execution Plans
25
Execution Plans suck
26
Execution Plans suck
27
Execution Plans suck
28
Top
29
Top
30
Filter
31
Filter
32
Filter
33
Sort
34
Sort
35
dbo.UsersDemo
36
ID Clustered Index DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int int int
37
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
38
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
39
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
40
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
41
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
42
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
43
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
44
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
45
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
46
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
47
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
48
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
50
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
51
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
52
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
53
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
54
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
55
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
56
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
57
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
58
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
59
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
60
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
61
ID PK DisplayName Nonclustered Index CreationDate Nonclustered Index Reputation Nonclustered Index int int int nvarchar(40) nvarchar(MAX) nvarchar(100) datetime int
64
Joins
65
Nested Loops
68
Nested Loops
69
Nested Loops
70
Nested Loops Best with small inputs.
Slooooow with really large inner inputs.
71
Merge
74
Merge Needs sorted data Many-to-many slows down
75
hash
78
hash “Semi-blocking” Needs memory
79
So which join is best?
80
Summary Join Strengths Weaknesses Commonly Seen Nested Loops
Simple, fast with good indexing Large inputs, bad cardinality estimates Small joins and proper indexing Merge Very fast with sorted inputs Sorting, many-to-many. Key to key joins, ORDER BY. Hash Generally fast Memory usage, spilling. Large joins. Heaps. No indexes.
81
Aggregates
82
Aggregates
94
Reading Plans
95
Reading plans Get the plans! Estimated vs Actual
sys.dm_exec_query_stats and sys.dm_exec_query_plan Query Store
96
Reading plans Percentages are not your friends
97
Reading plans Percentages are not your friends
Missing index suggestions are your frenemies
98
Reading plans Percentages are not your friends
Missing index suggestions are your frenemies Thickness of lines is helpful…mostly
99
Reading plans Actual time statistics are most helpful
100
Closing Remarks…
101
Go tune!
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.