Switch off your Mobiles Phones or Change Profile to Silent Mode.

Slides:



Advertisements
Similar presentations
Query optimisation.
Advertisements

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.
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.
CSCI 5708: Query Processing I Pusheng Zhang University of Minnesota Feb 3, 2004.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
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.
Query Optimization Overview Zachary G. Ives University of Pennsylvania CIS 550 – Database & Information Systems December 2, 2004 Some slide content derived.
©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.
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.
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.
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.
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.
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.
SCUHolliday - COEN 17814–1 Schedule Today: u Query Processing overview.
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.
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.
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.
Query Optimization CMPE 226 Database Systems By, Arjun Gangisetty
Relational Algebra p BIT DBMS II.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Introduction to Query Processing (1) Query optimization: The process of choosing a suitable execution.
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.
CS4432: Database Systems II Query Processing- Part 1 1.
Chiu Luk CS257 Database Systems Principles Spring 2009
CHAPTER 19 Query Optimization. CHAPTER 19 Query Optimization.
Query Processing and Optimization, and Database Tuning
Practical Database Design and Tuning
Query Optimization Heuristic Optimization
Database System Implementation CSE 507
Storage Access Paging Buffer Replacement Page Replacement
UNIT 11 Query Optimization
Database Management System
Secondary Storage Data Retrieval.
Database Performance Tuning and Query Optimization
Overview of Query Optimization
COST ESTIMATION FOR THE RELATIONAL ALGEBRA OPERATIONS MIT 813 GROUP 15 PRESENTATION.
Chapter 15 QUERY EXECUTION.
JULIE McLAIN-HARPER LINKEDIN: JM HARPER
Query Processing B.Ramamurthy Chapter 12 11/27/2018 B.Ramamurthy.
Practical Database Design and Tuning
Query Processing CSD305 Advanced Databases.
Chapter 12 Query Processing (1)
Chapter 11 Database Performance Tuning and Query Optimization
Database Systems (資料庫系統)
Course Instructor: Supriya Gupta Asstt. Prof
Unit 12 Index in Database 大量資料存取方法之研究 Approaches to Access/Store Large Data 楊維邦 博士 國立東華大學 資訊管理系教授.
Presentation transcript:

Switch off your Mobiles Phones or Change Profile to Silent Mode

Query Optimisation

Query Optimisation is an important component of a modern relational database system. Relational Database Systems provide a system managed optimisation facility by making use of a wealth of statistical information (meta data) available to the system

Query Optimisation Description A Query Optimiser 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 for Query Optimisation 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 for Query Optimisation To achieve acceptable performance There may be different plans (called query plan) to perform a single user query and query optimiser aims to select and execute most efficient query plan based on information available to system

Need for Query Optimisation To minimize existing discrepancies Due to existing discrepancy in speed between CPU and I/O devices, a query optimiser aims to minimise I/O activities by choosing ‘cheapest’ query plan for a given query

Effects of Optimisation -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 Optimisation -Example Assume that database tables contains 100 students in Student table 1000 lendings 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 Optimisation -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 Optimisation 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 Optimisation We calculate number of database accesses (tuple I/O operations) required for each stem 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: StepReadWriteIRSubtotal 1100 x <= 500

Query Plan B–With Optimisation 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 Optimisation 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: StepReadWriteIRSubtotal <= 500

Comparison Plan A vs Plan B Ratio of I/O tuples (Plan A to Plan B): / Intermediate relations in Plan B are much smaller than those in Plan A Tuple I/Os 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 Optimisation 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 Optimisation StudentLending Join Restrict Project Result Example of Query Tree – Plan A (Join – Select – Project) Over student no Where book-no = ‘B1’ Over student-name

Four Stages of Optimisation Some Transformation Rules Rule 1 (A where Restrict-1) where Restrict-2 = A (where Restrict-1 AND Restrict-2) Rule 2 A([Project]) where Restrict = (A where Restrict) [Project] Rule 3 (A [Project-1]) [project-2] = A [Project-2] Rule 4 (A join B) where Restrict-on-A AND Restrict-on-B = (A where Restrict-on-A0 Join (B where Restrict-on-B)

Four Stages of Optimisation Rule 5 where p OR (q AND r) = where (p OR q) AND (p OR r) Rule 6 (A Join B) Join C = A Join (B Join C) Rule 7 Perform projects as early as possible Rule 8 Perform restrictions as early as possible

Four Stages of Optimisation Stage 3 Choose a set of candidate 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 Optimisation Stage 4 Generate a set of candidate query plans and choose best (cheapest) 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 optimisation 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 optimiser 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 For each index Number of levels Number of leaf pages

Any Questions?