The document outlines 5 "detective stories" or troubleshooting scenarios involving SQL Server performance issues. Story 1 discusses slow query performance due to locking and blocking. Story 2 involves a missing database. Story 3 is about a database file that won't shrink due to fragmentation. Story 4 looks at high CPU with no queries running. And story 5 examines parameter sniffing issues causing intermittent performance. The presenter provides demonstrations of resolving each issue.
2. About Me
⢠Denis Reznik
⢠Kyiv, Ukraine
⢠Data Architect at Intapp
⢠Microsoft Data Platform MVP
⢠Co-Founder of Ukrainian Data Community Kyiv (PASS Chapter)
⢠PASS Regional Mentor, Central and Eastern Europe
⢠Co-author of âSQL Server MVP Deep Dives vol. 2â
3. Agenda
⢠Detective Story 1
⢠Why my query is slow?
⢠Detective Story 2
⢠Where is my database, dude?
⢠Detective Story 3
⢠File size is not reducing.
⢠Detective Story 4
⢠My CPU is burning but no queries are executing!
⢠Detective Story 5 (?)
⢠How deep is the rabbit hole?
5. Case Details
⢠User Experience
⢠Everything is slow
⢠System is not working
⢠Technical Details
⢠Query Timeout errors
⢠Connection Timeout Errors
⢠Long-Running Queries
7. LCK_M_* Waits
0
SchedulersRunnable Queue
1
2 1
Suspended Queue
2
SELECT * FROM Users
WHERE Name = 'Scott Nall'
UPDATE Users
SET Name = 'Optimus Prime'
WHERE Id = 3
Id Name
1 John Snow
2 Peter Partner
3 Scott Nall
4 Jane Dow
1
Users
2
3
2
Id Name
1 John Snow
2 Peter Partner
3 Optimus Prime
4 Jane Dow
LCK_M_X
LCK_M_X
2
X S
13. Case Details
⢠User Experience
⢠Disk space is running out
⢠Database file is not shrinking
⢠Preparing for disaster
⢠Technical Details
⢠Database Shrink operation stuck even on 1 MB Shrink
⢠Database is in FULL recovery mode
⢠Database is a part of availability group
⢠Database indexes are highly fragmented (50%-90%)
19. Case Details
⢠User Experience
⢠No explanation for the consistent 10%-20% of CPU utilization
⢠During the peak load this additional utilization become critical
⢠Technical Details
⢠Letâs check them on Demo
22. Case Details
⢠User Experience
⢠Application become slow apparently
⢠In a minute the same operation can be fast again
⢠Technical Details
⢠Query execution is really slow
⢠Running the same query in SSMS is almost instantaneous
23. Parameter Sniffing - Stored Procedure
EXEC ReportSecurityPermissions
@UserId = 1
Query
Processor
SQL Server Cache
Procedure cache
Plan created and cached for the
@UserId = 1
Procedure cache
EXEC ReportSecurityPermissions
@UserId = 22
Query executes using the query plan created for
@UserId = 1
24. SELECT * FROM Users WHERE Id = @Id
Parameter Sniffing - Parametrized Query
Query
Processor
SQL Server Cache
Procedure cache
Plan created and cached for the
@Id = 1
Procedure cache
Query executes using the query plan created for
@Id = 1
SELECT * FROM Users WHERE Id = @Id
sp_executesql N'SELECT * FROM Users
WHERE Id = @Id', N'@Id int', 1
sp_executesql N'SELECT * FROM Users
WHERE Id = @Id', N'@Id int', 22
25. Dynamic SQL â Multiple Plans
SELECT * FROM Users WHERE Id = 1
Query
Processor
SQL Server Cache
Procedure cache
New query plan created and cached. Query
executed using newly created plan.
Procedure cache
SELECT * FROM Users WHERE Id = 22
New query plan again created and cached.
Query executed using newly created plan.
SELECT * FROM Users WHERE Id = 1
Query executed using the query plan, created for
the first query.
Procedure cache
27. Summary
⢠Detective Story 1
⢠Why my query is slow?
⢠Detective Story 2
⢠Where is my database?
⢠Detective Story 3
⢠File size is not reducing.
⢠Detective Story 4
⢠My CPU is burning but no queries are executing!
⢠Detective Story 5 (?)
⢠How deep is the rabbit hole?