Query Tuning for Database Pros & DevelopersTed Krueger
The Developer and DBA Affair• Ownership  – Database Ownership  – Server Ownership  – Code Ownership     • Functional worki...
My T-SQL is so bad your…. – Start here  Developers   • Middle  DBA/Code Review  They should know the internals and perf...
My DBA is so bad your…• Every role has an apple• DBA roles aren’t bad ones  – Making relationships where it counts     • H...
Monitor – Talk DBA to me• Active Monitoring  – Blocking     • Code practices resulting in blocking     • Proactive tuning ...
Tuning - #1 Most Effective AreaQuery Optimization                           Processor  Parsing     Algebrizer             ...
How SELECT is read                        GROUP  FROM   JOIN   WHERE           HAVING   SELECT   SORTS                    ...
Execution Plans             Scan /                             SeekOperations                   Join                   Sor...
Start Tuning – High Cost Operations
Think “Result Set” not like a developer• Data is served not conditioned• Business Rules apply to the business layer not th...
Lookup – RID and Key – The other loop
Preventive T-SQL• Conversions – CONVERT_IMPLICIT• Tempdb – Sort and spills from memory• Sargable – Taking advantage of ind...
Abusive tempdb usage• Estimation of memory results in more needs• Statistics forcing poor Hash Joins• Sorting large amount...
Find pre-existing badness• Querying the Plan Cache  – DMV and DMF     • sys.dm_exec_cached_plans     • sys.dm_exec_sql_tex...
Size Matters – Columns, Tables…Indexes • Column Length and Type   • Duplicates • Overall Table Width      • Overlapping • ...
Index Analysis – Repeat after me!           • Duplicates           • Overlapping           • Too Many             – All le...
ted@onpnt.comThank you!                  http://Twitter.com/onpntwww.magenic.com                  http://blogs.lessthandot...
Upcoming SlideShare
Loading in …5
×

Query Tuning for Database Pros & Developers

698 views
615 views

Published on

Presentation for Code Mastery-Chicago.
Ted Krueger, Associate Principal Consultant, Microsoft MVP

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

  • Be the first to like this

No Downloads
Views
Total views
698
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Query Tuning for Database Pros & Developers

  1. 1. Query Tuning for Database Pros & DevelopersTed Krueger
  2. 2. The Developer and DBA Affair• Ownership – Database Ownership – Server Ownership – Code Ownership • Functional working relationships• SQL Server Performance vs. Database Performance – Tuning T-SQL at the code level – Developer with DBA Assistance – Hardware Tuning – DBA with Developer Assistance
  3. 3. My T-SQL is so bad your…. – Start here  Developers • Middle  DBA/Code Review  They should know the internals and performance reasoning and make suggestions. i.e. so why is SELECT * – End here  Developers
  4. 4. My DBA is so bad your…• Every role has an apple• DBA roles aren’t bad ones – Making relationships where it counts • Hardware Upgrades • Security Rights – VIEW SERVER STATE and VIEW DATABASE STATE • Work Together!
  5. 5. Monitor – Talk DBA to me• Active Monitoring – Blocking • Code practices resulting in blocking • Proactive tuning – Deadlocks • #1 reason for deadlocking – Poor performance of T-SQL – Timeouts • Unhappy – Oh how long is that query running? • Event Notifications • Extended Events • Blocked Process Reports
  6. 6. Tuning - #1 Most Effective AreaQuery Optimization Processor Parsing Algebrizer Optimizer Tree
  7. 7. How SELECT is read GROUP FROM JOIN WHERE HAVING SELECT SORTS BY
  8. 8. Execution Plans Scan / SeekOperations Join Sort Execution Plan Lookup Parallelism Convert
  9. 9. Start Tuning – High Cost Operations
  10. 10. Think “Result Set” not like a developer• Data is served not conditioned• Business Rules apply to the business layer not the data• Procedure <> Procedural• Row based operations are for high-level languages – Serve applications data – they do the work – Minimize the data being sent and received
  11. 11. Lookup – RID and Key – The other loop
  12. 12. Preventive T-SQL• Conversions – CONVERT_IMPLICIT• Tempdb – Sort and spills from memory• Sargable – Taking advantage of indexing in predicates
  13. 13. Abusive tempdb usage• Estimation of memory results in more needs• Statistics forcing poor Hash Joins• Sorting large amounts of data
  14. 14. Find pre-existing badness• Querying the Plan Cache – DMV and DMF • sys.dm_exec_cached_plans • sys.dm_exec_sql_text • sys.dm_exec_query_plan
  15. 15. Size Matters – Columns, Tables…Indexes • Column Length and Type • Duplicates • Overall Table Width • Overlapping • Page Count • Too Many • Overflow Page – All leading to transactional performance issues • DML suffers • UPDATE • DELETE • INSERT
  16. 16. Index Analysis – Repeat after me! • Duplicates • Overlapping • Too Many – All leading to transactional performance issues • DML suffers • UPDATE • DELETE • INSERT
  17. 17. ted@onpnt.comThank you! http://Twitter.com/onpntwww.magenic.com http://blogs.lessthandot.com

×