Database Systems, 8 th Edition 1 11.5 SQL Performance Tuning Evaluated from client perspective –Most current relational DBMSs perform automatic 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
Chapter 9. Performance Management Enterprise wide endeavor Research and ascertain all performance problems – not just DBMS Five factors influence DB performance.
Database Performance Tuning and Query Optimization
Chapter 10: Designing Databases
Database Systems: Design, Implementation, and Management Tenth Edition
Introduction to Structured Query Language (SQL)
XP Chapter 3 Succeeding in Business with Microsoft Office Access 2003: A Problem-Solving Approach 1 Analyzing Data For Effective Decision Making.
Chapter Physical Database Design Methodology Software & Hardware Mapping Logical Design to DBMS Physical Implementation Security Implementation Monitoring.
Introduction to Structured Query Language (SQL)
IS 4420 Database Fundamentals Chapter 6: Physical Database Design and Performance Leon Chen.
Physical Database Monitoring and Tuning the Operational System.
© 2005 by Prentice Hall 1 Chapter 6: Physical Database Design and Performance Modern Database Management 7 th Edition Jeffrey A. Hoffer, Mary B. Prescott,
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.
1 Chapter 2 Reviewing Tables and Queries. 2 Chapter Objectives Identify the steps required to develop an Access application Specify the characteristics.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 7 Introduction to Structured Query Language (SQL)
Chapter 8 Physical Database Design. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Overview of Physical Database.
Microsoft Access 2010 Chapter 7 Using SQL.
Chapter 9 Overview  Reasons to monitor SQL Server  Performance Monitoring and Tuning  Tools for Monitoring SQL Server  Common Monitoring and Tuning.
Chapter 6: Physical Database Design and Performance
ASP.NET Programming with C# and SQL Server First Edition
Chapters 17 & 18 Physical Database Design Methodology.
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.
Chapter 3 Single-Table Queries
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
IT The Relational DBMS Section 06. Relational Database Theory Physical Database Design.
PowerPoint Presentation for Dennis & Haley Wixom, Systems Analysis and Design, 2 nd Edition Copyright 2003 © John Wiley & Sons, Inc. All rights reserved.
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
TM 7-1 Copyright © 1999 Addison Wesley Longman, Inc. Physical Database Design.
Physical Database Design Chapter 6. Physical Design and implementation 1.Translate global logical data model for target DBMS  1.1Design base relations.
Analyzing Data For Effective Decision Making Chapter 3.
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.
Discovering Computers Fundamentals Fifth Edition Chapter 9 Database Management.
1 Single Table Queries. 2 Objectives  SELECT, WHERE  AND / OR / NOT conditions  Computed columns  LIKE, IN, BETWEEN operators  ORDER BY, GROUP BY,
Concepts of Database Management Seventh Edition
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
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.
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
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 Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
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.
SqlExam1Review.ppt EXAM - 1. SQL stands for -- Structured Query Language Putting a manual database on a computer ensures? Data is more current Data is.
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
Last Updated : 27 th April 2004 Center of Excellence Data Warehousing Group Teradata Performance Optimization.
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.
A Guide to SQL, Eighth Edition Chapter Four Single-Table Queries.
Oracle9i Developer: PL/SQL Programming Chapter 11 Performance Tuning.
3 Copyright © 2006, Oracle. All rights reserved. Designing and Developing for Performance.
1 Agenda TMA02 M876 Block 4. 2 Model of database development data requirements conceptual data model logical schema schema and database establishing requirements.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
Table General Guidelines for Better System Performance
Database Systems: Design, Implementation, and Management Tenth Edition
Database Performance Tuning &
Database Performance Tuning and Query Optimization
CHAPTER 5: PHYSICAL DATABASE DESIGN AND PERFORMANCE
Physical Database Design
Table General Guidelines for Better System Performance
Chapter 8 Advanced SQL.
Chapter 11 Database Performance Tuning and Query Optimization
Presentation transcript:

Database Systems, 8 th Edition 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 2 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 on indexed column is high Index selectivity is a measure of how likely an index will be used in query processing

Database Systems, 8 th Edition 3 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 4 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 5 Common practices for efficient SQL: –Use simple columns or literals in conditionals Avoid functions –Numeric field comparisons are faster than character, date, and NULL comparisons –Equality comparisons faster than inequality —the slowest is “LIKE” comparison –Transform conditional expressions to use literals –Write equality conditions first –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 Query Formulation Identify what columns and computations are required (p.459) –Expressions –Aggregate functions –Granularity of raw required Identify source tables Determine how to join tables Determine what selection criteria is needed –Simple comparison? IN? Nested Comparison? HAVING Determine in what order to display output

Database Systems, 8 th Edition DBMS Performance Tuning Includes managing DBMS processes in primary memory and structures in physical storage 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

Database Systems, 8 th Edition 8 DBMS Performance Tuning 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 with the following table spaces: system table, user table, index table, temporary table, rollback segment table –Put high-usage tables in their own table spaces –Assign separate data files in separate storage volumes for indexes, system, high-usage tables

Database Systems, 8 th Edition 9 DBMS Performance Tuning Some general recommendations for creation of databases: (continued) –Take advantage of table storage organizations in database An indexed organized table stores the end user table and the index table in consecutive locations on permanent storage –Partition tables based on usage –Use denormalized tables where appropriate –Store computed and aggregate attributes in tables

Database Systems, 8 th Edition 10 Common RAID Configurations

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

Database Systems, 8 th Edition 12 請參考以下 SQL Server 的講義

Database Systems, 8 th Edition 13

Database Systems, 8 th Edition 14 Check the differences in query plan: 1.Before UPDATE STATISTICS QOVENDOR 2.After UPDATE STATISTICS QOVENDOR 3. CREATE INDEX QOV_NDX1 on QOVENDOR (V_AREACODE) UPDATE STATISTICS QOVENDOR 4. CREATE INDEX QOV_NDX2 on QOVENDOR (V_NAME) UPDATE STATISTICS QOVENDOR

Database Systems, 8 th Edition 15

Database Systems, 8 th Edition 16

Database Systems, 8 th Edition 17

Database Systems, 8 th Edition 18

Database Systems, 8 th Edition 19 Check the differences in query plan: 1.Before UPDATE STATISTICS QOPRODUCT 2.After UPDATE STATISTICS QOPRODUCT 3. CREATE INDEX QOP_NDX2 ON QOPRODUCT(P_PRICE) UPDATE STATISTICS QOPRODUCT

Database Systems, 8 th Edition 20 Summary Database performance tuning –Refers to activities to ensure query is processed in minimum amount of time SQL performance tuning –Refers to activities on client side to generate SQL code Returns correct answer in least amount of time Uses minimum amount of resources at server end DBMS architecture represented by processes and structures used to manage a database

Database Systems, 8 th Edition 21 Summary (continued) Database statistics refers to measurements gathered by the DBMS –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

Database Systems, 8 th Edition 22 Summary (continued) During query optimization, DBMS chooses: –Indexes to use, how to perform join operations, table to use first, etc. Hints change optimizer mode for current SQL statement SQL performance tuning deals with writing queries that make good use of statistics Query formulation deals with translating business questions into specific SQL code