Dive into the Query Optimizer Dive into the Query Optimizer: Undocumented Insight Benjamin Nevarez Blog: benjaminnevarez.com

Slides:



Advertisements
Similar presentations
Query Optimizer Overview
Advertisements

CS CS4432: Database Systems II Logical Plan Rewriting.
The Volcano/Cascades Query Optimization Framework
EXECUTION PLANS By Nimesh Shah, Amit Bhawnani. Outline  What is execution plan  How are execution plans created  How to get an execution plan  Graphical.
Understanding Parameter Sniffing Benjamin Nevarez Blog: benjaminnevarez.com 1.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Query Optimization Chapters 14.
Query Optimization Goal: Declarative SQL query
Outline SQL Server Optimizer  Enumeration architecture  Search space: flexibility/extensibility  Cost and statistics Automatic Physical Tuning  Database.
Query Compiler. The Query Compiler Parses SQL query into parse tree Transforms parse tree into expression tree (logical query plan) Transforms logical.
Query Execution Optimizing Performance. Resolving an SQL query Since our SQL queries are very high level, the query processor must do a lot of additional.
COMP 451/651 Optimizing Performance
Chapter 14 An Overview of Query Optimization. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Figure 14.1 Typical architecture for.
CS263 Lecture 19 Query Optimisation.  Motivation for Query Optimisation  Phases of Query Processing  Query Trees  RA Transformation Rules  Heuristic.
CMSC724: Database Management Systems Instructor: Amol Deshpande
ICS (072)Query Processing and Optimization 1 Chapter 15 Algorithms for Query Processing and Optimization ICS 424 Advanced Database Systems Dr.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Query Optimization. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Physical Design.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Query Optimization Chapter 15.
Query Optimization Overview Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems December 2, 2004 Some slide content derived.
Chapter 19 Query Processing and Optimization
T HE Q UERY C OMPILER Prepared by : Ankit Patel (226)
CPS216: Advanced Database Systems Notes 03:Query Processing (Overview, contd.) Shivnath Babu.
Query Processing Presented by Aung S. Win.
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
Learningcomputer.com SQL Server 2008 – Entity Relationships in a Database.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
Database systems/COMP4910/Melikyan1 Relational Query Optimization How are SQL queries are translated into relational algebra? How does the optimizer estimates.
Database Management 9. course. Execution of queries.
Query optimization in relational DBs Leveraging the mathematical formal underpinnings of the relational model.
Module 9 Designing and Implementing Stored Procedures.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
RELATIONAL FAULT TOLERANT INTERFACE TO HETEROGENEOUS DISTRIBUTED DATABASES Prof. Osama Abulnaja Afraa Khalifah
Module 5 Planning for SQL Server® 2008 R2 Indexing.
Query Processing. Steps in Query Processing Validate and translate the query –Good syntax. –All referenced relations exist. –Translate the SQL to relational.
The Volcano Query Optimization Framework S. Sudarshan (based on description in Prasan Roy’s thesis Chapter 2)
1 Execution Strategies for SQL Subqueries Mostafa Elhemali, César Galindo- Legaria, Torsten Grabs, Milind Joshi Microsoft Corp With additional slides from.
Massive Stochastic Testing of SQL Don Slutz Microsoft Research Presented By Manan Shah.
Improving Database Performance Derrick Rapley
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
Query Processing Bayu Adhi Tama, MTI. 1 ownerNoclient © Pearson Education Limited 1995, 2005.
Copyright © Curt Hill Joins Revisited What is there beyond Natural Joins?
Chapter 18 Query Processing. 2 Chapter - Objectives u Objectives of query processing and optimization. u Static versus dynamic query optimization. u How.
SQL/Lesson 7/Slide 1 of 32 Implementing Indexes Objectives In this lesson, you will learn to: * Create a clustered index * Create a nonclustered index.
Query Processing – Query Trees. Evaluation of SQL Conceptual order of evaluation – Cartesian product of all tables in from clause – Rows not satisfying.
1 Execution Strategies for SQL Subqueries Mostafa Elhemali, César Galindo- Legaria, Torsten Grabs, Milind Joshi Microsoft Corp.
Query Optimization CMPE 226 Database Systems By, Arjun Gangisetty
Query Processing – Implementing Set Operations and Joins Chap. 19.
Lecture 15: Query Optimization. Very Big Picture Usually, there are many possible query execution plans. The optimizer is trying to chose a good one.
Thinking in Sets and SQL Query Logical Processing.
Chapter 18 Query Processing and Optimization. Chapter Outline u Introduction. u Using Heuristics in Query Optimization –Query Trees and Query Graphs –Transformation.
Chapter 13: Query Processing
Dave LinkedIn
Inside Query Processor Sort Dmitry Pilugin SQL Server Developer, MVP (RU) (EN)
SQL Server Deep Dive Denis Reznik Data Architect at Intapp.
Scott Fallen Sales Engineer, SQL Sentry Blog: scottfallen.blogspot.com.
Execution Plans Detail From Zero to Hero İsmail Adar.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
Query Optimizer Overview
Database Performance Tuning &
Prepared by : Ankit Patel (226)
Parameter Sniffing in SQL Server Stored Procedures
CS222P: Principles of Data Management Lecture #15 Query Optimization (System-R) Instructor: Chen Li.
Chapter 15 QUERY EXECUTION.
Physical Join Operators
SQL Fundamentals in Three Hours
EXECUTION PLANS Quick Dive.
Diving into Query Execution Plans
Query Optimization.
CS222: Principles of Data Management Lecture #15 Query Optimization (System-R) Instructor: Chen Li.
Presentation transcript:

Dive into the Query Optimizer Dive into the Query Optimizer: Undocumented Insight Benjamin Nevarez Blog: benjaminnevarez.com

About the Speaker Benjamin Nevarez Author of “Inside the SQL Server Query Optimizer” and “SQL Server 2014 Query Tuning & Optimization” SQL Server 2012 Internals Working with SQL Server for 15 years PASS Summit/SQL Server Connections speaker

Dive into the Query Optimizer SQL is a high-level declarative language

Dive into the Query Optimizer Query processing steps

Dive into the Query Optimizer The Optimization Process Parsing / Binding (before optimization) Simplification Initial set of Join Orders Trivial Plan Optimization Phases search 0 search 1 search 2

Parsing / Binding Parsing first makes sure that the T-SQL query has a valid syntax Binding is mostly concerned with name resolution Uses the query information to build a tree of relational operators

Demo Logical Trees

Simplification Reduces the query tree into a simpler form in order to make the optimization process easier Some of the simplifications include: Redundant inner and outer joins may be removed. A typical example is the Foreign Key Join elimination Filters in WHERE clauses are pushed down in the query tree in order to enable early data filtering (predicate pushdown) Contradictions are detected and remove

Demo Simplification

Transformation Rules Used to explore the search space Exploration rules (logical transformation rules) Generate logical equivalent alternatives Commutativity A join B – > B join A Associativity (A join B) join C – > A join (B join C) Implementation rules (physical transformation rules) Obtain physical alternatives Join to Sort Merge Join A join B – > A Merge Join B

Transformation Rules Applying transformations does not necessarily reduce the cost of the generated alternatives Cost will be estimated later (only physical alternatives are costed)

Demo Transformation Rules

The Memo Search data structure that is used to store the alternatives which are generated and analyzed by the Query Optimizer A new memo structure is created for each optimization The Query Optimizer copies the original query tree's logical expressions into the memo structure

The Memo After Optimization

Demo The Memo

Optimization Phases – Full Optimization Search 0, Transaction Processing phase Search 1, Quick Plan phase Search 2, Full Optimization

Demo The Optimization Phases

Dive into the Query Optimizer Thank You!