Chapter 18 Query Processing and Optimization. Chapter Outline u Introduction. u Using Heuristics in Query Optimization –Query Trees and Query Graphs –Transformation.

Slides:



Advertisements
Similar presentations
Query Processing Chapter 21 in Textbook.
Advertisements

Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Copyright © 2004 Ramez Elmasri and Shamkant Navathe Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 15-1 Query Processing and.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 19 Algorithms for Query Processing and Optimization.
Chapter 15 Algorithms for Query Processing and Optimization Copyright © 2004 Pearson Education, Inc.
Manajemen Basis Data Pertemuan Matakuliah: M0264/Manajemen Basis Data Tahun: 2008.
1 CSE 480: Database Systems Lecture 22: Query Optimization Reference: Read Chapter 15.6 – 15.8 of the textbook.
Query Optimization Dr. Karen C. Davis Professor School of Electronic and Computing Systems School of Computing Sciences and Informatics.
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.
CMPT 354, Simon Fraser University, Fall 2008, Martin Ester 52 Database Systems I Relational Algebra.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 19 Algorithms for Query Processing and Optimization.
Chapter 14 An Overview of Query Optimization. Copyright © 2005 Pearson Addison-Wesley. All rights reserved Figure 14.1 Typical architecture for.
CS 257, Spring’08 Presented By: Presented By: Gayatri Gopalakrishnan Gayatri Gopalakrishnan ID : 201.
CS263 Lecture 19 Query Optimisation.  Motivation for Query Optimisation  Phases of Query Processing  Query Trees  RA Transformation Rules  Heuristic.
QUERY OPTIMIZATION AND QUERY PROCESSING.
ACS-4902 Ron McFadyen Chapter 15 Algorithms for Query Processing and Optimization.
Introduction to Query Processing and Query Optimization Techniques
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Chapter 15 Algorithms for Query Processing and Optimization Copyright © 2004 Pearson Education, Inc.
ACS-4902 Ron McFadyen Chapter 15 Algorithms for Query Processing and Optimization See Sections 15.1, 2, 3, 7.
ICS (072)Query Processing and Optimization 1 Chapter 15 Algorithms for Query Processing and Optimization ICS 424 Advanced Database Systems Dr.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 6 The Relational Algebra and Relational Calculus.
Query Optimization. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Physical Design.
16.5 Introduction to Cost- based plan selection Amith KC Student Id: 109.
Chapter 19 Query Processing and Optimization
Query Processing Presented by Aung S. Win.
Ján GENČI PDT 2009 Systém riadenia bázy dát (Database Management System)
Database Management 9. course. Execution of queries.
Query Optimization (CB Chapter ) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems: An Application Oriented.
Department of Computer Science and Engineering, HKUST Slide Query Processing and Optimization Query Processing and Optimization.
Relational Algebra - Chapter (7th ed )
Query Optimization Chap. 19. Evaluation of SQL Conceptual order of evaluation – Cartesian product of all tables in from clause – Rows not satisfying where.
Chapter 15 Algorithms for Query Processing and Optimization Copyright © 2004 Pearson Education, Inc.
Academic Year 2014 Spring. MODULE CC3005NI: Advanced Database Systems “QUERY OPTIMIZATION” Academic Year 2014 Spring.
CSE314 Database Systems The Relational Algebra and Relational Calculus Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson Ed Slide Set.
Query Processing and Optimization
Switch off your Mobiles Phones or Change Profile to Silent Mode.
RELATIONAL ALGEBRA CHAPTER 6 1. LECTURE OUTLINE  Unary Relational Operations: SELECT and PROJECT  Relational Algebra Operations from Set Theory  Binary.
Lecture 11: Query processing and optimization Jose M. Peña
603 Database Systems Senior Lecturer: Laurie Webster II, M.S.S.E.,M.S.E.E., M.S.BME, Ph.D., P.E. Lecture 17 A First Course in Database Systems.
Chapter 15 Algorithms for Query Processing and Optimization Copyright © 2004 Pearson Education, Inc.
Query Processing Bayu Adhi Tama, MTI. 1 ownerNoclient © Pearson Education Limited 1995, 2005.
Chapter 18 Query Processing. 2 Chapter - Objectives u Objectives of query processing and optimization. u Static versus dynamic query optimization. u How.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Query Processing – Query Trees. Evaluation of SQL Conceptual order of evaluation – Cartesian product of all tables in from clause – Rows not satisfying.
Chapter 15 Algorithms for Query Processing and Optimization Copyright © 2004 Pearson Education, Inc.
Advance Database Systems Query Optimization Ch 15 Department of Computer Science The University of Lahore.
Relational Algebra p BIT DBMS II.
Chapter 15 Algorithms for Query Processing and Optimization Copyright © 2004 Pearson Education, Inc.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Introduction to Query Processing (1) Query optimization: The process of choosing a suitable execution.
Chapter 15 Algorithms for Query Processing and Optimization Copyright © 2004 Pearson Education, Inc.
Chapter 13 Query Optimization Yonsei University 1 st Semester, 2015 Sanghyun Park.
Chapter 13: Query Processing
1 Minggu 6, Pertemuan 12 Query Processing Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
Query Processing COMP3017 Advanced Databases Nicholas Gibbins
Relational Algebra COMP3211 Advanced Databases Nicholas Gibbins
Relational Algebra National University of Computer and Emerging Sciences Lecture # 6 June 30,2012.
Query Processing and Query Optimization Database System Implementation CSE 507 Slides adapted from Silberschatz, Korth and Sudarshan Database System Concepts.
Query Processing and Optimization, and Database Tuning
Query Optimization Heuristic Optimization
Database System Implementation CSE 507
Fundamental of Database Systems
The Relational Algebra and Relational Calculus
Query Optimization Phases of query processing
Chapter 15 QUERY EXECUTION.
QUERY OPTIMIZATION.
Advance Database Systems
Query Processing CSD305 Advanced Databases.
Algorithms for Query Processing and Optimization
Presentation transcript:

Chapter 18 Query Processing and Optimization

Chapter Outline u Introduction. u Using Heuristics in Query Optimization –Query Trees and Query Graphs –Transformation Rules for RA expressions –Heuristic Optimization

Introduction u With declarative languages such as SQL, user specifies what data is required rather than how it is to be retrieved. u Relieves user of knowing what constitutes good execution strategy. u Also gives DBMS more control over system performance. u Two main techniques for query optimization: – heuristic rules that order operations in a query. – comparing different strategies based on relative costs, and selecting one that minimizes resource usage.

Introduction Query Processing (QP) : Activities involved in retrieving data from the database. u Aims of QP: – transform query written in high-level language (e.g. SQL), into correct and efficient execution strategy expressed in low-level language (implementing RA); – execute the strategy to retrieve required data. Query Optimization (QO): Activity of choosing an efficient execution strategy for processing query. u As there are many equivalent transformations of same high-level query, aim of QO is to choose one that minimizes resource usage. u Generally, reduce total execution time of query. u May also reduce response time of query. u Problem computationally intractable with large number of relations, so strategy adopted is reduced to finding near optimum solution.

Introduction

Query Trees and Query Graphs

Transformation Rules for RA Operations u Cascade of Selection: Conjunctive selection operations can cascade into individual selection operations  p  q  r (R) =  p (  q (  r (R))) u Commutativity of selection.  p (  q (R)) =  q (  p (R)) u Cascade of Projection: In a sequence of projection operations, only the last in the sequence is required.   L   M …   N (R) =   L (R) u Commutativity of  and  : If the selection condition c involves only those attributes A 1, … A n in the projection list, then the two operations can commute:   Ai, …, Am (  c (R)) =  c (   Ai, …, Am (R))

Transformation Rules for RA Operations u Commutativity of  (and  ). R  p S = S  p R R  S = S  R u Associativity of  (and  ).  and natural join ( * )are always associative: (R * S)  T = R * (S * T) (R  S)  T = R  (S  T) If join condition q involves attributes only from S and T, then  is associative as follows: (R  p S)  q  r T = R  p  r (S  q T)

Transformation Rules for RA Operations u Commutativity of  and  (or  ). If all the attributes in the selection condition c involves only the attributes of one of the relations being joined – Say R – then the two operations can be commuted as follows:  c (R  r S) = (  c (R))  r S  c (R  S) = (  c (R))  S Alternatively if the condition c can be written as (c 1 and c 2 ), where condition c 1 involves only the attributes of the relations R and condition c 2 involves only the attributes of the relations S then the two operations can be commuted as follows:  c1 (R  r S) = (  c1 (R))  r (  c2 ( S))  c1 (R  S) = (  c1 (R))  (  c2 ( S))

Transformation Rules for RA Operations u Commutativity of  and  (or  ). If projection list is of form L = L 1  L 2, where L 1 only involves attributes of R, and L 2 only involves attributes of S, provided join condition only contains attributes of L, projection and theta-join operations commute as:   L1  L2 (R  r S) = (   L1 (R))  r (   L2 (S)) If join condition contains additional attributes not in L, say attributes M = M 1  M 2 where M 1 only involves attributes of R, and M 2 only involves attributes of S, a final projection operation is required:   L1   L2 ( R  r S ) =   L1  L2 ( (   L1   M1 ( R ))  r (   L2  M2 (S))) u Commutativity of  and  (but not - ). R  S = S  R R  S = S  R u Associativity of  and  (but not - ). (R  S)  T = S  (R  T) (R  S)  T = S  (R  T)

Transformation Rules for RA Operations Commutativity of  and set operations ( , , and - ).  p (R  S) =  p (S)   p (R)  p (R  S) =  p (S)   p (R)  p (R - S) =  p (S) -  p (R) u Commutativity of  and .   L (R  S) =   L (S)    L (R)

Heuristical Processing Strategies u Perform selection operations as early as possible. – Keep predicates on same relation together. u Combine Cartesian product with subsequent selection whose predicate represents join condition into a join operation. u Use associativity of binary operations to rearrange leaf nodes so leaf nodes with most restrictive selection operations executed first. u Perform projection as early as possible. – Keep projection attributes on same relation together. u Compute common expressions once. – If common expression appears more than once, and result not too large, store result and reuse it when required. – Useful when querying views, as same expression is used to construct view each time.

Use of Transformation Rules Q: Find the last name of employees born after 1975 who work on a project named ‘Aquarius’. SELECTLNAME, FROMEMPLOYEE, WORKS_ON, PROJECT, WHEREPNAME=‘Aquarius’ AND ESSN= SSN AND PNUMBER=PNO AND BDATE > ‘ ’

Use of Transformation Rules

Example 18.3 Use of Transformation Rules