Ján GENČI PDT 2009 Systém riadenia bázy dát (Database Management System)

Slides:



Advertisements
Similar presentations
Copyright © 2004 Pearson Education, Inc.. Chapter 15 Algorithms for Query Processing and Optimization.
Advertisements

Copyright © 2004 Ramez Elmasri and Shamkant Navathe Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 15-1 Query Processing and.
Chapter 15 Algorithms for Query Processing and Optimization Copyright © 2004 Pearson Education, Inc.
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.
CS346: Advanced Databases
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 19 Algorithms for Query Processing and Optimization.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 19 Algorithms for Query Processing and Optimization.
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 Processing and Optimization Dr. Muhammad Shafique
QUERY OPTIMIZATION AND QUERY PROCESSING.
CSCI 5708: Query Processing I Pusheng Zhang University of Minnesota Feb 3, 2004.
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.
Jan. 2014Dr. Yangjun Chen ACS Query Processing and Optimization Outline (Ch. 18, 3 rd – Ch. 15, 4 th ed. 5 th ed., Ch 19, 6 th ed.) Processing a.
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.
Algorithms for Query Processing and Optimization
CSCI 5708: Query Processing I Pusheng Zhang University of Minnesota Feb 3, 2004.
Algorithms for Query Processing and Optimization
Chapter 19 Query Processing and Optimization
©Silberschatz, Korth and Sudarshan14.1Database System Concepts 3 rd Edition Chapter 14: Query Optimization Overview Catalog Information for Cost Estimation.
Query Processing Presented by Aung S. Win.
Copyright © 2004 Ramez Elmasri and Shamkant Navathe Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 15-1 Query Processing and.
Department of Computer Science and Engineering, HKUST Slide Query Processing and Optimization Query Processing and Optimization.
Copyright © 2004 Pearson Education, Inc.. Chapter 15 Algorithms for Query Processing and Optimization.
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.
Query Processing and Optimization
Algorithms for Query Processing and Optimization
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Lecture 11: Query processing and optimization Jose M. Peña
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.
DatabaseIM ISU1 Fundamentals of Database Systems Chapter 6 The Relational Algebra.
16.7 Completing the Physical- Query-Plan By Aniket Mulye CS257 Prof: Dr. T. Y. Lin.
1 Chapter 18 Query Processing and Optimization Query Processing and Optimization Scanner: identify language components. keywords, attribute,
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.
Riyadh Philanthropic Society For Science Prince Sultan College For Woman Dept. of Computer & Information Sciences CS 340 Introduction to Database Systems.
CSCI Query Processing1 QUERY PROCESSING & OPTIMIZATION Dr. Awad Khalil Computer Science Department AUC.
Advance Database Systems Query Optimization Ch 15 Department of Computer Science The University of Lahore.
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 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
Query Processing COMP3017 Advanced Databases Nicholas Gibbins
Copyright © 2011 Ramez Elmasri and Shamkant Navathe CPSC 8620: Database Management System Design Notes 7 Query Processing.
Query optimization Algorithms for execution query elements Execution strategy Query optimization when using indices.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4 Basic SQL تنبيه : شرائح العرض (Slides) هي وسيلة لتوضيح الدرس واداة.
Query Processing and Query Optimization Database System Implementation CSE 507 Slides adapted from Silberschatz, Korth and Sudarshan Database System Concepts.
CHAPTER 19 Query Optimization. CHAPTER 19 Query Optimization.
Algorithms for Query Processing and Optimization
Query Processing and Optimization
Query Processing and Optimization, and Database Tuning
Query Optimization Heuristic Optimization
Database System Implementation CSE 507
Prepared by : Ankit Patel (226)
Overview of Query Optimization
Session - 6 Sequence - 2 SQL: The Structured Query Language:
Query processing and optimization
QUERY OPTIMIZATION.
1/3/2019.
Advance Database Systems
Completing the Physical-Query-Plan and Chapter 16 Summary ( )
Algorithms for Query Processing and Optimization
Presentation transcript:

Ján GENČI PDT 2009 Systém riadenia bázy dát (Database Management System)

2 Obsah Spracovanie dotazov Query tree Kanonický dotazovací strom Pravidlá algebraickej optimalizácie Query plány - príklady

3 Literatúra [1] Hector Garcia-Molina, Jeffrey D. Ullman, Jennifer D. Widom: Database System Implementation, Prentice Hall, ISBN-10: , pp.653 Database Systems: The Complete Book, 2001

4 Literatúra [2] Elmasri R., Navathe S. B. : Fundamentals of database systems. 4th ed., Pearson Education, th ed. – 2006, pp (ch ; 120 resp. 220 str.)

5 Literatúra [3] Ramakrishnan R., Gehrke J.: Database Management Systems. McGraw-Hill Science/Engineering/Math; 3rd ed., 2002, pp. 906 (ch. 7-14; 220 str.)

6 Literatúra [4] Abraham Silberschatz, Henry Korth, S. Sudarshan: Database System Concepts. McGraw-Hill Science/Engineering/Math; 5th ed., pp.~920 (ch ; 170 resp. 290 str.

Query processing and optimization Based on [2]

8 Query processing

9 Execution (query) plan Logical query plan Physical query plan

10 Logical query plan SQL – deklaratívny jazyk Potrebujeme transformovať dotaz v SQL (SELECT) na (previazanú) postupnosť operácií relačnej algebry Optimalizovať na logickej úrovni

11 Query tree A query tree - tree data structure that corresponds to a relational algebra expression. It represents the input relations of the query as leaf nodes of the tree, and represents the relational algebra operations as internal nodes. An execution of the query tree consists of executing an internal node operation whenever its operands are available and then replacing that internal node by the relation that results from executing the operation. The execution terminates when the root node is executed and produces the result relation for the query.

12 Query tree – example Example: For every project located in ‘ Stafford ’, retrieve the project number, the controlling department number and the department manager ’ s last name, address and birthdate. Relation algebra:  PNUMBER, DNUM, LNAME, ADDRESS, BDATE (((  PLOCATION=‘STAFFORD’ (PROJECT)) ⋈ DNUM=DNUMBER (DEPARTMENT)) ⋈ MGRSSN=SSN (EMPLOYEE)) SQL query: Q2: SELECT P.NUMBER,P.DNUM,E.LNAME, E.ADDRESS, E.BDATE FROM PROJECT AS P,DEPARTMENT AS D, EMPLOYEE AS E WHERE P.DNUM=D.DNUMBER AND D.MGRSSN=E.SSN AND P.PLOCATION= ‘ STAFFORD ’ ;

13 Query tree – example

14 Inicial (canonical) query tree

15 Konštrukcia „canonical query tree“ Nad všetkými reláciami vybuduj „veľký“ kartézsky súčin Vyselektuj záznamy podľa úplnej podmienky vo WHERE klauzule Sprav projekciu výsledku podľa atribútov za SELECT klauzulou

16 Konštrukcia „canonical query tree“ SELECT FROM T 1, …, T n WHERE C V relačnej algebre:  (  c (  (T 1, …, T n ) ) ) T1, …, Tn X cc 

17 Heuristic Optimization of Query Trees The same query could correspond to many different relational algebra expressions — and hence many different query trees. The task of heuristic optimization of query trees is to find a final query tree that is efficient to execute. Example: Q: SELECT LNAME FROM EMPLOYEE, WORKS_ON, PROJECT WHERE PNAME = ‘ AQUARIUS ’ AND PNMUBER=PNO AND ESSN=SSN AND BDATE > ‘ ’ ;

18 Canonical query tree

19 Steps in converting QT (1)

20 Steps in converting QT (2)

21 Transformation Rules for query optimization  Cascade of  : A conjunctive selection condition can be broken up into a cascade (sequence) of individual s operations:  c1 AND c2 AND... AND cn (R)   c1 (  c2 (...(  cn (R))...) )  Commutativity of  : The  operation is commutative:  c1 (  c2 (R))   c2 (  c1 (R))  Cascade of  : In a cascade (sequence) of  operations, all but the last one can be ignored:  List1 (  List2 (...(  Listn (R))...) ) =  List1 (R)

22 Transformation Rules for query optimization  Commuting  with  : If the selection condition c involves only the attributes A1,..., An in the projection list, the two operations can be commuted:  A1, A2,..., An (  c (R)) =  c (  A1, A2,..., An (R))  Commutativity of ⋈ ( and x ): The ⋈ operation is commutative as is the x operation: R ⋈ C S = S ⋈ C R; R x S = S x R

23 Transformation Rules for query optimization  Commuting  with ⋈ (or x  ): If all the attributes in the selection condition c involve only the attributes of one of the relations being joined - say, R - the two operations can be commuted as follows :  c ( R ⋈ S )  (  c (R)) ⋈ S Alternatively, if the selection condition c can be written as (c1 and c2), where condition c1 involves only the attributes of R and condition c2 involves only the attributes of S, the operations commute as follows:  c ( R ⋈ S )  (  c1 (R)) ⋈ (  c2 (S))

24 Transformation Rules for query optimization  Commuting  with ⋈ (or x ): Suppose that the projection list is L = {A1,..., An, B1,..., Bm}, where A1,..., An are attributes of R and B1,..., Bm are attributes of S. If the join condition c involves only attributes in L, the two operations can be commuted as follows:  L ( R ⋈ C S )  (  A1,..., An (R)) ⋈ C (  B1,..., Bm (S)) If the join condition c contains additional attributes not in L, these must be added to the projection list, and a final  operation is needed.

25 Transformation Rules for query optimization  Commutativity of set operations: The set operations  and  are commutative but – is not.  Associativity of ⋈, x, , and  : These four operations are individually associative; that is, if  stands for any one of these four operations (throughout the expression), we have ( R  S )  T  R  ( S  T )  Commuting  with set operations: The  operation commutes with  , , and –. If  stands for any one of these three operations, we have  c ( R  S )  (  c (R))  (  c (S))

26 Transformation Rules for query optimization  The  operation commutes with υ.  L ( R  S )  (  L (R))  (  L (S))  Converting a (  x  sequence into ⋈ : If the condition c of a  that  follows a  corresponds to a join condition, convert the (  x  sequence into a ⋈ as follows: (  C (R x S)) = (R ⋈ C S)  Other transformations

27 Outline of a Heuristic Algebraic Optimization Algorithm  Using rule 1, break up any select operations with conjunctive conditions into a cascade of select operations.  Using rules 2, 4, 6, and 10 concerning the commutativity of select with other operations, move each select operation as far down the query tree as is permitted by the attributes involved in the select condition.  Using rule 9 concerning associativity of binary operations, rearrange the leaf nodes of the tree so that the leaf node relations with the most restrictive select operations are executed first in the query tree representation.

28 Outline of a Heuristic Algebraic Optimization Algorithm  Using Rule 12, combine a cartesian product operation with a subsequent select operation in the tree into a join operation.  Using rules 3, 4, 7, and 11 concerning the cascading of project and the commuting of project with other operations, break down and move lists of projection attributes down the tree as far as possible by creating new project operations as needed.  Identify subtrees that represent groups of operations that can be executed by a single algorithm.

29 Summary of Heuristics for Algebraic Optimization  The main heuristic is to apply first the operations that reduce the size of intermediate results.  Perform select operations as early as possible to reduce the number of tuples and perform project operations as early as possible to reduce the number of attributes. (This is done by moving select and project operations as far down the tree as possible.)  The select and join operations that are most restrictive should be executed before other similar operations. (This is done by reordering the leaf nodes of the tree among themselves and adjusting the rest of the tree appropriately.)

30 Physical Query ( Execution ) Plans An physical query plan for a relational algebra query consists of a combination of the relational algebra query tree and information about the access methods to be used for each relation as well as the methods to be used in computing the relational operators stored in the tree.

31 Úloha Ako “obsadiť“ jednotlivé operácie RA konkrétnymi implementáciami Potreba ohodnotenia jednotlivých implementácií – cost based optimization Mali by sa vybudujú a prepočítať všetky možnosti Ak ich je veľa, peverujú sa len niektoré vetvy

32 Cost Components for Query Execution 1.Access cost to secondary storage 2.Storage cost 3.Computation cost 4.Memory usage cost 5.Communication cost Note: Different database systems may focus on different cost components.

33 Catalog Information Used in Cost Functions –Information about the size of a file number of records (tuples) (r), record size (R), number of blocks (b) blocking factor (bfr) –Information about indexes and indexing attributes of a file Number of levels (x) of each multilevel index Number of first-level index blocks (b I1 ) Number of distinct values (d) of an attribute Selectivity (sl) of an attribute Selection cardinality (s) of an attribute. (s = sl * r)

34 Otázky

Ladenie dotazov

36 Príklad INFORMIX (1) Detailnejsi opis - Sample Query Plan Reports.pdf

37 Príklad INFORMIX (2)

38 Príklad INFORMIX (3)

39 MS-SQL

40 Otázky