#sqlsatPordenone #sqlsat367 February 28 th, 2015 Executions Plans End-to-End in SQL Server Sergio

Slides:



Advertisements
Similar presentations
Youre Smarter than a Database Overcoming the optimizers bad cardinality estimates.
Advertisements

Understanding SQL Server Query Execution Plans
Introduction to SQL Tuning Brown Bag Three essential concepts.
Module 13: Performance Tuning. Overview Performance tuning methodologies Instance level Database level Application level Overview of tools and techniques.
Raghavendra Madala. Introduction Icicles Icicle Maintenance Icicle-Based Estimators Quality Guarantee Performance Evaluation Conclusion 2 ICICLES: Self-tuning.
1 What Are You Waiting For? A Performance Tuning Process Thomas LaRock Senior DBA, Confio Software.
Aaron Bertrand SQL Sentry, Senior Kevin Kline SQL Sentry, Dir of Engineering
Indexing HDFS Data in PDW: Splitting the data from index 1 Vinitha Gankidi #, Nikhil Teletia *, Jignesh M. Patel #, Alan Halverson *, David J. DeWitt *
Modern Performance - SQL Server Joe Chang yahoo.
Evaluating XML-Extended OLAP Queries Based on a Physical Algebra Xuepeng Yin and Torben B. Pedersen Department of Computer Science Aalborg University.
What Happens when a SQL statement is issued?
Anindya Datta Debra VanderMeer Krithi Ramamritham Presented by –
Modern Performance - SQL Server
Data Warehouse Tuning. 7 - Datawarehouse2 Datawarehouse Tuning Aggregate (strategic) targeting: –Aggregates flow up from a wide selection of data, and.
Jingren Zhou Microsoft Corp.. Large-scale Distributed Computing Large data centers (x1000 machines): storage and computation Key technology for search.
Ingres/Vectorwise Implementation Details XXV Ingres Benutzerkonferenz 2012 Confidential © 2011 Actian Corporation Doug Inkster 1 of 9.
Presentation: 20 minutes
Statistics That Need Special Attention Joe Chang yahoo
EXECUTION PLANS By Nimesh Shah, Amit Bhawnani. Outline  What is execution plan  How are execution plans created  How to get an execution plan  Graphical.
Sponsored by: Professional Association for SQL Server Bad plan! Sit! Gail Shaw.
1Key – Report Creation with DB2. DB2 Databases Create Domain for DB2 Test Demo.
Harikrishnan Karunakaran Sulabha Balan CSE  Introduction  Icicles  Icicle Maintenance  Icicle-Based Estimators  Quality & Performance  Conclusion.
Query Optimization Dr. Karen C. Davis Professor School of Electronic and Computing Systems School of Computing Sciences and Informatics.
Virtual techdays INDIA │ 9-11 February 2011 SQL 2008 Query Tuning Praveen Srivatsa │ Principal SME – StudyDesk91 │ Director, AsthraSoft Consulting │ Microsoft.
#sqlsatPordenone #sqlsat367 February 28, 2015 Testing your databases Alessandro
A Cost-based Approach For Converting Relational Schemas To XML Ramon Lawrence University of Iowa
School of Software SUN YAT-SEN UNIVERSITY Mar, 27, 2011.
Database Project Team 4 Group c v Menna Hamza Mohamad Hesham Mona Abdel Mageed Yasmine Shaker.
Denny Cherry Manager of Information Systems MVP, MCSA, MCDBA, MCTS, MCITP.
Maciej Pilecki Consultant, SQL Server MVP Project Botticelli Ltd. SESSION CODE: DAT403.
Cracking Execution Plans By Sarabpreet Singh Anand.
Developers of a suite of products to help you monitor and optimize Windows/SQL Server performance o Performance Advisor – awareness and control over Windows.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
SQL Dev Tips for Small Workstations How to develop SQL on small dev workstations when prod is huge. Kevin Kline and Aaron Bertrand SQL Sentry.
Multi-Way Hash Join Effectiveness M.Sc Thesis Michael Henderson Supervisor Dr. Ramon Lawrence 2.
Query Optimizer Execution Plan Cost Model Joe Chang
1 Chapter 8 Execution Plan Management. 2 Overview of Execution Plan Management Review techniques to – override optimizer – Improve optimizer’s decisions.
Dave LinkedIn
Scott Fallen Sales Engineer, SQL Sentry Blog: scottfallen.blogspot.com.
Execution Plans Detail From Zero to Hero İsmail Adar.
No more waiting. Sponsors About me  Database Technology Specialist  MVP  Blogger  Author 3
Session Name Pelin ATICI SQL Premier Field Engineer.
SQL Server Performance Tuning
Presented By: Jessica M. Moss
Execution Planning for Success
Parameter Sniffing in SQL Server Stored Procedures
Reading execution plans successfully
In the name of the resources
Please Support Our Sponsors
Reading Execution Plans Successfully
Query Execution Expectation-Reality Denis Reznik
The Ins and Outs of Indexes
The Ins and Outs of Indexes
In the name of the resources
The Ins and Outs of Indexes
Reading Execution Plans Successfully
The 5 Hidden Performance Gems
SQL Server Performance Tuning Nowadays
Some issues in databse-directory integration
Please Support our Sponsors
Introduction to Execution Plans
The Ins and Outs of Indexes
Performance Tuning for SQL Developers through Execution Plans
Performance Tuning for SQL Developers through Execution Plans
Performance Tuning for SQL Developers through Execution Plans
The Ins and Outs of Indexes
Performance Tuning for SQL Developers through Execution Plans
Performance Tuning for SQL Developers through Execution Plans
Performance Tuning for SQL Developers through Execution Plans
Presentation transcript:

#sqlsatPordenone #sqlsat367 February 28 th, 2015 Executions Plans End-to-End in SQL Server Sergio speakerscore.com/sqlsat367-Execution-Plans-End-to-End

#sqlsatPordenone #sqlsat367 February 28 th, 2015 Sponsors

#sqlsatPordenone #sqlsat367 February 28 th, 2015 Organizers

#sqlsatPordenone #sqlsat367 February 28 th, 2015 Speaker Server MVP sqlblog.com/blogs/sergio_govoni manning.com/delaney

#sqlsatPordenone #sqlsat367 February 28 th, 2015 Agenda  Execution Plan Fundamentals  The Optimization Process  How to influence Query Optimizer  How to force a particular Execution Plan  Plan Cache

#sqlsatPordenone #sqlsat367 February 28 th, 2015 Execution Plans - Fundamentals  Execution plan is generated by Query Optimizer  It helps us to answer the question: Why this query is slow?  It contains the instructions to execute a query  Table access order  Join operators  Indexes

#sqlsatPordenone #sqlsat367 February 28 th, 2015 Execution Plans - Fundamentals  Two types  Estimated Execution Plan  Actual Execution Plan  Three formats  Graphical Plans  Text Plans (deprecated)  XML Plans  Where you can find them?  SSMS, SQL Profiler, DMVs

#sqlsatPordenone #sqlsat367 February 28 th, 2015 Cost-based Plan > From David DeWitt keynote at PASS Summit - Select o_year, sum(case when nation = 'BRAZIL' then volume else 0 end) / sum(volume) from ( select YEAR(O_ORDERDATE) as o_year, L_EXTENDEDPRICE * (1 - L_DISCOUNT) as volume, n2.N_NAME as nation from PART, SUPPLIER, LINEITEM, ORDERS, CUSTOMER, NATION n1, NATION n2, REGION where P_PARTKEY = L_PARTKEY and S_SUPPKEY = L_SUPPKEY and L_ORDERKEY = O_ORDERKEY and O_CUSTKEY = C_CUSTKEY and C_NATIONKEY = n1.N_NATIONKEY and n1.N_REGIONKEY = R_REGIONKEY and R_NAME = 'AMERICA‘ and S_NATIONKEY = n2.N_NATIONKEY and O_ORDERDATE between ' ' and ' ' and P_TYPE = 'ECONOMY ANODIZED STEEL' and S_ACCTBAL <= constant-1 and L_EXTENDEDPRICE <= constant-2 ) as all_nations group by o_year order by o_year

#sqlsatPordenone #sqlsat367 February 28 th, 2015 Heap table (no clustered index) IAM index_id = 0 first_iam_page Data rows

#sqlsatPordenone #sqlsat367 February 28 th, 2015 Clustered index Prev | Next Index rows index_id = 1 root_page Prev | Next Data rows Prev | Next Index rows Prev | Next Data rows Prev | Next Data rows Prev | Next Data rows

#sqlsatPordenone #sqlsat367 February 28 th, 2015 Non-Clustered Index Prev | Next Index rows index_id > 1 root_page Prev | Next RIDs or CI Keys, Included cols Prev | Next Index rows Prev | Next … Prev | Next … Prev | Next …

#sqlsatPordenone #sqlsat367 February 28 th, 2015 The optimization process  Parsing and Binding  Logical tree  Simplification  Trivial Plan  Full optimization  Search 0 (TP)  Search 1 (QP)  Search 2 (FULL) No data dependences No access to statistics No cost-based plan Using statistics Cost-based plan Each phase can return the execution plan

#sqlsatPordenone #sqlsat367 February 28 th, 2015 The optimization process  Information about the optimization process  sys.dm_exec_query_optimizer_info sys.dm_exec_query_optimizer_info  Information on the use of transformation rules  sys.dm_exec_query_transformation_stats sys.dm_exec_query_transformation_stats  Cumulative values since the SQL Server Instance restart

#sqlsatPordenone #sqlsat367 February 28 th, 2015 DEMO The optimization process

#sqlsatPordenone #sqlsat367 February 28 th, 2015 How to influence the Query Optimizer  Special directives called Hints are able to influence the choices of the Query Optimizer  Advanced troubleshooting  They can not be used to generate an invalid execution plan  Not completely documented  Restrict the search space of the Query Optimizer is dangerous!  Do not use it massively

#sqlsatPordenone #sqlsat367 February 28 th, 2015 Hints  Query Hints  The most numerous and prominent  They have affect on the entire query  Join Hints  They require the use of a particular join operator  Table Hints  They allow you to control the table access methods

#sqlsatPordenone #sqlsat367 February 28 th, 2015 Trace Flags  Trace Flags are special directives used for:  Enable a specific feature  Disable a particular behavior  Scope: Global, Session, Query  Not completely documented  DBCC TRACE* DBCC TRACE*  QUERYTRACEON QUERYTRACEON

#sqlsatPordenone #sqlsat367 February 28 th, 2015 Before using Hints and Trace Flags (QO)  Has the Query Optimizer all the necessary information to produce a good execution plan?  Are the queries deterministic?  Are the tables indexed?  Are the statistics accurate?  Are the system resources appropriate?  I/O sub-system, CUP, RAM

#sqlsatPordenone #sqlsat367 February 28 th, 2015 DEMO How to influence the Query Optimizer

#sqlsatPordenone #sqlsat367 February 28 th, 2015 How to force a particular Execution Plan  You can force the Query Optimizer to use a specific Execution Plan (for a query) with  USE PLAN query hint  Plan Giude  sp_create_plan_guide sp_create_plan_guide  sp_create_plan_guide_from_handle sp_create_plan_guide_from_handle  sp_control_plan_guide sp_control_plan_guide  Wizard on SSMS  sys.plan_guides sys.plan_guides

#sqlsatPordenone #sqlsat367 February 28 th, 2015 How to force a particular Execution Plan - Limitations!  You can not force the Query Optimizer to use a specific Execution Plan for  DML statements (INSERT, UPDATE, DELETE)  Queries that use dynamic cursors  Distributed queries and Full Text queries  Plans that are non considered during the optimization process

#sqlsatPordenone #sqlsat367 February 28 th, 2015 DEMO How to force a particular Execution Plan

#sqlsatPordenone #sqlsat367 February 28 th, 2015 Plan Cache  SQL Server stores Execution Plans in Buffer Pool zone that is known as Plan Cache  Each Execution Plan (in cache) is divided in  Query Plan  Read only  No information about the user context  Two copies (one for parallel plan)  Execution Context  Stores information about the user context

#sqlsatPordenone #sqlsat367 February 28 th, 2015 Plan Cache  DMVs that showing cached plans  sys.dm_exec_cached_plans sys.dm_exec_cached_plans  sys.dm_exec_plan_attributes sys.dm_exec_plan_attributes  sys.dm_exec_query_plan sys.dm_exec_query_plan

#sqlsatPordenone #sqlsat367 February 28 th, 2015 sys.dm_exec_cached_plans  Six types of cached plans (cacheobjtype)  Compiled Plan, Compiled Plan Stub  Parse Tree, Extended Proc, CLR Proc, CLR Function  Three types (objtype) of Compiled Plan  Adhoc, Prepared, Proc  Look at usercounts to know if cached plan is reused or not  plan_handle

#sqlsatPordenone #sqlsat367 February 28 th, 2015 Optimize for Ad-hoc Workloads  Available since SQL Server 2008  Server level option  Adhoc Query Plans are not cached on the first use  Better Memory Management  One more recompilation is necessary  sys.dm_exec_cached_plans  cacheobjtype «Compiled Plan Stub»  objtype «Adhoc»

#sqlsatPordenone #sqlsat367 February 28 th, 2015 Parameterized Plans  Obytype shown as “Prepared”  Auto-parameterization  SIMPLE by default applied to small class of queries  FORCED allows to parametrize more queries  Explicit parameterization with  Prepare/Execute through the application  sp_executesql

#sqlsatPordenone #sqlsat367 February 28 th, 2015 DEMO Plan Cache

#sqlsatPordenone #sqlsat367 February 28 th, 2015 Tools  SQL Sentry Plan Explorer   x86, x64, Free & PRO Versions  Add-in for SQL Server Management Studio

#sqlsatPordenone #sqlsat367 February 28 th, 2015 Resources  SQL Server Execution Plans (2 nd Edition) – Grant Fritchey   Inside the SQL Server Query Optimizer – Benjamin Nevarez 

#sqlsatPordenone #sqlsat367 February 28 th, 2015 Q&A  Questions?

#sqlsatPordenone #sqlsat367 February 28 th, 2015 THANKS! Thanks for attending this session. If you have additional questions, please post them on UGISS forum at #sqlsatPordenone Feedback form: