Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.

Slides:



Advertisements
Similar presentations
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Advertisements

Tuning: overview Rewrite SQL (Leccotech)Leccotech Create Index Redefine Main memory structures (SGA in Oracle) Change the Block Size Materialized Views,
Database Performance Tuning and Query Optimization
Database Performance Tuning and Query Optimization
CS 540 Database Management Systems
Introduction to Structured Query Language (SQL)
CS263 Lecture 19 Query Optimisation.  Motivation for Query Optimisation  Phases of Query Processing  Query Trees  RA Transformation Rules  Heuristic.
Chapter Physical Database Design Methodology Software & Hardware Mapping Logical Design to DBMS Physical Implementation Security Implementation Monitoring.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 8 Advanced SQL.
Physical Database Monitoring and Tuning the Operational System.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Introduction to Structured Query Language (SQL)
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Query Execution Chapter 15 Section 15.1 Presented by Khadke, Suvarna CS 257 (Section II) Id
Chapter 8 Physical Database Design. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Overview of Physical Database.
Chapter 9 Overview  Reasons to monitor SQL Server  Performance Monitoring and Tuning  Tools for Monitoring SQL Server  Common Monitoring and Tuning.
Query Processing Presented by Aung S. Win.
Introduction to Databases Chapter 8: Improving Data Access.
Chapter 11 Database Performance Tuning and Query Optimization
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.
CSC271 Database Systems Lecture # 30.
IT The Relational DBMS Section 06. Relational Database Theory Physical Database Design.
Chapter Oracle Server An Oracle Server consists of an Oracle database (stored data, control and log files.) The Server will support SQL to define.
1 © Prentice Hall, 2002 Physical Database Design Dr. Bijoy Bordoloi.
Database System Concepts, 5th Ed. ©Silberschatz, Korth and Sudarshan See for conditions on re-usewww.db-book.com Chapter 13: Query Processing.
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
Chapter 7 Advanced SQL Database Systems: Design, Implementation, and Management, Sixth Edition, Rob and Coronel.
Physical Database Design Chapter 6. Physical Design and implementation 1.Translate global logical data model for target DBMS  1.1Design base relations.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
Chapter 6 1 © Prentice Hall, 2002 The Physical Design Stage of SDLC (figures 2.4, 2.5 revisited) Project Identification and Selection Project Initiation.
Academic Year 2014 Spring. MODULE CC3005NI: Advanced Database Systems “QUERY OPTIMIZATION” Academic Year 2014 Spring.
Copyright © Curt Hill Query Evaluation Translating a query into action.
Concepts of Database Management Seventh Edition
Chapter 16 Practical Database Design and Tuning Copyright © 2004 Pearson Education, Inc.
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
Physical Database Design Transparencies. ©Pearson Education 2009 Chapter 11 - Objectives Purpose of physical database design. How to map the logical database.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
BTM 382 Database Management Chapter Writing optimized SQL queries Chitu Okoli Associate Professor in Business Technology Management John Molson.
By Shanna Epstein IS 257 September 16, Cnet.com Provides information, tools, and advice to help customers decide what to buy and how to get the.
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
8 1 Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Lecture 1- Query Processing Advanced Databases Masood Niazi Torshiz Islamic Azad university- Mashhad Branch
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
Chapter 8 Physical Database Design. Outline Overview of Physical Database Design Inputs of Physical Database Design File Structures Query Optimization.
Query Optimization CMPE 226 Database Systems By, Arjun Gangisetty
1 Copyright © 2005, Oracle. All rights reserved. Following a Tuning Methodology.
IMS 4212: Database Implementation 1 Dr. Lawrence West, Management Dept., University of Central Florida Physical Database Implementation—Topics.
1 Chapter 9 Tuning Table Access. 2 Overview Improve performance of access to single table Explain access methods – Full Table Scan – Index – Partition-level.
20 Copyright © 2008, Oracle. All rights reserved. Cache Management.
CS 540 Database Management Systems
Oracle9i Developer: PL/SQL Programming Chapter 11 Performance Tuning.
Chapter 13: Query Processing
Database Systems, 8 th Edition SQL Performance Tuning Evaluated from client perspective –Most current relational DBMSs perform automatic query optimization.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
Practical Database Design and Tuning
Table General Guidelines for Better System Performance
Database Management System
Database Systems: Design, Implementation, and Management Tenth Edition
Database Performance Tuning &
Chapter 12: Query Processing
Database Performance Tuning and Query Optimization
Chapter 15 QUERY EXECUTION.
Practical Database Design and Tuning
Table General Guidelines for Better System Performance
Chapter 8 Advanced SQL.
Chapter 11 Database Performance Tuning and Query Optimization
Presentation transcript:

Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization

Database Systems, 8 th Edition 2 Objectives In this chapter, you will learn: –Basic database performance-tuning concepts –How a DBMS processes SQL queries –About the importance of indexes in query processing –About the types of decisions the query optimizer has to make –Some common practices used to write efficient SQL code –How to formulate queries and tune the DBMS for optimal performance

Database Systems, 8 th Edition 3 Database Performance-Tuning Concepts Goal of database performance is to execute queries as fast as possible Database performance tuning –Set of activities and procedures designed to reduce response time of database system All factors must operate at optimum level with minimal bottlenecks Good database performance starts with good database design

Database Systems, 8 th Edition 4

5 Performance Tuning: Client and Server Database performance-tuning activities can be divided into: –Client side Generate SQL query that returns correct answer in least amount of time Using minimum amount of resources at server SQL performance tuning –Server side DBMS environment configured to respond to clients’ requests as fast as possible Optimum use of existing resources DBMS performance tuning

Database Systems, 8 th Edition 6 DBMS Architecture All data in database are stored in data files Data files –Automatically expand in predefined increments known as extends –Grouped in file groups or table spaces Table space or file group: –Logical grouping of several data files that store data with similar characteristics

Database Systems, 8 th Edition 7

8 DBMS Architecture (continued) Data cache or buffer cache: shared, reserved memory area –Stores most recently accessed data blocks in RAM SQL cache or procedure cache: stores most recently executed SQL statements –Also PL/SQL procedures DBMS retrieves data from permanent storage and places it in RAM

Database Systems, 8 th Edition 9 DBMS Architecture (continued) Input/output request: low-level data access operation to/from computer devices Data cache is faster than data in data files –DBMS does not wait for hard disk to retrieve data Majority of performance-tuning activities focus on minimizing I/O operations Typical DBMS processes: –Listener, User, Scheduler, Lock manager, Optimizer

Database Systems, 8 th Edition 10 Database Statistics Measurements about database objects and available resources –Tables –Indexes –Number of processors used –Processor speed –Temporary space available

Database Systems, 8 th Edition 11 Database Statistics (continued) Make critical decisions about improving query processing efficiency Can be gathered manually by DBA or automatically by DBMS Example: ANALYZE object name COMPUTE STATISTICS.

Database Systems, 8 th Edition 12 Query Processing DBMS processes queries in three phases –Parsing DBMS parses the query and chooses the most efficient access/execution plan –Execution DBMS executes the query using chosen execution plan –Fetching DBMS fetches the data and sends the result back to the client

Database Systems, 8 th Edition 13

Database Systems, 8 th Edition 14 SQL Parsing Phase Break down query into smaller units Transform original SQL query into slightly different version of original SQL code –Fully equivalent Optimized query results are always the same as original query –More efficient Optimized query will almost always execute faster than original query

Database Systems, 8 th Edition 15 SQL Parsing Phase (continued) Query optimizer analyzes SQL query and finds most efficient way to access data –Validated for syntax compliance –Validated against data dictionary Tables, column names are correct User has proper access rights –Analyzed and decomposed into components –Optimized –Prepared for execution

Database Systems, 8 th Edition 16 SQL Parsing Phase (continued) Access plans are DBMS-specific –Translate client’s SQL query into series of complex I/O operations –Required to read the data from the physical data files and generate result set DBMS checks if access plan already exists for query in SQL cache DBMS reuses the access plan to save time If not, optimizer evaluates various plans –Chosen plan placed in SQL cache

Database Systems, 8 th Edition 17

Database Systems, 8 th Edition 18 SQL Execution Phase SQL Fetching Phase All I/O operations indicated in access plan are executed –Locks acquired –Data retrieved and placed in data cache –Transaction management commands processed Rows of resulting query result set are returned to client DBMS may use temporary table space to store temporary data

Database Systems, 8 th Edition 19 Query Processing Bottlenecks Delay introduced in the processing of an I/O operation that slows the system –CPU –RAM –Hard disk –Network –Application code

Database Systems, 8 th Edition 20 Indexes and Query Optimization Indexes –Crucial in speeding up data access –Facilitate searching, sorting, and using aggregate functions as well as join operations –Ordered set of values that contains index key More efficient to use index to access table than to scan all rows in table sequentially

Database Systems, 8 th Edition 21

Database Systems, 8 th Edition 22 Optimizer Choices Rule-based optimizer –Uses set of preset rules and points to determine best approach to execute query Cost-based optimizer –Algorithms based on statistics about objects being accessed –Adds up processing cost, I/O costs, resource costs to derive total cost

Database Systems, 8 th Edition 23

Database Systems, 8 th Edition 24 SQL Performance Tuning Evaluated from client perspective –Most current relational DBMSs perform automatic query optimization at the server end –Most SQL performance optimization techniques are DBMS-specific Rarely portable Majority of performance problems related to poorly written SQL code Carefully written query usually outperforms a poorly written query

Database Systems, 8 th Edition 25 Index Selectivity Indexes are used when: –Indexed column appears by itself in search criteria of WHERE or HAVING clause –Indexed column appears by itself in GROUP BY or ORDER BY clause –MAX or MIN function is applied to indexed column –Data sparsity is high Measure of how likely an index will be used

Database Systems, 8 th Edition 26 Index Selectivity (continued) General guidelines for indexes: –Create indexes for each attribute in WHERE, HAVING, ORDER BY, or GROUP BY clause –Do not use in small tables or tables with low sparsity –Declare primary and foreign keys so optimizer can use indexes in join operations –Declare indexes in join columns other than PK/FK

Database Systems, 8 th Edition 27 Conditional Expressions Normally expressed within WHERE or HAVING clauses of SQL statement Restricts output of query to only rows matching conditional criteria

Database Systems, 8 th Edition 28 Conditional Expressions (continued) Common practices for efficient SQL: –Use simple columns or literals in conditionals Avoid using expressions –Numeric field comparisons are faster –Equality comparisons faster than inequality –Transform conditional expressions to use literals P_PRICE − 10 = 7, change it to read P_PRICE = 17 –Write equality conditions first Change P_QOH < P_MIN AND P_MIN = P_REORDER AND P_QOH = 10 To P_QOH = 10 AND P_MIN = P_REORDER AND P_MIN > 10 –AND: Use condition most likely to be false first –OR: Use condition most likely to be true first –Avoid NOT

Database Systems, 8 th Edition 29 Query Formulation Identify what columns and computations are required Identify source tables Determine how to join tables Determine what selection criteria is needed Determine in what order to display output

Database Systems, 8 th Edition 30 DBMS Performance Tuning Includes managing the DBMS processes in primary memory (allocating memory for caching purposes) and managing the structures in physical storage (allocating space for the data files). DBMS performance tuning at server end focuses on setting parameters used for: –Data cache –SQL cache –Sort cache –Optimizer mode

Database Systems, 8 th Edition 31 Query Optimization Example Example illustrates how query optimizer works Based on QOVENDOR and QOPRODUCT tables Uses Oracle SQL*Plus

Database Systems, 8 th Edition 32

Database Systems, 8 th Edition 33

Database Systems, 8 th Edition 34

Database Systems, 8 th Edition 35

Database Systems, 8 th Edition 36

Database Systems, 8 th Edition 37

Database Systems, 8 th Edition 38

Database Systems, 8 th Edition 39

Database Systems, 8 th Edition 40