Query Processing and Query Optimization CS 157B Dennis Le Weishan Wang.

Slides:



Advertisements
Similar presentations
Chapter 13: Query Processing
Advertisements

Equality Join R X R.A=S.B S : : Relation R M PagesN Pages Relation S Pr records per page Ps records per page.
CS 245Notes 71 CS 245: Database System Principles Notes 7: Query Optimization Hector Garcia-Molina.
Copyright © 2011 Ramez Elmasri and Shamkant Navathe Algorithms for SELECT and JOIN Operations (8) Implementing the JOIN Operation: Join (EQUIJOIN, NATURAL.
Chapter 15 Algorithms for Query Processing and Optimization Copyright © 2004 Pearson Education, Inc.
CS 540 Database Management Systems
CS CS4432: Database Systems II Operator Algorithms Chapter 15.
Database Management Systems 3ed, R. Ramakrishnan and Johannes Gehrke1 Evaluation of Relational Operations: Other Techniques Chapter 14, Part B.
Database Management Systems, R. Ramakrishnan and Johannes Gehrke1 Evaluation of Relational Operations: Other Techniques Chapter 12, Part B.
Database Management Systems, R. Ramakrishnan and Johannes Gehrke1 Evaluation of Relational Operations: Other Techniques Chapter 12, Part B.
Query processing and optimization. Advanced DatabasesQuery processing and optimization2 Definitions Query processing –translation of query into low-level.
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.
CS 245Notes 71 CS 245: Database System Principles Notes 7: Query Optimization Hector Garcia-Molina.
1 Chapter 10 Query Processing: The Basics. 2 External Sorting Sorting is used in implementing many relational operations Problem: –Relations are typically.
CS263 Lecture 19 Query Optimisation.  Motivation for Query Optimisation  Phases of Query Processing  Query Trees  RA Transformation Rules  Heuristic.
Query Processing and Optimization
1 Optimization - Selection. 2 The Selection Operation Table: Reserves(sid, bid, day, agent) A page (block) can hold 100 Reserves tuples There are 1,000.
Quick Review of Apr 22 material Sections 13.1 through 13.3 in text Query Processing: take an SQL query and: –parse/translate it into an internal representation.
Query Optimization 3 Cost Estimation R&G, Chapters 12, 13, 14 Lecture 15.
1 Evaluation of Relational Operations: Other Techniques Chapter 12, Part B.
1 Query Processing: The Basics Chapter Topics How does DBMS compute the result of a SQL queries? The most often executed operations: –Sort –Projection,
Chapter 19 Query Processing and Optimization
CS 4432query processing - lecture 171 CS4432: Database Systems II Lecture #17 Join Processing Algorithms (cont). Professor Elke A. Rundensteiner.
Query Evaluation and Optimization Main Steps 1.Translate into RA: select/project/join 2.Greedy optimization of RA: by pushing selection and projection.
1 Relational Operators. 2 Outline Logical/physical operators Cost parameters and sorting One-pass algorithms Nested-loop joins Two-pass algorithms.
AN INTRODUCTION TO EXECUTION PLAN OF QUERIES These slides have been adapted from a presentation originally made by ORACLE. The full set of original slides.
Relational Database Performance CSCI 6442 Copyright 2013, David C. Roberts, all rights reserved.
ICOM 6005 – Database Management Systems Design Dr. Manuel Rodríguez-Martínez Electrical and Computer Engineering Department Lecture 14 – Join Processing.
COMP 5138 Relational Database Management Systems Semester 2, 2007 Lecture 12 Query Processing and Optimization.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
CPS216: Advanced Database Systems Notes 07:Query Execution Shivnath Babu.
Query Processing. Steps in Query Processing Validate and translate the query –Good syntax. –All referenced relations exist. –Translate the SQL to relational.
CS 338Query Evaluation7-1 Query Evaluation Lecture Topics Query interpretation Basic operations Costs of basic operations Examples Textbook Chapter 12.
Joseph M. Hellerstein Peter J. Haas Helen J. Wang Presented by: Calvin R Noronha ( ) Deepak Anand ( ) By:
CS4432: Database Systems II Query Processing- Part 3 1.
CS411 Database Systems Kazuhiro Minami 11: Query Execution.
Advance Database Systems Query Optimization Ch 15 Department of Computer Science The University of Lahore.
David Konopnicki –1997, Rev. MS Optimizing Join Statements To choose an execution plan for a join statement, the optimizer must choose: ä Access.
CS 440 Database Management Systems Lecture 5: Query Processing 1.
More Optimization Exercises. Block Nested Loops Join Suppose there are B buffer pages Cost: M + ceil (M/(B-2))*N where –M is the number of pages of R.
Chapter 12 Query Processing (2) Yonsei University 2 nd Semester, 2013 Sanghyun Park.
Query Processing – Implementing Set Operations and Joins Chap. 19.
Relational Operator Evaluation. overview Projection Two steps –Remove unwanted attributes –Eliminate any duplicate tuples The expensive part is removing.
CS 540 Database Management Systems
Alon Levy 1 Relational Operations v We will consider how to implement: – Selection ( ) Selects a subset of rows from relation. – Projection ( ) Deletes.
Fan Qi Database Lab 1, com1 #01-08 CS3223 Tutorial 8.
Fan Qi Database Lab 1, com1 #01-08 CS3223 Tutorial 6.
1 Lecture 23: Query Execution Monday, November 26, 2001.
Fan Qi Database Lab 1, com1 #01-08 CS3223 Tutorial 5.
Chapter 10 The Basics of Query Processing. Copyright © 2005 Pearson Addison-Wesley. All rights reserved External Sorting Sorting is used in implementing.
CS 540 Database Management Systems
CS 440 Database Management Systems
Query Processing Exercise Session 4.
Database Management System
Database Applications (15-415) DBMS Internals- Part VII Lecture 16, October 25, 2016 Mohammad Hammoud.
Teradata Join Processing
Evaluation of Relational Operations: Other Operations
File Processing : Query Processing
Yan Huang - CSCI5330 Database Implementation – Access Methods
CS143:Evaluation and Optimization
Performance Join Operator Select * from R, S where R.a = S.a;
Implementation of Relational Operations
Lecture 23: Query Execution
Evaluation of Relational Operations: Other Techniques
Lecture 22: Query Execution
C. Faloutsos Query Optimization – part 2
External Sorting Sorting is used in implementing many relational operations Problem: Relations are typically large, do not fit in main memory So cannot.
Database Administration
Evaluation of Relational Operations: Other Techniques
Lecture 20: Query Execution
Presentation transcript:

Query Processing and Query Optimization CS 157B Dennis Le Weishan Wang

What are we going to cover 1. Processing Selection Queries 2. Processing Projection Queries and Eliminating Duplicates 3. Processing Join Queries 4. Query Plans and Query Optimization for Complex Relational Expression 5. Query Optimization and Database Analysis in Oracle8 6. Summary

1. How database processes queries

1. Processing Selection Queries A Query Plan is a particular strategy for reading the indexes and files to process a query

Query plan for query 1 s elect * from Customer where accountId = 101

Query 5 selection based on a hash table index select * from Customer where zipcode = 32306

2. Processing Projection Queries and Eliminating Duplicates Suppose we use the following query to eliminate the duplicates select distinct lastName, firstName from Customer The DBMS has two ways of doing this which are based on sorting and hashing The sorting method sorts the projected records and writes the nonduplicates The hashing method partitions the file into buckets then sorts within buckets to eliminate duplicates

3. Processing Join Queries Suppose we have following three tables: Customer, Rental and Movie B: number of Blocks, R: number of rows The following example shows the same cost of data blocks reads for both plans

Two plans have the same cost

Improvement - block nested loops join Use the method readBlock() in the outer loop to read the outer table into an array The inner loop reads the inner file(array) Reduce the cost to Bc + Bc x Br

Improvement - indexed nested loops join Reduce the reads by using index If one of the attributes is indexed, we should take advantage of it Use indexed read  readByAccountId() Two plans have different costs because of the one-to-many relationship

Improvement - indexed nested loops join

Each rental has a customer but not every customer has a rental Plan-1 (Rental inner)reads every customer and every rental once, but plan- 2 (Rental outer)reads some customers many times and some customer no times Which plan to use is depending on the size of the file(table). Chose plan-1 if the customer file is smaller

Improvement - sort-merge join Sort both tables and merge the result The cost will depend on the cost of sorting(typically on the order of NlogN for N records)

Improvement - hash join Create a hash table for each join table The cost of the hash join depends on the size of the two hash tables(Hc and Hr) The total cost is 2(Bc+Br+Hc+Hr)

4. Query Plans and Query Optimization for Complex Relational Expression Query Optimization Process: 1. Enumerate the query plans 2. Estimate the costs of the plans 3. Choose the best plan for the query

4. Query Plans and Query Optimization for Complex Relational Expression

Estimating costs (Query Optimizer) - number of records - size of records in each table - location and types of indexes - ordering of files - memory available for disk cache - etc…

5. Query Optimization and Database Analysis in Oracle8 Tables that keep information about the DataBase Analyze Statement

5. Query Optimization and Database Analysis in Oracle8

6. Summary Principles and Practices of Query Processing Techniques in optimizing Query Processes Process of Query Optimization Commercial products implements these principles

7. References “Principles of Database Systems with internet and JAVA applications,” by Greg Riccardi