Upload
code-mastery
View
547
Download
0
Tags:
Embed Size (px)
DESCRIPTION
Presentation for Code Mastery-Chicago. Ted Krueger, Associate Principal Consultant, Microsoft MVP
Citation preview
Query Tuning for Database Pros & Developers
Ted Krueger
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
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
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!
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
Tuning - #1 Most Effective Area Query Optimization
Parsing Algebrizer Processor
Tree Optimizer
FROM JOIN WHERE GROUP
BY HAVING SELECT SORTS
How SELECT is read
Execution Plans Operations
Execution
Plan
Scan / Seek
Sort
Parallelism
Convert
Lookup
Join
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 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
Lookup – RID and Key – The other loop
Preventive T-SQL • Conversions – CONVERT_IMPLICIT
• Tempdb – Sort and spills from memory
• Sargable – Taking advantage of indexing in predicates
Abusive tempdb usage • Estimation of memory results in more needs
• Statistics forcing poor Hash Joins
• Sorting large amounts of data
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
Size Matters – Columns, Tables…Indexes • Duplicates
• Overlapping
• Too Many
– All leading to transactional
performance issues • DML suffers
• UPDATE
• DELETE
• INSERT
• Column Length and Type
• Overall Table Width
• Page Count
• Overflow Page
Index Analysis – Repeat after me! • Duplicates
• Overlapping
• Too Many
– All leading to transactional
performance issues • DML suffers
• UPDATE
• DELETE
• INSERT
Thank you! www.magenic.com
http://Twitter.com/onpnt
http://blogs.lessthandot.com