Query Processing Presented by Aung S. Win.

Slides:



Advertisements
Similar presentations
Query Processing Chapter 21 in Textbook.
Advertisements

Query Optimization Reserves Sailors sid=sid bid=100 rating > 5 sname (Simple Nested Loops) Imperative query execution plan: SELECT S.sname FROM Reserves.
Distributed DBMS © M. T. Özsu & P. Valduriez Ch.7/1 Outline Introduction Background Distributed Database Design Database Integration Semantic Data Control.
Manajemen Basis Data Pertemuan Matakuliah: M0264/Manajemen Basis Data Tahun: 2008.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Relational Query Optimization Chapters 14.
1 CSE 480: Database Systems Lecture 22: Query Optimization Reference: Read Chapter 15.6 – 15.8 of the textbook.
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.
Query processing and optimization. Advanced DatabasesQuery processing and optimization2 Definitions Query processing –translation of query into low-level.
Cs44321 CS4432: Database Systems II Query Optimizer – Cost Based Optimization.
CS263 Lecture 19 Query Optimisation.  Motivation for Query Optimisation  Phases of Query Processing  Query Trees  RA Transformation Rules  Heuristic.
Database Systems: A Practical Approach to Design, Implementation and Management International Computer Science S. Carolyn Begg, Thomas Connolly Lecture.
1 Intermediate representation Goals: –encode knowledge about the program –facilitate analysis –facilitate retargeting –facilitate optimization scanning.
QUERY OPTIMIZATION AND QUERY PROCESSING.
CSCI 5708: Query Processing I Pusheng Zhang University of Minnesota Feb 3, 2004.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
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.
Query Optimization. General Overview Relational model - SQL  Formal & commercial query languages Functional Dependencies Normalization Physical Design.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Query Optimization Chapter 15.
CSCI 5708: Query Processing I Pusheng Zhang University of Minnesota Feb 3, 2004.
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.
T HE Q UERY C OMPILER Prepared by : Ankit Patel (226)
Chapter 17 Methodology – Physical Database Design for Relational Databases Transparencies © Pearson Education Limited 1995, 2005.
Team Dosen UMN Physical DB Design Connolly Book Chapter 18.
Query Optimization, part 2 CS634 Lecture 13, Mar Slides based on “Database Management Systems” 3 rd ed, Ramakrishnan and Gehrke.
CSC271 Database Systems Lecture # 30.
Context Tailoring the DBMS –To support particular applications Beyond alphanumerical data Beyond retrieve + process –To support particular hardware New.
Lecture 9 Methodology – Physical Database Design for Relational Databases.
Database Management Systems, R. Ramakrishnan and J. Gehrke1 Query Evaluation Chapter 12: Overview.
COMP 5138 Relational Database Management Systems Semester 2, 2007 Lecture 12 Query Processing and Optimization.
Query Optimization. overview Histograms A histogram is a data structure maintained by a DBMS to approximate a data distribution Equiwidth vs equidepth.
Database Management 9. course. Execution of queries.
Chapter 16 Methodology – Physical Database Design for Relational Databases.
Query Optimization (CB Chapter ) CPSC 356 Database Ellen Walker Hiram College (Includes figures from Database Systems: An Application Oriented.
©Silberschatz, Korth and Sudarshan13.1Database System Concepts Chapter 13: Query Processing Overview Measures of Query Cost Selection Operation Sorting.
Query Optimization Arash Izadpanah. Introduction: What is Query Optimization? Query optimization is the process of selecting the most efficient query-evaluation.
Query Optimization Chap. 19. Evaluation of SQL Conceptual order of evaluation – Cartesian product of all tables in from clause – Rows not satisfying where.
Academic Year 2014 Spring. MODULE CC3005NI: Advanced Database Systems “QUERY OPTIMIZATION” Academic Year 2014 Spring.
1 Chapter 20 Query Processing Transparencies. 2 Chapter 20 - Objectives u Objectives of query processing and optimization. u Static versus dynamic query.
PMIT-6102 Advanced Database Systems By- Jesmin Akhter Assistant Professor, IIT, Jahangirnagar University.
Switch off your Mobiles Phones or Change Profile to Silent Mode.
Query Processing Bayu Adhi Tama, MTI. 1 ownerNoclient © Pearson Education Limited 1995, 2005.
Methodology – Physical Database Design for Relational Databases.
Chapter 18 Query Processing. 2 Chapter - Objectives u Objectives of query processing and optimization. u Static versus dynamic query optimization. u How.
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.
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.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Introduction to Query Processing (1) Query optimization: The process of choosing a suitable execution.
Lecture 15: Query Optimization. Very Big Picture Usually, there are many possible query execution plans. The optimizer is trying to chose a good one.
Chapter 18 Query Processing and Optimization. Chapter Outline u Introduction. u Using Heuristics in Query Optimization –Query Trees and Query Graphs –Transformation.
1 Overview of Query Evaluation Chapter Outline  Query Optimization Overview  Algorithm for Relational Operations.
Chapter 13: Query Processing
1 Minggu 6, Pertemuan 12 Query Processing Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
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.
Chapter 14: Query Optimization
Query Processing and Optimization, and Database Tuning
Query Optimization Heuristic Optimization
Database Management System
Prepared by : Ankit Patel (226)
Methodology – Physical Database Design for Relational Databases
CS222P: Principles of Data Management Lecture #15 Query Optimization (System-R) Instructor: Chen Li.
Query Optimization Phases of query processing
Chapter 15 QUERY EXECUTION.
Query Processing B.Ramamurthy Chapter 12 11/27/2018 B.Ramamurthy.
Chapter 23 Query Processing Pearson Education © 2014.
Query Optimization.
CS222: Principles of Data Management Lecture #15 Query Optimization (System-R) Instructor: Chen Li.
Presentation transcript:

Query Processing Presented by Aung S. Win

Objectives Query processing and optimization. Static versus dynamic query optimization. How a query is decomposed and semantically analyzed. How to create a relational algebra tree to represent a query. The rules of equivalence for the relational algebra operations.

(Cont.) Heuristic transformation rules. The types of database statistics required to estimate the cost of operations. The different strategies for implementing the relational algebra operations. The difference between materialization and pipelining. The advantages of left-deep trees.

Query Processing The activities involved in retrieving data from the database. The aims of query processing (1)to transform a query written in a high-level language into a low-level language (2)to execute the strategy to retrieve the required data.

(Cont.) Query processing can be divided into four main phases: decomposition, optimization, code generation, and execution.

Query Decomposition The aims of query decomposition (1)to transform a high-level query into a relational algebra query. (2)to check that the query is syntactically and semantically correct.

(Cont.) The typical stages of query decomposition are analysis, normalization, semantic analysis, simplification, and query restructuring.

Analysis The query is lexically and syntactically analyzed using the techniques of programming language compilers. Verifies that the relations and attributes specified in the query are defined in the system catalog. Verifies that any operations applied to database objects are appropriate for the object type.

(Cont.) On completion of the analysis, the high-level query has been transformed into some internal representation (query tree) that is more suitable for processing. Root Intermediate operations leaves

Normalization Converts the query into a normalized form that can be more easily manipulated. There are two different normal forms, conjunctive normal form and disjunctive normal form.

Conjunctive normal form A sequence of conjuncts that are connected with the and operator. Each conjunct contains one or more terms connected by the or operator. for example (position=‘Manager’ V salary>20000) ^ branchNo = ‘B003’

Disjunctive normal form A sequence of disjuncts that are connected with the or operator. Each disjunt contains one or more terms connected by the and operator. for example (position=‘Manager’ ^ branchNo = ‘B003’) V (salary>20000 ^ branchNo = ‘B003’)

Semantic analysis The objective is to reject normalized queries that are incorrectly formulated or contradictory.

Simplification To detect redundant qualifications, eliminate common subexpressions , and transform the query to a semantically equivalent but more easily and efficiently computed form. Access restrictions, view definitions, and integrity constraints are considered at this stage.

Query restructuring The final stage of query decomposition. The query is restructured to provide a more efficient implementation.

Query optimization The activity of choosing an efficient execution strategy for processing a query. An important aspect of query processing is query optimization. The aim of query optimization is to choose the one that minimizes resource usage.

(Cont.) Every method of query optimization depend on database statistics. The statistics cover information about relations, attribute, and indexes. Keeping the statistics current can be problematic. If the DBMS updates the statistics every time a tuple is inserted, updated, or deleted, this would have a significant impact on performance during peak period.

(Cont.) An alternative approach is to update the statistics on a periodic basis, for example nightly, or whenever the system is idle.

Dynamic query optimization Advantage: all information required to select an optimum strategy is up to date. Disadvantage: the performance of the query is affected because the query has to be parsed, validated, and optimized before it can be executed.

Static query optimization The query is parsed, validated, and optimized once that is similar to the approach taken by a compiler for a programming language. Advantages 1)The runtime overhead is removed 2)More time available to evaluate a larger number of execution strategies.

(cont.) Disadvantage: the execution strategy that is chosen as being optimal when the query is compiled may no longer be optimal when the query is run.

Transformation Rules for the Relational Algebra Operations By applying transformation rules, we can transform one relational algebra into an equivalent expression that is more efficient. There are twelve rules that can be used to restructure the relational algebra tree generated during query decomposition.

Heuristics rules Many DBMSs use heuristics to determine strategies for query processing. Heuristics rules include -performing Selection and Projections as early as possible. -combining Cartesian product with a subsequent selection whose predicate represents a join condition into a join operation.

(Cont.) -using associativity of binary operations to rearrange leaf nodes so that leaf nodes with the most restrictive Selections are executed first.

Cost estimation Depends on statistical information held in the system catalog. Typical statistics include the cardinality of each base relation, the number of blocks required to store a relation, the number of distinct values for each attribute, the selection cardinality of each attribute, and the number of levels in each multilevel index.

Join operation Block nested loop join Indexed nested loop join Sort-merge join Hash join

Pipelining In materialization, the output of one operation is stored in a temporary relation for processing by the next operation. An alternative approach is to pipeline the results of one operation to another operation without creating a temporary relation to hold the intermediate result. By using it, we can save on the cost of creating temporary relations and reading the results back in again.

Left – deep trees A relational algebra tree where the right-hand relation is always a base relation. Advantages: reducing the search space for the optimum strategy and allowing the query optimizer to be based on dynamic processing techniques.