Comprehensive Performance with Automated Execution Plan Analysis (ExecStats) Joe Chang yahoo

Slides:



Advertisements
Similar presentations
Tuning: overview Rewrite SQL (Leccotech)Leccotech Create Index Redefine Main memory structures (SGA in Oracle) Change the Block Size Materialized Views,
Advertisements

Copyright © SoftTree Technologies, Inc. DB Tuning Expert.
Chapter 9. Performance Management Enterprise wide endeavor Research and ascertain all performance problems – not just DBMS Five factors influence DB performance.
Module 13: Performance Tuning. Overview Performance tuning methodologies Instance level Database level Application level Overview of tools and techniques.
SQL Server performance tuning basics
Statistics That Need Special Attention Joe Chang yahoo
SQL Performance 2011/12 Joe Chang, SolidQ
Module 17 Tracing Access to SQL Server 2008 R2. Module Overview Capturing Activity using SQL Server Profiler Improving Performance with the Database Engine.
Automating Performance … Joe Chang SolidQ
10 Things Not To Do With SQL SQLBits 7. Some things you shouldn’t do.
Comprehensive Indexing via Automated Execution Plan Analysis (ExecStats) Joe Chang yahoo Slide deck here.
Virtual techdays INDIA │ 9-11 February 2011 SQL 2008 Query Tuning Praveen Srivatsa │ Principal SME – StudyDesk91 │ Director, AsthraSoft Consulting │ Microsoft.
Indexes Rose-Hulman Institute of Technology Curt Clifton.
The Essentials: DMV’s and T-SQL for the DBA Rocky Mountain Tech Tri-Fecta.
SQL Server Query Optimizer Cost Formulas Joe Chang
Parallel Execution Plans Joe Chang
IT The Relational DBMS Section 06. Relational Database Theory Physical Database Design.
Comprehensive Indexing via Automated Execution Plan Analysis (ExecStats) Joe Chang yahoo Slide deck here.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
Ideas to Improve SharePoint Usage 4. What are these 4 Ideas? 1. 7 Steps to check SharePoint Health 2. Avoid common Deployment Mistakes 3. Analyze SharePoint.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
Oracle9i Performance Tuning Chapter 1 Performance Tuning Overview.
Insert, Update & Delete Performance Joe Chang
IT 456 Seminar 5 Dr Jeffrey A Robinson. Overview of Course Week 1 – Introduction Week 2 – Installation of SQL and management Tools Week 3 - Creating and.
ISV Innovation Presented by ISV Innovation Presented by Business Intelligence Fundamentals: Data Cleansing Ola Ekdahl IT Mentors 9/12/08.
Siebel 8.0 Module 5: EIM Processing Integrating Siebel Applications.
Parallel Execution Plans Joe Chang
Large Data Operations Joe Chang
Parallel Execution Plans Joe Chang
By Shanna Epstein IS 257 September 16, Cnet.com Provides information, tools, and advice to help customers decide what to buy and how to get the.
TPC-H Studies Joe Chang
Microsoft AREC TAM Internship SQL Server Performance Tuning(I) Haijun Yang AREC SQL Support Team Feb, SQL Server 2000.
Query Optimizer Execution Plan Cost Model Joe Chang
Enterprise Database Administration & Deployment SIG ▪ 313M ▪ Sept 29, 2005 ▪ 10:15 AM SQL Server 2005 Performance Diagnosis and Tuning using SQL Tools.
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
Connect with life Nauzad Kapadia Quartz Systems
Session 1 Module 1: Introduction to Data Integrity
IMS 4212: Database Implementation 1 Dr. Lawrence West, Management Dept., University of Central Florida Physical Database Implementation—Topics.
SQL Server - Review Managing the System. Objectives  Understand the importance of maintenance plans.  Check for database consistency.  Understand how.
Dave LinkedIn
How to kill SQL Server Performance Håkan Winther.
SQL Server Statistics DEMO SQL Server Statistics SREENI JULAKANTI,MCTS.MCITP,MCP. SQL SERVER Database Administration.
Scott Fallen Sales Engineer, SQL Sentry Blog: scottfallen.blogspot.com.
Troubleshooting Dennis Shasha and Philippe Bonnet, 2013.
Why Should I Care About … The Plan Cache? Tuning When Stakeholders Won’t Say Where It Hurts.
Module 6: Creating and Maintaining Indexes. Overview Creating Indexes Understanding Index Creation Options Maintaining Indexes Introducing Statistics.
SQL Server Statistics DEMO SQL Server Statistics SREENI JULAKANTI,MCTS.MCITP SQL SERVER Database Administration.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
Improve query performance with the new SQL Server 2016 query store!! Michelle Gutzait Principal Consultant at
Session Name Pelin ATICI SQL Premier Field Engineer.
11 Copyright © 2009, Oracle. All rights reserved. Enhancing ETL Performance.
SQL Server Statistics and its relationship with Query Optimizer
Query Optimization Techniques
Joe Chang yahoo . com qdpma.com
Database Performance Tuning and Query Optimization
Introduction to Execution Plans
Cardinality Estimator 2014/2016
Statistics What are the chances
Query Optimization Techniques
JULIE McLAIN-HARPER LINKEDIN: JM HARPER
SQL Server 2016 Query Data Store
Statistics: What are they and How do I use them
Joe Chang yahoo Comprehensive Indexing via Automated Execution Plan Analysis (ExecStats) Joe Chang yahoo
SQL Server Query Optimizer Cost Formulas
Introduction to Execution Plans
Chapter 11 Database Performance Tuning and Query Optimization
Diving into Query Execution Plans
Introduction to Execution Plans
Query Optimization Techniques
Introduction to Execution Plans
Presentation transcript:

Comprehensive Performance with Automated Execution Plan Analysis (ExecStats) Joe Chang yahoo

About Joe SQL Server consultant since 1999 Query Optimizer execution plan cost formulas (2002) True cost structure of SQL plan operations (2003?) Database with distribution statistics only, – no data 2004 Decoding statblob-stats_stream – writing your own statistics Disk IO cost structure Tools for system monitoring, execution plan analysis See ExecStats Download: Blog:

Objectives Complexities & depth SQL performance – Cause and Effect Focus on the execution plan – Inefficient plans – missing indexes – very large estimate/actual row discrepancies Comprehensive Index Strategy – few good indexes, but no more than necessary

Non-Objective List of rules to be followed blindly without consideration for the underlying reason and whether rule actually applies in the current circumstance DBA skill: cause and effect analysis & assessment

Preliminary: Correct Results Normalization – Data stored once, avoid anomalies Unique Keys – Avoid duplicate rows Foreign Keys – Avoid orphaned rows Incorrect architecture requires use of SELECT DISTINCT etc. to correct architecture deficiencies Which may cause performance problems as well Correct action is to address the architecture mistakes before the performance issue.

Performance Factors Natural keys with unique indexes, not SQL The Execution Plan links all the elements of performance Index tuning alone has limited value Over indexing can cause problems as well Index and Statistics maintenance policy 1 Logic may need more than one execution plan? Compile cost versus execution cost? Tables and SQL combined implement business logic Plan cache bloat? SQL Tables natural keys Indexes Execution Plan Statistics & Compile parameters Compile Row estimate propagation errors Storage Engine Hardware DOP Memory Parallel plans Recompile temp table / table variable Query Optimizer

Performance Strategy Tables – support business logic – Normalization, uniqueness etc. SQL – clear SARG, Query optimizer interpretable – 1 Logic maps to X Execution plans Indexes – good cluster key choice – Good nonclustered indexes, no more than necessary Statistics – sample strategy & update frequency Compile parameter strategy Temp table / Table variable strategy: Recompile & Row est. prop. error Parallel execution plans: DOP and CTOP strategy

Indexing Principles Good cluster key choice – Grouping + unique, not too wide Good nonclustered indexes – For key queries, not necessarily every query – Covered indexes were practical (update overhead) – Create and drop custom indexes for maintenance ops No more indexes than necessary – Update overhead – Compile overhead – May tolerate occasional scans to avoid update maintenance Note emphasis on good, not perfect

Comprehensive Strategy Identify (weight) important SQL statements – stored procedure: parameter values & code path Recompile impact for temp tables Execution plan cross references SQL & indexes – Actual plan is better than estimate plan – Compile parameters & skewed statistics Temp tables - Recompile impact Automate Execution Plan analysis to fully cross-reference SQL to index usage

Using DMVs – Execution Plan dm_exec_query_stats dm_exec_sql_text dm_exec_query_plan dm_exec_text_query_plan dm_db_index_usage_stats dm_db_index_operational_stats dm_db_index_physical_stats DBCC SHOW_STATISTICS STATS_DATE (object_id, stats_id) dm_db_stats_properties Execution Plan Indexes, joins Compile parameters System views Indexes, key columns, Include list, filter, XML, Columns store etc. sys.dm_db_stats_properties, is available in SQL Server 2012 starting with Service Pack 1 and in SQL Server 2008 R2 starting with Service Pack 2. last_updated, rows, rows_sampled, steps, unfiltered_rows, modification_counter dm_exec_query_profiles 2014 Real time query progress?

Using DMVs – Execution Plan dm_exec_query_stats dm_exec_sql_text dm_exec_query_plan dm_exec_text_query_plan dm_db_index_usage_stats dm_db_index_operational_stats dm_db_index_physical_stats DBCC SHOW_STATISTICS STATS_DATE (object_id, stats_id) dm_db_stats_properties Execution Plan Indexes, joins Compile parameters System views Indexes, key columns, Include list, filter, XML, Columns store etc. sys.dm_db_stats_properties, is available in SQL Server 2012 starting with Service Pack 1 and in SQL Server 2008 R2 starting with Service Pack 2. last_updated, rows, rows_sampled, steps, unfiltered_rows, modification_counter dm_exec_query_profiles 2014 Real time query progress?

SQL & Execution Plan Sources Estimated Execution Plan – dm_exec_query_stats Contents of plan cache + execution statistics – List of stored procedures SELECT name FROM sys.procedures Any SQL list – Plans not in cache, to be generated – Can also execute SQL for actual plans

sys.dm_exec_query_stats sql_handle – token for batch or stored procedure statement_start_offset – sql_handle + offset = SQL statement plan_handle – SQL (batch) can have multiple plans on recompile query_hash – identify queries with similar logic, – differing only by literal values

sys.procedures Get list of stored procedures in database – functions are called from procedure? Generate estimated execution plan for each – Default parameters Full map of index usage to stored procedure No trigger details in estimated plan

SQL List Configuration file has SQL to retrieve SQL list – Can be explicit SQL or stored procedures with parameters – Same procedure, multiple parameter set To expose different code path (actual plan) EXEC proc RECOMPILE (estimated plan)

About ExecStats General information Execution plan sources 1.dm_exec_query_stats 2.list of all stored procedures (estimated) 3.List of SQL in table (estimated or actual plan) 4.Trace file Correlates execution plans to index usage Procedures, functions and triggers Rollup file IO stats by DB, filegroup, disk/vol, data/log Distribution Statistics Output to Excel, sqlplan file, (sql in txt file)

ExecStats Output Files Txt – runtime info Log – abbreviated SQL error logs Excel – Missing Indexes DMV SQL plan directory This can be sent to someone who can identify and fix your problem

Important Items Query cost – plan efficiency? Recompiles? – Compile parameters – skewed statistics CPU versus Duration (worker – elapsed time) – Disk IO, network transmission, parallel plan? Execution count – network roundtrip? Plan cost – Parallelism – High volume of quick queries is bad, so is excessive DOP Index – current rows, rows at time stats generated, sample rows & date

Execution Plans Estimated Actual: estimated cost, actual rows, DOP – Executed stored procedure once for each possible code path – with appropriate parameters

Execution Plans Pay attention to: – Compile parameters – Large table scans: how many rows output? – Predicate search condition without suitable index – Rebinds and Rewinds – key lookup – Parallelism

Index Usage – missing IX, excess IX? Index usage – seek, scan, lookup & update – Unused indexes (infrequent code?) can be dropped – Infrequent usage: check plan references – Similar indexes (leading keys) Same keys, different order Check plan reference – consolidate if possible Scans to large tables or even nonclustered IX – Is it real (SELECT TOP 1 may not be a real scan) Lookups – can these be reduced?

SQL Server Skills & Roles Developers SQL code Architect Table structure, unique keys Data Architect normalization DBA Index + Statistics Maintenance Hardware & Storage Performance.

SQL Server Performance History Before DMVs (SQL Server 2000) – Profiler/Trace to get top SQL – Execution plans – not really exportable – Which indexes are actually used? Today – Trace/Extended Events sometimes not necessary If the dm_exec_query_stats content is good – Execution plans are exportable – Index Usage Stats

How much can be automated? Data collectionall, of course – Top resource consumers, etc. Assessment sometimes – Is there a problem – Can it be fixed or improved Fix/Changesometimes – Indexes – SQL – sometimes – Table structure, architectureno If problems could be solved by pushing a button, what would be the skill requirements to be a DBA? Great accomplishments – 99% perspiration 1% inspiration

Performance Approaches Check against list of “Best Practices” Manual DMV scripts approach – Find Top 5 or 10 SQL – Fix it if/when there is a problem All Indexes and procedures/SQL – Examine the complete set of stored procedures – Or the full list of SQL statements – Good indexes for all SQL, no more indexes than

Why bother when there are no problems? No problems for over 1 year – Never bothered to collect performance baseline Problem Today – Find it with DMV, fix it – the problem was xxx – but why did it occur today & not before? Probably statistics or compile parameters, but prove it? Why ExecStats – SQL scripts? – too much manual work – Third party tools? – only find problem

Rigorous Optimization Table structure, SQL, Client-side Cluster Key Good (nonclustered) Indexes – All indexes are actually used No more indexes than necessary – Consolidate similar indexes same keys, same order, or reverse order? – What SQL is impacted? Statistics update Index maintenance Must consider the full set of SQL/procedures in removing indexes?

SQL versus programming languages SQL – great for data access – Not good for everything else – When SQL becomes horribly complicated – What would the code looks like in VB/Java/Cxx Client-side program C#

Performance Information Server, Storage OS & SQL Server Settings SQL Server – SQL, query execution statistics, execution plan – Compile parameters – Indexes and index usage statistics – Statistics sampling – when? percentage? skew?