ACS-4902 Ron McFadyen Chapter 15 Algorithms for Query Processing and Optimization.

Slides:



Advertisements
Similar presentations
ICS 434 Advanced Database Systems
Advertisements

Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Equality Join R X R.A=S.B S : : Relation R M PagesN Pages Relation S Pr records per page Ps records per page.
Copyright © 2011 Ramez Elmasri and Shamkant Navathe Algorithms for SELECT and JOIN Operations (8) Implementing the JOIN Operation: Join (EQUIJOIN, NATURAL.
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.
CS346: Advanced Databases
Database Management Systems 3ed, R. Ramakrishnan and Johannes Gehrke1 Evaluation of Relational Operations: Other Techniques Chapter 14, Part B.
Implementation of Other Relational Algebra Operators, R. Ramakrishnan and J. Gehrke1 Implementation of other Relational Algebra Operators Chapter 12.
Database Management Systems, R. Ramakrishnan and Johannes Gehrke1 Evaluation of Relational Operations: Other Techniques Chapter 12, Part B.
SPRING 2004CENG 3521 Query Evaluation Chapters 12, 14.
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.
Midterm Review Lecture 14b. 14 Lectures So Far 1.Introduction 2.The Relational Model 3.Disks and Files 4.Relational Algebra 5.File Org, Indexes 6.Relational.
CS263 Lecture 19 Query Optimisation.  Motivation for Query Optimisation  Phases of Query Processing  Query Trees  RA Transformation Rules  Heuristic.
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
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.
Algorithms for Query Processing and Optimization
1 Evaluation of Relational Operations: Other Techniques Chapter 12, Part B.
CSCI 5708: Query Processing I Pusheng Zhang University of Minnesota Feb 3, 2004.
1 Query Processing: The Basics Chapter Topics How does DBMS compute the result of a SQL queries? The most often executed operations: –Sort –Projection,
Algorithms for Query Processing and Optimization
Chapter 19 Query Processing and Optimization
Copyright © 2004 Ramez Elmasri and Shamkant Navathe Elmasri/Navathe, Fundamentals of Database Systems, Fourth Edition Chapter 15-1 Query Processing and.
©Silberschatz, Korth and Sudarshan13.1Database System Concepts Chapter 13: Query Processing Overview Measures of Query Cost Selection Operation Sorting.
Chapter 13 Query Processing Melissa Jamili CS 157B November 11, 2004.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Chapter 15 Algorithms for Query Processing and Optimization Copyright © 2004 Pearson Education, Inc.
Query Processing and Optimization
Query Processing. Steps in Query Processing Validate and translate the query –Good syntax. –All referenced relations exist. –Translate the SQL to relational.
Algorithms for Query Processing and Optimization
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
CPSC 404, Laks V.S. Lakshmanan1 Evaluation of Relational Operations: Other Operations Chapter 14 Ramakrishnan & Gehrke (Sections ; )
Computing & Information Sciences Kansas State University Tuesday, 03 Apr 2007CIS 560: Database System Concepts Lecture 29 of 42 Tuesday, 03 April 2007.
Chapter 15 Algorithms for Query Processing and Optimization Copyright © 2004 Pearson Education, Inc.
Lecture 1- Query Processing Advanced Databases Masood Niazi Torshiz Islamic Azad university- Mashhad Branch
Chapter 12 Query Processing. Query Processing n Selection Operation n Sorting n Join Operation n Other Operations n Evaluation of Expressions 2.
Chapter 12 Query Processing (1) Yonsei University 2 nd Semester, 2013 Sanghyun Park.
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
Chapter 15 Algorithms for Query Processing and Optimization Copyright © 2004 Pearson Education, Inc.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Advance Database Systems Query Optimization Ch 15 Department of Computer Science The University of Lahore.
1 B + -Trees: Search  If there are n search-key values in the file,  the path is no longer than  log  f/2  (n)  (worst case).
File Processing : Query Processing 2008, Spring Pusan National University Ki-Joune Li.
Query Processing – Implementing Set Operations and Joins Chap. 19.
Chapter 15 Algorithms for Query Processing and Optimization Copyright © 2004 Pearson Education, Inc.
Alon Levy 1 Relational Operations v We will consider how to implement: – Selection ( ) Selects a subset of rows from relation. – Projection ( ) Deletes.
Query Processing and Query Optimization Database System Implementation CSE 507 Some slides adapted from Silberschatz, Korth and Sudarshan Database System.
Chapter 15 Algorithms for Query Processing and Optimization Copyright © 2004 Pearson Education, Inc.
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.
Algorithms for Query Processing and Optimization
Query Processing and Optimization, and Database Tuning
Database Management System
Chapter 12: Query Processing
Chapter 15 QUERY EXECUTION.
File Processing : Query Processing
Database Applications (15-415) DBMS Internals- Part VI Lecture 15, Oct 23, 2016 Mohammad Hammoud.
1/3/2019.
Advance Database Systems
Chapter 12 Query Processing (1)
Evaluation of Relational Operations: Other Techniques
Database Administration
Algorithms for Query Processing and Optimization
Presentation transcript:

ACS-4902 Ron McFadyen Chapter 15 Algorithms for Query Processing and Optimization

ACS-4902 Ron McFadyen 2 Introduction Translating SQL Queries into Relational Algebra Algorithms for External Sorting

ACS-4902 Ron McFadyen 3 Introduction to Query Processing Query optimization: The process of choosing a suitable execution strategy for processing a query.

ACS-4902 Ron McFadyen 4 Introduction to Query Processing

ACS-4902 Ron McFadyen 5 Translating SQL Queries into Relational Algebra Query block: The basic unit that can be translated into the algebraic operators and optimized. A query block contains a single SELECT-FROM- WHERE expression, as well as GROUP BY and HAVING clause if these are part of the block. Nested queries within a query are identified as separate query blocks. Aggregate operators in SQL must be included in the extended algebra.

ACS-4902 Ron McFadyen 6 Translating SQL Queries into Relational Algebra consider: to find names of employees making more than everyone in department 5. SELECT lname, fname FROM employee WHERE salary > ( SELECT MAX(salary) FROM employee WHERE dno=5)

ACS-4902 Ron McFadyen 7 Translating SQL Queries into Relational Algebra 2 query blocks: SELECT lname, fname FROM employee WHERE salary > constant SELECT MAX(salary) FROM employee WHERE dno=5 Relational Algebra: π lname, fname (σ salary>cons (employee)) where cons is the result from: F MAX Salary (σ dno=5 (employee))

ACS-4902 Ron McFadyen 8 Translating SQL Queries into Relational Algebra consider: to find names of employees making more than everyone in department 5. SELECT lname, dname FROM employee e, department d WHERE e.dno=d.dno Relational Algebra: π lname, fname (employee * department)

ACS-4902 Ron McFadyen 9 Algorithms for External Sorting External sorting: Refers to sorting algorithms that are suitable for large files of records stored on disk that do not fit entirely in main memory, such as most database files. Sort-Merge strategy: Starts by sorting small subfiles (runs) of the main file and then merges the sorted runs, creating larger sorted subfiles that are merged in turn. Sorting phase: n R =  (b/n B )  Merging phase: d M = Min (n B -1, n R ); n P =  (log dM (n R ))  n R : number of initial runs b: number of file blocks n B : available buffer space d M : degree of merging n P : number of passes.

ACS-4902 Ron McFadyen 10 Simple Example of a Sort/Merge 1.Suppose we have an unsorted file… 2.Sort phase: Suppose we can hold one half in memory … Read in first half, sort it, write out as a sorted file Do the same for the second half Now we have two sorted files 3.Merge phase: Reading from both of the sorted files, we can sort and write out a single sorted file

ACS-4902 Ron McFadyen 11 Algorithms for External Sorting

ACS-4902 Ron McFadyen 12 Algorithms for SELECT and JOIN Operations Implementing the SELECT Operation Examples: (OP1):  SSN=' ' (EMPLOYEE) (OP2):  DNUMBER>5 (DEPARTMENT) (OP3):  DNO=5 (EMPLOYEE) (OP4):  DNO=5 AND SALARY>30000 AND SEX=F (EMPLOYEE) (OP5):  ESSN= AND PNO=10 (WORKS_ON)

ACS-4902 Ron McFadyen 13 Algorithms for SELECT and JOIN Operations Search Methods for Simple Selection: S1 Linear search (brute force): Retrieve every record in the file, and test whether its attribute values satisfy the selection condition. S2 Binary search: If the selection condition involves an equality comparison on a key attribute on which the file is ordered, binary search (which is more efficient than linear search) can be used. (See OP1). S3 Using a primary index or hash key to retrieve a single record: If the selection condition involves an equality comparison on a key attribute with a primary index (or a hash key), use the primary index (or the hash key) to retrieve the record.

ACS-4902 Ron McFadyen 14 Algorithms for SELECT and JOIN Operations S4 Using a primary index to retrieve multiple records: If the comparison condition is >, ≥, <, or ≤ on a key field with a primary index, use the index to find the record satisfying the corresponding equality condition, then retrieve all subsequent records in the (ordered) file. S5 Using a clustering index to retrieve multiple records: If the selection condition involves an equality comparison on a non- key attribute with a clustering index, use the clustering index to retrieve all the records satisfying the selection condition. S6 Using a secondary (B+-tree) index: On an equality comparison, this search method can be used to retrieve a single record if the indexing field has unique values (is a key) or to retrieve multiple records if the indexing field is not a key. In addition, it can be used to retrieve records on conditions involving >,>=, <, or <=. (FOR RANGE QUERIES)

ACS-4902 Ron McFadyen 15 Algorithms for SELECT and JOIN Operations S7 Conjunctive selection: If an attribute involved in any single simple condition in the conjunctive condition has an access path that permits the use of one of the methods S2 to S6, use that condition to retrieve the records and then check whether each retrieved record satisfies the remaining simple conditions in the conjunctive condition. S8 Conjunctive selection using a composite index If two or more attributes are involved in equality conditions in the conjunctive condition and a composite index (or hash structure) exists on the combined field, we can use the index directly.

ACS-4902 Ron McFadyen 16 Algorithms for SELECT and JOIN Operations S9 Conjunctive selection by intersection of record pointers: This method is possible if secondary indexes are available on all (or some of) the fields involved in equality comparison conditions in the conjunctive condition and if the indexes include record pointers (rather than block pointers). Each index can be used to retrieve the record pointers that satisfy the individual condition. The intersection of these sets of record pointers gives the record pointers that satisfy the conjunctive condition, which are then used to retrieve those records directly. If only some of the conditions have secondary indexes, each retrieved record is further tested to determine whether it satisfies the remaining conditions.