Database Performance Tuning and Query Optimization

Slides:



Advertisements
Similar presentations
Using the SQL Access Advisor
Advertisements

Numbers Treasure Hunt Following each question, click on the answer. If correct, the next page will load with a graphic first – these can be used to check.
Variations of the Turing Machine
Chapter 13: Query Processing
AP STUDY SESSION 2.
Advanced SQL Topics Edward Wu.
1
Chapter 7 Constructors and Other Tools. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 7-2 Learning Objectives Constructors Definitions.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
1 Copyright © 2013 Elsevier Inc. All rights reserved. Chapter 4 Computing Platforms.
Processes and Operating Systems
Chapter 6 File Systems 6.1 Files 6.2 Directories
1 Chapter 11 I/O Management and Disk Scheduling Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and.
1 Chapter 12 File Management Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles,
Programming Language Concepts
1 Advanced Tools for Account Searches and Portfolios Dawn Gamache Cindy Bylander.
1 Click here to End Presentation Software: Installation and Updates Internet Download CD release NACIS Updates.
1.
Break Time Remaining 10:00.
Table 12.1: Cash Flows to a Cash and Carry Trading Strategy.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
13 Copyright © 2005, Oracle. All rights reserved. Monitoring and Improving Performance.
Database Performance Tuning and Query Optimization
PP Test Review Sections 6-1 to 6-6
Chapter 10: Applications of Arrays and the class vector
1 IMDS Tutorial Integrated Microarray Database System.
Normalization of Database Tables
Introduction to Structured Query Language (SQL)
Microsoft Confidential. We look at the world... with our own eyes...
Displaying Data from Multiple Tables
EIS Bridge Tool and Staging Tables September 1, 2009 Instructor: Way Poteat Slide: 1.
Bellwork Do the following problem on a ½ sheet of paper and turn in.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 24.1 Test-Driving the Ticket Information Application.
Operating Systems Operating Systems - Winter 2010 Chapter 3 – Input/Output Vrije Universiteit Amsterdam.
Exarte Bezoek aan de Mediacampus Bachelor in de grafische en digitale media April 2014.
Chapter 6 File Systems 6.1 Files 6.2 Directories
Sample Service Screenshots Enterprise Cloud Service 11.3.
Copyright © 2012, Elsevier Inc. All rights Reserved. 1 Chapter 7 Modeling Structure with Blocks.
Adding Up In Chunks.
1 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt 10 pt 15 pt 20 pt 25 pt 5 pt Synthetic.
GEtServices Services Training For Suppliers Requests/Proposals.
1 hi at no doifpi me be go we of at be do go hi if me no of pi we Inorder Traversal Inorder traversal. n Visit the left subtree. n Visit the node. n Visit.
Types of selection structures
Chapter 12: Designing Databases
Chapter 12 Working with Forms Principles of Web Design, 4 th Edition.
Essential Cell Biology
Chapter 8 Estimation Understandable Statistics Ninth Edition
Clock will move after 1 minute
PSSA Preparation.
Chapter 11 Creating Framed Layouts Principles of Web Design, 4 th Edition.
Chapter 13 The Data Warehouse
Chapter 13 Web Page Design Studio
Physics for Scientists & Engineers, 3rd Edition
Energy Generation in Mitochondria and Chlorplasts
Select a time to count down from the clock above
Management Information Systems, 10/e
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 11 Database Performance Tuning and Query Optimization
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.
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
Database Systems, 8 th Edition SQL Performance Tuning Evaluated from client perspective –Most current relational DBMSs perform automatic query optimization.
Table General Guidelines for Better System Performance
Database Performance Tuning &
Database Performance Tuning and Query Optimization
Table General Guidelines for Better System Performance
Chapter 11 Database Performance Tuning and Query Optimization
Presentation transcript:

Database Performance Tuning and Query Optimization Chapter 11 Database Performance Tuning and Query Optimization Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel

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

In this chapter, you will learn (continued): Some common practices used to write efficient SQL code How to formulate queries and tune the DBMS for optimal performance

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

Database Performance-Tuning Concepts (continued)

Database Performance-Tuning Concepts (continued) All factors must be checked to ensure that each one operates at its optimum level and has sufficient resources to minimize occurrence of bottlenecks Good database performance starts with good database design

Performance Tuning: Client and Server Database performance-tuning activities can be divided into: Client side Objective is to generate SQL query that returns correct answer in least amount of time, using minimum amount of resources at server end SQL performance tuning Server side DBMS environment must be properly configured to respond to clients’ requests in fastest way possible, while making optimum use of existing resources DBMS performance tuning

DBMS Architecture All data in database are stored in data files Automatically expand in predefined increments known as extends Generally grouped in file groups of table spaces Table space or file group is logical grouping of several data files that store data with similar characteristics

DBMS Architecture (continued)

DBMS Architecture (continued) DBMS retrieve data from permanent storage and place it in RAM Data cache or buffer cache is shared, reserved memory area that stores most recently accessed data blocks in RAM SQL cache or procedure cache is shared, reserved memory area that stores most recently executed SQL statements or PL/SQL procedures, including triggers and functions

DBMS Architecture (continued) An input/output request is low-level (read or write) data access operation to/from computer devices Working with data in data cache is many times faster than working with data in data files because DBMS doesn’t have to wait for hard disk to retrieve data Majority of performance-tuning activities focus on minimizing number of I/O operations

Database Statistics Refers to number of 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

Database Statistics (continued)

11.2 Query Processing DBMS processes queries in three phases Parsing (剖析): The DBMS parses the SQL query and chooses the most efficient access/execution plan Execution: The DBMS executes the SQL query, using the chosen execution plan Fetching: The DBMS fetches the data and sends the result set back to the client

SQL Parsing Phase Breaking down (parsing) query into smaller units and transforming 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

SQL Parsing Phase (continued)

SQL Parsing Phase (continued) Query optimizer analyzes SQL query and finds most efficient way to access data Access plans are DBMS-specific and 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

SQL Parsing Phase (continued)

SQL Execution Phase SQL Fetching Phase All I/O operations indicated in access plan are executed SQL Fetching Phase Rows of resulting query result set are returned to client DBMS may use temporary table space to store temporary data

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 Data sparsity determines whether index is needed

Indexes and Query Optimization (continued)

11.4 Optimizer Choices Rule-based optimizer Cost-based optimizer Uses set of preset rules and points to determine best approach to execute query Cost-based optimizer Uses sophisticated algorithms based on statistics about objects being accessed to determine best approach to execute query

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

Optimizer Choices (continued)

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

Using Hints to Affect Optimizer Choices Oracle 版本 SQL Server 2005 的語法請參考: http://geeks.netindonesia.net/blogs/kasim.wirama/archive/2007/12/31/sql-server-2005-query-hints.aspx http://download.microsoft.com/download/1/3/4/134644FD-05AD-4EE8-8B5A-0AED1C18A31E/Forcing_Query_Plans.doc

11.5 SQL Performance Tuning Evaluated from client perspective Most current-generation relational DBMSs perform automatic query optimization at the server end Most SQL performance optimization techniques are DBMS-specific and are rarely portable

Index Selectivity Indexes are likely used when: Index Selectivity 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 on indexed column is high Index Selectivity Measure of how likely an index will be used

Index Selectivity (continued) General guidelines for creating and using 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

Conditional Expressions Normally expressed within WHERE or HAVING clauses of SQL statement Restricts output of query to only rows matching conditional criteria

Common Practices to write efficient Conditional Expressions Use simple columns or literals as operands in a conditional expression – avoid functions Numeric field comparisons are faster than character, date, and NULL comparisons Equality comparisons are faster than inequality comparisons—the slowest is “LIKE” comparison Transform conditional expressions to use literals Write equality conditions first For multiple AND (OR) conditions, write the condition most likely to be false (true) first Avoid the use of NOT logical operator

11.6 Query Formulation Identify what columns and computations are required Check simple expressions, aggregate functions, granularity of the raw data Identify source tables Determine how to join tables Determine what selection criteria is needed Check simple comparisons, single value to multiple values, nested comparisons, grouped data selection Determine in what order to display output

11.7 DBMS Performance Tuning Includes global tasks such as managing DBMS processes in primary memory and structures in physical storage Includes applying several practices examined in previous section DBMS performance tuning at server end focuses on setting parameters used for: Data cache: large enough SQL cache: same query may be submitted by many users Sort cache Optimizer mode

DBMS Performance Tuning (continued) Some general recommendations for creation of databases: Use RAID (Redundant Array of Independent Disks) to provide balance between performance and fault tolerance Minimize disk contention At least the following table spaces: system table space, user data table space, index table space, temporary table space, rollback segment table space Put high-usage tables in their own table spaces

DBMS Performance Tuning (continued) Assign separate data files in separate storage volumes for indexes, system, and high-usage tables Partition tables based on usage Use denormalized tables where appropriate Store computed and aggregate attributes in tables

DBMS Performance Tuning (continued)

11.8 Query Optimization Example (跳過) 請參考 SQL Server 版本

Query Optimization Example 請參考 SQL Server 版本

Query Optimization Example 請參考 SQL Server 版本

Query Optimization Example 請參考 SQL Server 版本

Query Optimization Example 請參考 SQL Server 版本

Query Optimization Example 請參考 SQL Server 版本

Query Optimization Example 請參考 SQL Server 版本

Query Optimization Example 請參考 SQL Server 版本

Query Optimization Example 請參考 SQL Server 版本

Summary Database performance tuning SQL performance tuning Refers to set of activities and procedures designed to ensure that end-user query is processed by DBMS in minimum amount of time SQL performance tuning Refers to activities on client side designed to generate SQL code that returns correct answer in least amount of time, using minimum amount of resources at server end

Summary (continued) DBMS performance tuning refers to activities on server side oriented to ensure that DBMS is properly configured to respond to clients’ requests in fastest way possible while making optimum use of existing resources DBMS architecture is represented by many processes and structures (in memory and in permanent storage) used to manage a database

Summary (continued) Database statistics refers to a number of measurements gathered by the DBMS that describe snapshot of database objects’ characteristics DBMS processes queries in three phases: Parsing, Execution and Fetching Indexes are crucial in process that speeds up data access

Summary (continued) During query optimization, DBMS must choose what indexes to use, how to perform join operations, what table to use first, and so on Hints are used to change optimizer mode for current SQL statement SQL performance tuning deals with writing queries that make good use of statistics

Summary (continued) Query formulation deals with how to translate business questions into specific SQL code to generate required results DBMS performance tuning includes tasks such as managing DBMS processes in primary memory and structures in physical storage