Academic Year 2014 Spring. MODULE CC3005NI: Advanced Database Systems “QUERY OPTIMIZATION” Academic Year 2014 Spring.

Slides:



Advertisements
Similar presentations
Query optimisation.
Advertisements

Tuning: overview Rewrite SQL (Leccotech)Leccotech Create Index Redefine Main memory structures (SGA in Oracle) Change the Block Size Materialized Views,
Copyright © 2004 Pearson Education, Inc.. Chapter 15 Algorithms for Query Processing and Optimization.
Manajemen Basis Data Pertemuan Matakuliah: M0264/Manajemen Basis Data Tahun: 2008.
UNIT 15 Query Optimization Wei-Pang Yang, Information Management, NDHU Contents  15.1 Introduction to Query Optimization  15.2 The Optimization.
Advanced Databases: Lecture 2 Query Optimization (I) 1 Query Optimization (introduction to query processing) Advanced Databases By Dr. Akhtar Ali.
CS263 Lecture 19 Query Optimisation.  Motivation for Query Optimisation  Phases of Query Processing  Query Trees  RA Transformation Rules  Heuristic.
CSCI 5708: Query Processing I Pusheng Zhang University of Minnesota Feb 3, 2004.
THE QUERY COMPILER 16.6 CHOOSING AN ORDER FOR JOINS By: Nitin Mathur Id: 110 CS: 257 Sec-1.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Database Management Systems 3ed, R. Ramakrishnan and J. Gehrke1 Relational Query Optimization Chapter 15.
Query Processing & Optimization
©Silberschatz, Korth and Sudarshan14.1Database System Concepts 3 rd Edition Chapter 14: Query Optimization Overview Catalog Information for Cost Estimation.
Access Path Selection in a Relation Database Management System (summarized in section 2)
Query Processing Presented by Aung S. Win.
Relational Database Performance CSCI 6442 Copyright 2013, David C. Roberts, all rights reserved.
Practical Database Design and Tuning. Outline  Practical Database Design and Tuning Physical Database Design in Relational Databases An Overview of Database.
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
Access Path Selection in a Relational Database Management System Selinger et al.
Query Optimization. overview Histograms A histogram is a data structure maintained by a DBMS to approximate a data distribution Equiwidth vs equidepth.
Advanced Databases: Lecture 8 Query Optimization (III) 1 Query Optimization Advanced Databases By Dr. Akhtar Ali.
Database Management 9. course. Execution of queries.
Switch off your Mobiles Phones or Change Profile to Silent Mode.
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.
1 Chapter 7 Optimizing the Optimizer. 2 The Oracle Optimizer is… About query optimization Is a sophisticated set of algorithms Choosing the fastest approach.
Query Optimization Chap. 19. Evaluation of SQL Conceptual order of evaluation – Cartesian product of all tables in from clause – Rows not satisfying where.
Advanced Databases: Lecture 6 Query Optimization (I) 1 Introduction to query processing + Implementing Relational Algebra Advanced Databases By Dr. Akhtar.
Chapter 16 Practical Database Design and Tuning Copyright © 2004 Pearson Education, Inc.
Lecture2: Database Environment Prepared by L. Nouf Almujally 1 Ref. Chapter2 Lecture2.
Physical Database Design Transparencies. ©Pearson Education 2009 Chapter 11 - Objectives Purpose of physical database design. How to map the logical database.
SCUHolliday - COEN 17814–1 Schedule Today: u Query Processing overview.
Switch off your Mobiles Phones or Change Profile to Silent Mode.
Lecture 1- Query Processing Advanced Databases Masood Niazi Torshiz Islamic Azad university- Mashhad Branch
Chapter 12 Query Processing (1) Yonsei University 2 nd Semester, 2013 Sanghyun Park.
DATABASE MANAGEMENT SYSTEM ARCHITECTURE
Indexes and Views Unit 7.
Switch off your Mobiles Phones or Change Profile to Silent Mode.
Query Optimizer (Chapter ). Optimization Minimizes uses of resources by choosing best set of alternative query access plans considers I/O cost,
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
Query Processing – Query Trees. Evaluation of SQL Conceptual order of evaluation – Cartesian product of all tables in from clause – Rows not satisfying.
CSCI Query Processing1 QUERY PROCESSING & OPTIMIZATION Dr. Awad Khalil Computer Science Department AUC.
Query Optimization CMPE 226 Database Systems By, Arjun Gangisetty
Relational Algebra p BIT DBMS II.
File Processing : Query Processing 2008, Spring Pusan National University Ki-Joune Li.
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
1 Minggu 6, Pertemuan 12 Query Processing Matakuliah: T0206-Sistem Basisdata Tahun: 2005 Versi: 1.0/0.0.
Chiu Luk CS257 Database Systems Principles Spring 2009
Query Processing and Optimization, and Database Tuning
Practical Database Design and Tuning
Storage Access Paging Buffer Replacement Page Replacement
UNIT 11 Query Optimization
Database Management System
Secondary Storage Data Retrieval.
Query Optimization Kush Kashyap B.Tech -IT.
Chapter 12: Query Processing
Overview of Query Optimization
COST ESTIMATION FOR THE RELATIONAL ALGEBRA OPERATIONS MIT 813 GROUP 15 PRESENTATION.
Chapter 15 QUERY EXECUTION.
Access Path Selection in a Relational Database Management System
JULIE McLAIN-HARPER LINKEDIN: JM HARPER
Query Processing B.Ramamurthy Chapter 12 11/27/2018 B.Ramamurthy.
Practical Database Design and Tuning
Creating Noninput Items
Query Processing CSD305 Advanced Databases.
Chapter 12 Query Processing (1)
Course Instructor: Supriya Gupta Asstt. Prof
Presentation transcript:

Academic Year 2014 Spring

MODULE CC3005NI: Advanced Database Systems “QUERY OPTIMIZATION” Academic Year 2014 Spring

Query Optimization:  Query Optimization is the process of choosing the most efficient way to execute a SQL statement.  When the cost-based optimizer was offered for the first time with Oracle 7, Oracle supported only standard relational data.  Query Optimization is an important component of a modern relational database system.  Relational Database Systems provide a system managed optimization facility by making use of available tools.

Query Optimization:  Description  A Query Optimizer is essentially a program for efficient evaluation of relational queries, making use of relevant statistic information  Objective  To choose the most efficient strategy for implementing a given relational query, thereby improve the efficiency and performance of a relational database system

Need of Query Optimization: 1. To perform automatic navigation:  A relational database system (based on non-navigational relational model) allows users to simply state what data they require and leave system to locate and process that data in database

Need of Query Optimization: 2. To achieve acceptable performance:  There may be different plans (called query plan) to perform a single user query and query optimizer aims to select and execute most efficient query plan based on information available to system

Need of Query Optimization: 3. To minimize existing differences:  Due to existing difference in speed between CPU and I/O devices, a query optimizer aims to minimize I/O activities by choosing ‘cheapest’ query plan for a given query

Effects of Optimization – Example:  Consider following Student, Lending and Book tables:  Student (student_no, student_name, gender, address)  Lending (lending_no, student_no, book_no)  Book (book_no, title, author, edition)

Effects of Optimization – Example  Assume that database tables contains  100 students in Student table  1000 lending in Lending table, of which only 50 are for book ‘B1’  5000 books in Book table  Further assume that only results (intermediate relations) of up to 50 tuples can be kept in memory during query processing

Effects of Optimization – Example:  Query  Retrieve names of students who have borrowed book ‘B1’  SQL  SELECT DISTINCT student_name FROM student, lending WHERE student.student_no = lending.student_no AND lending.book_no = ‘B1’

Query Plan A – No Optimization:  Operation Sequence – Join – Select – Project  Step 1 Join student and lending over student_no giving T1  Step 2 Select T1 where book_no = ‘B1’ giving T2  Step 3 Project T2 over student_name giving result

Query Plan A – No Optimization:  We calculate number of database accesses (tuple I/O operations) required for each item  Number of tuple I/O is described as number of tuples (records) to be read and written during operation

Query Plan A – Calculation:  Step 1 – Join student and lending over student: no giving T1  Step 2 – Select T1 where book_no = ‘B1’ giving T2  Step 3 – Project T2 over student_name giving result IR: Intermediate Relation  Total tuple I/O: 1,02,0000 StepReadWriteIRSubtotal 1100 x 10,00010,000 1,01, , , <= 500

Query Plan B – with Optimization:  Operation Sequence – Select – Join – Project  Step 1 Select lending where book_no = ‘B1’ giving T1  Step 2 Join T1 and student over student_no giving T2  Step 3 Project T2 over student_name giving result

Query Plan B – with Optimization:  We again calculate number of tuple I/O operations required for each step

Query Plan B – Calculation:  Step 1 – Select lending where book_no = ‘B1’ giving T1  Step 2 – Join T1 and student over student_no giving T2  Step 3 – Project T2 over student_name giving result IR: Intermediate Relation  Total tuple I/O: 10,100 StepReadWriteIRSubtotal 110, , <= 500

Comparison Plan A vs. Plan B:  Ratio of I/O tuples (Plan A to Plan B):  1,02,0000 / 10,100  Intermediate relations in Plan B are much smaller than those in Plan A  Tuple I/O can be further reduced by using indexes  If there is an index on book_no in lending table, tuples to be read will be just 50 instead of 10000

Four Stages of Optimization: what how The query processing activity therefore acts as an interface between the querying individual/process and the database. It relieves the querying individual/ process of the burden of deciding the best execution strategy. So while the querying individual/ process specifies what, the query processor determines how.

Four Stages of Optimization:  Stage 1  Convert query into some internal form more suitable for machine manipulation e.g. Query Tree Relational Algebra  Stage 2  Further convert internal form into some equivalent and more efficient Canonical Form making use of well defined transformation rules

Four Stages of Optimization:  Example of Query Tree – Plan A (Join – Select – Project) StudentLending Join Restrict Project Result Over student_no Where book_no = ‘B1’ Over student_name

Four Stages of Optimization:  Stage 3  Choose a set of low-level procedures using statistics about database Low Level Operations (e.g. join, select, project) Implementation procedures (one for each low level operation based on varying conditions) Cost formulae (one for each implementation procedure)

Four Stages of Optimization:  Stage 4  Generate a set of candidate query plans and choose best of those plans by evaluating cost formulae Process of selecting a query plan is also called ‘access path’ selection ‘cheapest’ query plan is normally considered to be one which produces minimum I/O tuple operations and smallest set of intermediate relations

Database Statistics:  Selection of ‘optimal’ query plans in optimization process makes use of database statistics stored in System Catalogue or Data Dictionary of database system  In other words, without this information (meta data) being available, query optimizer will not be able to choose most efficient query plan for implementing a given query

Database Statistics:  Typical Database Statistics include  For each base table Cardinality Number of pages for this tables  For each column of each base table Number of distinct values Maximum, minimum and average value Actual values and their frequencies

Database Statistics:  Typical Database Statistics include (continued)  For each index Number of levels Number of leaf pages

Thank you!!! Questions are WELCOME Academic Year 2014 Spring