Chapter 13 Query Processing Melissa Jamili CS 157B November 11, 2004.

Slides:



Advertisements
Similar presentations
Chapter 13: Query Processing
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.
SPRING 2004CENG 3521 Query Evaluation Chapters 12, 14.
Query processing and optimization. Advanced DatabasesQuery processing and optimization2 Definitions Query processing –translation of query into low-level.
CS263 Lecture 19 Query Optimisation.  Motivation for Query Optimisation  Phases of Query Processing  Query Trees  RA Transformation Rules  Heuristic.
Quick Review of Apr 17 material Multiple-Key Access –There are good and bad ways to run queries on multiple single keys Indices on Multiple Attributes.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Query Processing.
©Silberschatz, Korth and Sudarshan13.1Database System Concepts Chapter 13: Query Processing Overview Measures of Query Cost Selection Operation Sorting.
Query Processing (overview)
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 13: Query Processing.
CSCI 5708: Query Processing I Pusheng Zhang University of Minnesota Feb 3, 2004.
ACS-4902 Ron McFadyen Chapter 15 Algorithms for Query Processing and Optimization.
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.
CSCI 5708: Query Processing I Pusheng Zhang University of Minnesota Feb 3, 2004.
Query Processing & 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.
©Silberschatz, Korth and Sudarshan13.1Database System Concepts Chapter 13: Query Processing Overview Measures of Query Cost Selection Operation Sorting.
Dr. Kalpakis CMSC 461, Database Management Systems Query Processing.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 13: Query Processing.
Query Processing Chapter 12
Database Management 9. course. Execution of queries.
©Silberschatz, Korth and Sudarshan13.1Database System Concepts Chapter 13: Query Processing Overview Measures of Query Cost Selection Operation Sorting.
©Silberschatz, Korth and Sudarshan7.1 Chapter 13: Query Processing Overview Measures of Query Cost Selection Operation Sorting Join Operation Other Operations.
Query Processing. Steps in Query Processing Validate and translate the query –Good syntax. –All referenced relations exist. –Translate the SQL to relational.
©Silberschatz, Korth and Sudarshan14.1Database System Concepts 3 rd Edition Chapter 14: Query Optimization Overview Catalog Information for Cost Estimation.
12.1Database System Concepts - 6 th Edition Chapter 12: Query Processing Overview Measures of Query Cost Selection Operation Join Operation Sorting 、 Other.
SCUHolliday - COEN 17814–1 Schedule Today: u Query Processing overview.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan Chapter 13: Query Processing.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 13: Query Processing.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 13: Query Processing.
Chapter 13: Query Processing Chapter 13: Query Processing Overview Measures of Query Cost Selection Operation Sorting Join Operation Other Operations.
Computing & Information Sciences Kansas State University Tuesday, 03 Apr 2007CIS 560: Database System Concepts Lecture 29 of 42 Tuesday, 03 April 2007.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 13: Query Processing.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 12: Query Processing.
Lecture 1- Query Processing Advanced Databases Masood Niazi Torshiz Islamic Azad university- Mashhad Branch
CPT-S Topics in Computer Science Big Data 1 1 Yinghui Wu EME 49.
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.
Chapter 13: Query Processing
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 13: Query Processing.
QUERY PROCESSING RELATIONAL DATABASE KUSUMA AYU LAKSITOWENING
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).
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 12: Query Processing.
13.1 Chapter 13: Query Processing n Overview n Measures of Query Cost n Selection Operation n Sorting n Join Operation n Other Operations n Evaluation.
Chapter 13: Query Processing. Overview Measures of Query Cost Selection Operation Sorting Join Operation Other Operations Evaluation of Expressions.
File Processing : Query Processing 2008, Spring Pusan National University Ki-Joune Li.
Query Processing and Query Optimization Database System Implementation CSE 507 Some slides adapted from Silberschatz, Korth and Sudarshan Database System.
Computing & Information Sciences Kansas State University Wednesday, 02 Apr 2008CIS 560: Database System Concepts Lecture 27 of 42 Wednesday, 02 April 2008.
1 Overview of Query Evaluation Chapter Outline  Query Optimization Overview  Algorithm for Relational Operations.
Chapter 13: Query Processing
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 12: Query Processing.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 12: Query Processing.
Chapter 4: Query Processing
Database Management System
Chapter 12: Query Processing
Chapter 15 QUERY EXECUTION.
File Processing : Query Processing
File Processing : Query Processing
Database Applications (15-415) DBMS Internals- Part VI Lecture 15, Oct 23, 2016 Mohammad Hammoud.
Query Processing B.Ramamurthy Chapter 12 11/27/2018 B.Ramamurthy.
Lecture 2- Query Processing (continued)
Advance Database Systems
Chapter 12 Query Processing (1)
Overview of Query Evaluation
Presentation transcript:

Chapter 13 Query Processing Melissa Jamili CS 157B November 11, 2004

Outline Overview Measures of query cost Selection operation –Basic algorithms –Selections using indices –Selections involving comparisons –Implementation of complex selections Sorting

Overview Query processing – the range of activities involved in extracting data from a database. –Includes: translation of queries, query- optimizing transformations, evaluation of queries.

Overview (cont.) Steps involved in processing a query: 1)Parsing and translation 2)Optimization 3)Evaluation

Step 1. Parsing and translation System checks the syntax of the query. Creates a parse-tree representation of the query. Translates the query into a relational- algebra expression.

Step 2. Optimization Each relational-algebra operation can be executed by one of several different algorithms. Ex. Every tuple can be searched linearly or a B+ tree can be used to index the tuples. A query optimizer must know the cost of each operation.

Step 3. Evaluation A relational-algebra expression and evaluation primitive are needed. –evaluation primitive - relational-algebra expression annotated with instructions specifying how to evaluate each operation.

Step 3. Evaluation (cont.) Query execution plan or query-evaluation plan – sequence of primitive operations that can be used to evaluate the expression. Π balance (σ balance < 2500 (account))

Step 3. Evaluation (cont.) Then the query-execution engine takes a query-evaluation plan, executes that plan, and returns the answers to the query.

Steps in query processing

Measures of Query Cost Measured in terms of different resources, including disk accesses and CPU execution time Measured in response time for a query-evaluation plan (clock time to execute the plan)

Measures of Query Cost (cont.) Disk accesses, number of block transfers from disk, are usually the most important cost To calculate add these numbers: 1)# of seek operations performed 2)# of blocks read 3)# of blocks written After multiplying them by the average seek time, average transfer time, and average transfer time, respectively.

Selection Operation File scan is the lowest-level operator to access data. File scans are search algorithms that locate and retrieve records that fulfill a selection condition. Allows an entire relation to be read where the relation is stored in a single, dedicated file.

Basic Algorithms Two basic scan algorithms to implement the selection operation: A1 (linear search). –The system scans each file block and tests all records to see whether they satisfy the selection condition. –System terminates if the required record is found, without looking at the other records. A2 (binary search). –System performs the binary search on the blocks of the file. –File is ordered on an attribute, and selection condition is an equality comparison.

Selections Using Indices Index structures referred to a access paths, since they provide a path through which data can be located and accessed. Primary index – allows records to be read in an order that corresponds to the physical order in the file. Secondary index – any index that is not a primary index.

Selections Using Indices (cont.) A3 (primary index, equality on key). –Use the index to retrieve a single record that satisfies the corresponding equality condition. A4 (primary index, equality on nonkey). –Same as A3, but multiple records may need to be fetched.

Selections Using Indices (cont.) A5 (secondary index, equality). –Retrieve a single record if the equality condition is on a key. –Retrieve multiple records if the indexing field is not a key.

Selections Involving Comparisons Consider the form σ A ≥ v (r). Can be implemented by linear or binary search or by using indices: A6 (primary index, comparison). –For A ≥ v, look for first tuple that has the value of A = v, return all the tuples starting from the tuple up to the end of the file. –For A < v, file scan from the beginning up to (but not including) the first tuple with attribute A = v.

Selections Involving Comparisons (cont.) A7 (secondary index, comparison). –The lowest-level blocks are scanned From the smallest value up to v for < and ≤. From v up to the maximum value for > and ≥.

Implementation of Complex Selections Previously only considered simple selection conditions with an equality or comparison operation. Now consider more complex selection predicates.

Implementation of Complex Selections (cont.) Conjunction: σ θ1 ∩ θ2 ∩ … ∩ θn (r) Disjunction: σ θ1 ∪ θ2 ∪ … ∪ θn (r) Negation: σ -θ (r)

Implementation of Complex Selections (cont.) A8 (conjunctive selection using one index). –Determine if there is an access path for an attribute in one of the simple conditions. –If yes, algorithms A2 through A7 can be used. –On all records retrieved test if they satisfy the remaining simple conditions.

Implementation of Complex Selections (cont.) A9 (conjunctive selection using composite index (multiple attributes). –Search index directly if selection specifies an equality condition on 2 or move attributes and a composite index exists. –Type of index determines if A3, A4, or A5 will be used.

Implementation of Complex Selections (cont.) A10 (conjunction selection by intersection of identifiers). –Requires indices with record pointers. –Scan each index for pointers that satisfy an individual condition. –Take intersection of all retrieved pointers to get set of pointers that satisfy the conjunctive condition. –Then pointers used to retrieve actual records. –If indices not available on all conditions, then algorithm tests retrieved records against remaining conditions.

Implementation of Complex Selections (cont.) A11 (disjunctive selection by union of identifiers). –Each index is scanned for pointers to tuples that satisfy the individual condition. –Union of all the retrieved pointers gives the set of pointers to all tuples that satisfy the disjunctive condition. –Pointers then used to retrieve actual records.

Sorting Focus on external sorting where relations that are bigger than memory. Most common is external merge-sort algorithm.

Sorting (cont.) N-way merge –A number of runs are created and sorted. –Runs are merged.

Conclusion Query processing - translation, transformation, and evaluation. Query cost measured by number of disk accesses. Selection operation algorithms Sorting – N-way merge.