Chapter 11 Database Performance Tuning and Query Optimization

Slides:



Advertisements
Similar presentations
Tuning: overview Rewrite SQL (Leccotech)Leccotech Create Index Redefine Main memory structures (SGA in Oracle) Change the Block Size Materialized Views,
Advertisements

Database Performance Tuning and Query Optimization
Module 13: Performance Tuning. Overview Performance tuning methodologies Instance level Database level Application level Overview of tools and techniques.
Database Performance Tuning and Query Optimization
CS 540 Database Management Systems
EXECUTION PLANS By Nimesh Shah, Amit Bhawnani. Outline  What is execution plan  How are execution plans created  How to get an execution plan  Graphical.
CS263 Lecture 19 Query Optimisation.  Motivation for Query Optimisation  Phases of Query Processing  Query Trees  RA Transformation Rules  Heuristic.
Query Processing (overview)
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Transaction Management and Concurrency Control.
Physical Database Monitoring and Tuning the Operational System.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Chapter 8 Physical Database Design. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Overview of Physical Database.
Transaction Management and Concurrency Control
Client/Server Databases and the Oracle 10g Relational Database
Introduction to Databases Chapter 8: Improving Data Access.
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.
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 Physical Data Organization and Indexing Lecture 14.
1 © Prentice Hall, 2002 Physical Database Design Dr. Bijoy Bordoloi.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
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.
Database Management 9. course. Execution of queries.
Query optimization in relational DBs Leveraging the mathematical formal underpinnings of the relational model.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
©Silberschatz, Korth and Sudarshan13.1Database System Concepts Chapter 13: Query Processing Overview Measures of Query Cost Selection Operation Sorting.
Chapter 6 1 © Prentice Hall, 2002 The Physical Design Stage of SDLC (figures 2.4, 2.5 revisited) Project Identification and Selection Project Initiation.
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 Processing. Steps in Query Processing Validate and translate the query –Good syntax. –All referenced relations exist. –Translate the SQL to relational.
Advanced SQL Advanced SQL Complex Queries, Joining Tables.
1 CS 430 Database Theory Winter 2005 Lecture 16: Inside a DBMS.
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.
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.
Indexes / Session 2/ 1 of 36 Session 2 Module 3: Types of Indexes Module 4: Maintaining Indexes.
Lecture 1- Query Processing Advanced Databases Masood Niazi Torshiz Islamic Azad university- Mashhad Branch
Chapter 8 Advanced SQL Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
SQL/Lesson 7/Slide 1 of 32 Implementing Indexes Objectives In this lesson, you will learn to: * Create a clustered index * Create a nonclustered index.
Physical Database Design Purpose- translate the logical description of data into the technical specifications for storing and retrieving data Goal - create.
Introduction.  Administration  Simple DBMS  CMPT 454 Topics John Edgar2.
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.
CS 440 Database Management Systems Lecture 5: Query Processing 1.
CS 540 Database Management Systems
CS 540 Database Management Systems
for all Hyperion video tutorial/Training/Certification/Material Essbase Optimization Techniques by Amit.
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.
Execution Plans Detail From Zero to Hero İsmail Adar.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
CS 440 Database Management Systems
Database Management System
Physical Database Design
Database Performance Tuning &
Chapter 12: Query Processing
Database Performance Tuning and Query Optimization
Physical Database Design
Chapter 11 Database Performance Tuning and Query Optimization
Evaluation of Relational Operations: Other Techniques
Presentation transcript:

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

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 Performance tuning in SQL Server 2005 Database Systems, 8th Edition

11.1 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, 8th Edition

Database Systems, 8th Edition

Performance Tuning: Client and Server 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, 8th Edition

DBMS Architecture All data in database are stored in 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, 8th Edition

Basic DBMS architecture Database Systems, 8th Edition

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, including triggers and functions DBMS retrieves data from permanent storage and places it in RAM Database Systems, 8th Edition

DBMS Architecture (continued) Input/output request: low-level data access operation to/from computer devices, such as memory, hard disks, videos, and printers 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, 8th Edition

Database Statistics Measurements about database objects and available resources Tables, Indexes, Number of processors used, Processor speed, Temporary space available Make critical decisions about improving query processing efficiency Can be gathered manually by DBA or automatically by DBMS UPDATE STATISTICS table_name [index_name] Auto-Update and Auto-Create Statistics option 資料庫屬性 -> 自動更新統計資料 資料庫屬性 -> 自動建立統計資料 Database Systems, 8th Edition

Database Systems, 8th Edition

Ch08: dbcc show_statistics (customer, PK__CUSTOMER__24927208 ) Ch08: dbcc show_statistics (customer, CUS_UI1) 補充 SQL Server 2005 Database Systems, 8th Edition

11.2 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, 8th Edition

Query Processing Database Systems, 8th Edition

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, 8th Edition

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 more atomic components Optimized through transforming into a fully equivalent but more efficient SQL query Prepared for execution by determining the execution or access plan Database Systems, 8th Edition

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, 8th Edition

Database Systems, 8th Edition

SQL Execution and 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 The server may send only the first 100 rows of 9000 rows Database Systems, 8th Edition

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, 8th Edition

SQL 敘述輸入完成後先不要執行查詢, 請按下工具列的顯示估計執行計劃鈕 : Database Systems, 8th Edition

11.3 Indexes and Query Optimization 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 and pointers More efficient to use index to access table than to scan all rows in table sequentially Database Systems, 8th Edition

Indexes and Query Optimization Data sparsity: number of different values a column could possibly have Indexes implemented using: (課本 p. 453) Hash indexes B-tree indexes: most common index type. Used in tables in which column values repeat a small number of times. The leaves contain pointers to records It is self-balanced. Bitmap indexes: 0/1 DBMSs determine best type of index to use Ex: CUST_LNAME with B-tree and REGION_CODE with Bitmap indexes Database Systems, 8th Edition

B-tree and bitmap index representation Database Systems, 8th Edition B-tree and bitmap index representation

Index Representation for the CUSTOMER table SELECT CUS_NAME FROM CUSTOMER WHERE CUS_STATE=‘FL’ Requires only 5 accesses to STATE_INDEX, 5 accesses to CUSTOMER Index Representation for the CUSTOMER table

11.4 Optimizer Choices Rule-based optimizer Cost-based optimizer Preset rules and points Rules assign a fixed cost to each operation 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, 8th Edition

Example With the following database statistics: SELECT P_CODE, P_DESCRIPT, P_PRICE, V_NAME, V_STATE FROM PRODUCT P, VENDOR V WHERE P.V_CODE=V.V_CODE AND V.V_STATE=‘FL’; With the following database statistics: The PRODUCT table has 7000 rows The VENDOR table has 300 rows 10 vendors come from Florida 1000 products come from vendors in Florida Database Systems, 8th Edition

Database Systems, 8th Edition

Example Assume the PRODUCT table has the index PQOH_NDX in the P_QOH attribute SELECT MIN(P_QOH) FROM PRODUCT could be resolved by reading only the first entry in the PQOH_NDX index Database Systems, 8th Edition

Using Hints to Affect Optimizer Choices Optimizer might not choose best plan Makes decisions based on existing statistics Statistics may be old Might choose less efficient decisions Optimizer hints: special instructions for the optimizer embedded in the SQL command text Database Systems, 8th Edition

Oracle 版本 Database Systems, 8th Edition

SQL Server Query Hints Example select o.customerid,companyname from orders as o inner MERGE join customers as c on o.customerid = c.customerid from orders as o inner HASH join customers as c  select o.customerid,companyname from orders as o inner LOOP join customers as c select city, count(*) from customers group by city OPTION (HASH GROUP)   MS SQL Server 的語法請參考: http://msdn.microsoft.com/en-us/library/ms187713.aspx Database Systems, 8th Edition