Query Processing CSD305 Advanced Databases.

Slides:



Advertisements
Similar presentations
Understanding SQL Server Query Execution Plans
Advertisements

Module 13: Performance Tuning. Overview Performance tuning methodologies Instance level Database level Application level Overview of tools and techniques.
EXECUTION PLANS By Nimesh Shah, Amit Bhawnani. Outline  What is execution plan  How are execution plans created  How to get an execution plan  Graphical.
Advanced Databases: Lecture 2 Query Optimization (I) 1 Query Optimization (introduction to query processing) Advanced Databases By Dr. Akhtar Ali.
Query Evaluation. An SQL query and its RA equiv. Employees (sin INT, ename VARCHAR(20), rating INT, age REAL) Maintenances (sin INT, planeId INT, day.
CS263 Lecture 19 Query Optimisation.  Motivation for Query Optimisation  Phases of Query Processing  Query Trees  RA Transformation Rules  Heuristic.
Query Optimization. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Physical Design.
Query Processing Presented by Aung S. Win.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
DBSQL 14-1 Copyright © Genetic Computer School 2009 Chapter 14 Microsoft SQL Server.
Module 12: Optimizing Query Performance. Overview Introducing the Query Optimizer Tuning Performance Using SQL Utilities Using an Index to Cover a Query.
Advanced Databases: Lecture 8 Query Optimization (III) 1 Query Optimization Advanced Databases By Dr. Akhtar Ali.
Database Management 9. course. Execution of queries.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
RELATIONAL FAULT TOLERANT INTERFACE TO HETEROGENEOUS DISTRIBUTED DATABASES Prof. Osama Abulnaja Afraa Khalifah
Copyright © 2004 Pearson Education, Inc.. Chapter 15 Algorithms for Query Processing and Optimization.
Academic Year 2014 Spring. MODULE CC3005NI: Advanced Database Systems “QUERY OPTIMIZATION” Academic Year 2014 Spring.
Advanced Databases: Lecture 6 Query Optimization (I) 1 Introduction to query processing + Implementing Relational Algebra Advanced Databases By Dr. Akhtar.
Switch off your Mobiles Phones or Change Profile to Silent Mode.
Microsoft AREC TAM Internship SQL Server Performance Tuning(I) Haijun Yang AREC SQL Support Team Feb, SQL Server 2000.
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 RELATIONAL DATABASE KUSUMA AYU LAKSITOWENING
Query Processing – Query Trees. Evaluation of SQL Conceptual order of evaluation – Cartesian product of all tables in from clause – Rows not satisfying.
Session 1 Module 1: Introduction to Data Integrity
Lecture 15: Query Optimization. Very Big Picture Usually, there are many possible query execution plans. The optimizer is trying to chose a good one.
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
Scott Fallen Sales Engineer, SQL Sentry Blog: scottfallen.blogspot.com.
Database Applications (15-415) DBMS Internals- Part IX Lecture 20, March 31, 2016 Mohammad Hammoud.
Data Integrity & Indexes / Session 1/ 1 of 37 Session 1 Module 1: Introduction to Data Integrity Module 2: Introduction to Indexes.
SQL IMPLEMENTATION & ADMINISTRATION Indexing & Views.
CHAPTER 19 Query Optimization. CHAPTER 19 Query Optimization.
Query Processing and Optimization, and Database Tuning
Query Optimization Heuristic Optimization
Database System Implementation CSE 507
15.1 – Introduction to physical-Query-plan operators
Record Storage, File Organization, and Indexes
Database Management System
Database Performance Tuning &
Prepared by : Ankit Patel (226)
Chapter 12: Query Processing
Database Performance Tuning and Query Optimization
Introduction to Query Optimization
Relational Algebra Chapter 4, Part A
Overview of Query Optimization
Chapter 15 QUERY EXECUTION.
Query Execution Presented by Khadke, Suvarna CS 257
Examples of Physical Query Plan Alternatives
Database management concepts
External Sorting The slides for this text are organized into chapters. This lecture covers Chapter 11. Chapter 1: Introduction to Database Systems Chapter.
JULIE McLAIN-HARPER LINKEDIN: JM HARPER
Cse 344 APRIL 23RD – Indexing.
Execution Plans Demystified
Selected Topics: External Sorting, Join Algorithms, …
Relational Algebra Chapter 4, Sections 4.1 – 4.2
Database Applications (15-415) DBMS Internals- Part IX Lecture 21, April 1, 2018 Mohammad Hammoud.
SQL Server Query Plans Journeyman and Beyond
Highlights of Query Processing And Optimization
Query Optimization CS 157B Ch. 14 Mien Siao.
Database management concepts
Chapter 11 Database Performance Tuning and Query Optimization
CS222P: Principles of Data Management Notes #13 Set operations, Aggregation, Query Plans Instructor: Chen Li.
Evaluation of Relational Operations: Other Techniques
Diving into Query Execution Plans
Distributed Databases
Query Optimization.
Query Processing.
Completing the Physical-Query-Plan and Chapter 16 Summary ( )
Course Instructor: Supriya Gupta Asstt. Prof
Unit 12 Index in Database 大量資料存取方法之研究 Approaches to Access/Store Large Data 楊維邦 博士 國立東華大學 資訊管理系教授.
Presentation transcript:

Query Processing CSD305 Advanced Databases

Agenda Query Processing Fundamentals QP vs. RA QP in MS SQL Server Rule-based optimization Cost-based optimization Statistical query optimization Query Plans Search Conditions Access Methods Join Methods Query tuning CSD305 Advanced Databases

Fundamentals of Query Processing A SQL statement is semantically rather similar to a specification in Relational Calculus and can be translated into an expression in Relational Algebra SELECT title FROM Loan JOIN Book ON bookNo JOIN Member ON memberNo WHERE memberNo = 4128 can be expressed as p title((rmember#=4128 Loan) Book) Member ) CSD305 Advanced Databases

Relational algebra reminder p title((rmember#=4128 Loan) Book) Member ) CSD305 Advanced Databases

Notes on the algebra Note that the expression can be represented as a tree With each leaf representing a base table And each node representing an RA operation Each RA operation can be binary or unary And the result being a single relation CSD305 Advanced Databases

Does this look at all familiar? CSD305 Advanced Databases This picture shows a Query Plan from SQL Server

QP vs. RA As we have seen Query Plans are rather similar to Relational Algebra They take the form of binary trees They produce intermediate results (relations) on the way to producing the answer But They are concerned with physical structures as well as logical structures The operations are physical implementations of RA expressions e.g. there are several ways to do a JOIN CSD305 Advanced Databases

SQL Server QP Basics SQL requests are sent to the DBMS The DBMS parses the SQL accesses metadata prepares query plan(s) chooses the cheapest plan executes the chosen plan Results in the form of a table are returned to the client CSD305 Advanced Databases

QP Schematic CSD305 Advanced Databases

Inside the DBMS CSD305 Advanced Databases

What do the QP components do? Within the SQL Processor The Query Parser Ensures that the SQL is well-formed and is consistent with the schema The Query Optimizer Generates plans for carrying out the query and chooses the best Saves plans in the cache The Query Executor Picks plans from the cache Carries out the chosen plan Returns results to the client CSD305 Advanced Databases

What do the QP components do? Within the Storage Manager The Page Manager Processes the request for data at a logical level (the database page) The I/O Manager Processes the request at a physical level (disk input/output) CSD305 Advanced Databases

Query Optimization There are three basic techniques of query optimization Rule-based In which rules are applied to generate a Query Plan Cost-based In which the costs of various Query Plans are estimated and compared Statistical In which the optimizer makes use of statistics about data distribution to improve Query Plans Microsoft SQL Server uses a combination of all three to select a QP CSD305 Advanced Databases

Rule-based Query Optimization A sequence of heuristics (rules of thumb) is applied to construct a QP Examples of rules Apply WHERE clause conditions first if it is possible If you have an index and you know the key value, use the key for direct access If you have an index and you know the leftmost part of the key value, use the key for direct access CSD305 Advanced Databases

Cost-based optimization Each QP is evaluated with respect to its estimated costs, including Disk I/O Number and size of rows processed Use of processing cycles The accuracy of cost estimation can vary greatly e.g. what percentage of rows will be returned when the condition (WHERE sex = ‘F’) is applied? 1%, 10%, 50%? The Query Optimizer needs statistics to make a good estimate CSD305 Advanced Databases

Statistical optimization The DBMS maintains statistics about the distribution of data values in tables and indexes The statistics are stored as part of the metadata and used by the Query Optimizer The statistics include Densities of key values (calculated as 1 divided by the number of different values) Sample values or range endpoints (up to 200 of them) CSD305 Advanced Databases

Statistics Example CSD305 Advanced Databases

Analyzing Query Plans Use SQL Management Studio On the Query toolbar Choose “New Query” On the Query toolbar Turn on “Display Estimated Execution Plan" option Run your SQL query A graphical representation of the plan will be displayed You can then click on any node to "drill down" to find more about what is going on Example on next few slides CSD305 Advanced Databases

The SQL query and results CSD305 Advanced Databases

The QP overview CSD305 Advanced Databases

Drilling down on the first node CSD305 Advanced Databases

…and the next CSD305 Advanced Databases

…and the last CSD305 Advanced Databases

Some notes on the query plan The query begins by seeking the classCode in a nonclustered index From this it will collect bookmarks The bookmarks are used in the next step to look up the corresponding row in the clustered index The rows are then returned to the client CSD305 Advanced Databases

Summary SQL queries are first parsed to establish syntactic correctness The Query Optimizer generates query plan(s) using rule-based, cost-based and statistical techniques A query plan is somewhat similar to the RA but incorporates physical considerations CSD305 Advanced Databases