M ODULE 4 D ATABASE T UNING Section 3 Application Performance 1 ITEC 450 Fall 2012.

Slides:



Advertisements
Similar presentations
Using the SQL Access Advisor
Advertisements

Youre Smarter than a Database Overcoming the optimizers bad cardinality estimates.
Refreshing Materialized Views
12 Copyright © 2005, Oracle. All rights reserved. Query Rewrite.
Tuning Oracle SQL The Basics of Efficient SQLThe Basics of Efficient SQL Common Sense Indexing The Optimizer –Making SQL Efficient Finding Problem Queries.
Copyright © 2007 Ramez Elmasri and Shamkant B. Navathe Slide
Tuning: overview Rewrite SQL (Leccotech)Leccotech Create Index Redefine Main memory structures (SGA in Oracle) Change the Block Size Materialized Views,
Presented By Akin S Walter-Johnson Ms Principal PeerLabs, Inc
Introduction to SQL Tuning Brown Bag Three essential concepts.
9 Copyright © 2006, Oracle. All rights reserved. Automatic Performance Management.
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.
13 Copyright © 2005, Oracle. All rights reserved. Monitoring and Improving Performance.
Module 13: Performance Tuning. Overview Performance tuning methodologies Instance level Database level Application level Overview of tools and techniques.
Overview of performance tuning strategies Oracle Performance Tuning Allan Young June 2008.
© Bharati Vidyapeeths Institute of Computer Applications and Management, New Delhi © Bharati Vidyapeeths Institute of Computer Applications and.
Database Performance Tuning and Query Optimization
State of Connecticut Core-CT Project Query 8 hrs Updated 6/06/2006.
Creating Tables. 2 home back first prev next last What Will I Learn? List and provide an example of each of the number, character, and date data types.
4 Oracle Data Integrator First Project – Simple Transformations: One source, one target 3-1.
What Happens when a SQL statement is issued?
1 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
EXECUTION PLANS By Nimesh Shah, Amit Bhawnani. Outline  What is execution plan  How are execution plans created  How to get an execution plan  Graphical.
I NTRODUCTION OF W EEK 14  Assignment Discussion  Graded: (Lab4: Query Optimization)  Creating, reviewing, and interpretation are all important.
Agenda Overview of the optimizer How SQL is executed Identifying statements that need tuning Explain Plan Modifying the plan.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Lecture Nine Database Planning, Design, and Administration
Access Path Selection in a Relation Database Management System (summarized in section 2)
Query Processing Presented by Aung S. Win.
Relational Database Performance CSCI 6442 Copyright 2013, David C. Roberts, all rights reserved.
Database System Development Lifecycle © Pearson Education Limited 1995, 2005.
Overview of the Database Development Process
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.
Oracle Database Administration Lecture 6 Indexes, Optimizer, Hints.
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
RBO RIP George Lumpkin Director Product Management Oracle Corporation Session id:
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 Optimization Chap. 19. Evaluation of SQL Conceptual order of evaluation – Cartesian product of all tables in from clause – Rows not satisfying where.
11-1 Improve response time of interactive programs. Improve batch throughput. To ensure scalability of applications load vs. performance. Reduce system.
Physical Database Design Transparencies. ©Pearson Education 2009 Chapter 11 - Objectives Purpose of physical database design. How to map the logical database.
SQL Performance and Optimization l SQL Overview l Performance Tuning Process l SQL-Tuning –EXPLAIN PLANs –Tuning Tools –Optimizing Table Scans –Optimizing.
1 Chapter 10 Joins and Subqueries. 2 Joins & Subqueries Joins – Methods to combine data from multiple tables – Optimizer information can be limited based.
Oracle tuning: a tutorial Saikat Chakraborty. Introduction In this session we will try to learn how to write optimized SQL statements in Oracle 8i We.
Module 4 Database SQL Tuning Section 3 Application Performance.
DATABASE ADMINISTRATION Pertemuan ke-7. Application Performance source : Database Administration the complete guide to practices and procedures chapter.
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.
Query Processing – Query Trees. Evaluation of SQL Conceptual order of evaluation – Cartesian product of all tables in from clause – Rows not satisfying.
Query Optimization CMPE 226 Database Systems By, Arjun Gangisetty
1 Copyright © 2005, Oracle. All rights reserved. Following a Tuning Methodology.
1 Chapter 9 Tuning Table Access. 2 Overview Improve performance of access to single table Explain access methods – Full Table Scan – Index – Partition-level.
DB Tuning : Chapter 10. Optimizer Center for E-Business Technology Seoul National University Seoul, Korea 이상근 Intelligent Database Systems Lab School of.
Sorting and Joining.
8 Copyright © 2005, Oracle. All rights reserved. Gathering Statistics.
Database Systems, 8 th Edition SQL Performance Tuning Evaluated from client perspective –Most current relational DBMSs perform automatic query optimization.
Scott Fallen Sales Engineer, SQL Sentry Blog: scottfallen.blogspot.com.
3 Copyright © 2006, Oracle. All rights reserved. Designing and Developing for Performance.
SAP Tuning 실무 SK㈜ ERP TFT.
11 Copyright © 2009, Oracle. All rights reserved. Enhancing ETL Performance.
Tuning Oracle SQL The Basics of Efficient SQL Common Sense Indexing
Database Performance Tuning &
Choosing Access Path The basic methods.
Methodology – Physical Database Design for Relational Databases
Database Performance Tuning and Query Optimization
Chapter 11 Database Performance Tuning and Query Optimization
Introduction to the Optimizer
Query Processing.
Presentation transcript:

M ODULE 4 D ATABASE T UNING Section 3 Application Performance 1 ITEC 450 Fall 2012

O VERVIEW OF A PPLICATION P ERFORMANCE Application Performance – Developer and DBA Shared Responsibilities Tuning and optimizing SQL statement to maximize an applications performance Ensuring the application interacts with the DBMS appropriately and efficiently. Fall ITEC 450

D ESIGNING A PPLICATIONS FOR D ATABASE For relational database, application design should be for relational access. Type of SQL – planned or not, dynamic or static, embedded or stand-alone Programming language – any features can be explored for database access performance Transaction design and processing Locking strategy Commit strategy Batch processing or Online processing Fall ITEC 450

O VERVIEW OF O PTIMIZER The optimizer is the heart of a DBMS, and is an inference engine responsible for determining the most efficient means of accessing the specified data. Each DBMS also provides techniques that you can use to influence the optimizer perform its job better. The query optimizer performs the following operations for each SQL statement: Evaluation of expressions and conditions Statement transformation Choice of optimizer goals – batch for best throughput, online for best response time Choice of access paths Choice of join orders Fall ITEC 450

O PTIMIZER I NFLUENCE F ACTORS CPU and I/O costs Database statistics – one of DBAs main responsibilities. You can use ANALYZE TABLE in Oracle, or utilities. Query analysis – involved objects and conditions Joins – how to combine the outputs from each table in the most efficient manner Access path choices Full table scans – read all rows and filters out those that do not meet the selection criteria Indexed access – retrieve by traversing the index Rowid scans – fastest way to retrieve a single row, as rowid specifies the datafile, data block and the location of the row in that block Hashed access – access based on a hash value, similar to indexed access Fall ITEC 450

SQL T UNING T IPS SQL tuning is a complicated task that requires a full-length book of its own. KISS principle: Keep It Short and Simple. Retrieve only what is needed Judicious use of LIKE – avoid leading wild-card (%) Beware of code generators – automatically created query statements from a tool can be a nightmare to DBAs Goals for tuning: Reduce the workload – for example to create or use an index Balance the workload – adjust query running time to avoid peak usage Parallelize the workload – for large amounts of data in data warehouse queries Fall ITEC 450

M ODULE 4 D ATABASE T UNING Section 4 Oracle SQL Query Optimization 7 ITEC 450 Fall 2012

O PTIMIZING O RACLE Q UERY P ROCESSING Query processing is the transformation of your SQL statement into an efficient execution plan to return the requested data from the database. Parsing – checking the syntax and semantics of the SQL statements Optimization – using a cost-based optimizer (CBO) to choose the best access method for retrieving data for the tables and indexes referred to in the query Query rewrite – converting into an abstract logical query plan Execution plan generation phase – permutation of various operations, orders, algorithms, etc. Query execution – executing the physical query plan Fall ITEC 450

O RACLE C OST B ASED O PTIMIZER Fall ITEC 450

U NDERSTANDING S TATISTICS Optimizer statistics are a collection of data: Table statistics Number of rows Number of blocks Average row length Column statistics Number of distinct values in column Number of nulls in column Data distribution (histogram) Extended statistics Index statistics Number of leaf blocks Levels Clustering factor System statistics I/O performance and utilization CPU performance and utilization Fall ITEC 450

P ROVIDING S TATISTICS TO THE O PTIMIZER The recommended approach is to allow Oracle database to automatically collect the statistics. The job to collect statistics can be found SQL> select owner, job_name, enabled, state, comments from dba_scheduler_jobs; To check that the statistics are indeed collected SQL> select table_name, last_analyzed, num_rows from dba_tables where owner = 'OE' ; Oracle also collects the statistics on columns SQL> select column_name, num_distinct from dba_tab_col_statistics where owner = 'OE' and table_name = 'PRODUCT_DESCRIPTIONS'; Fall ITEC 450

M ANUALLY G ATHERING S TATISTICS Because the automatic optimizer statistics collection runs during maintenance windows, the statistics on tables which are significantly modified throughout the day may become stale. Volatile tables that are being deleted and rebuilt Objects with large bulk loads Manual Statistics Gathering Using the dbms_stats utility, for example: SQL> exec dbms_stats.gather_schema_stats( - ownname => 'SCOTT', - options => 'GATHER AUTO', - estimate_percent => dbms_stats.auto_sample_size, - method_opt => 'for all columns size repeat', - degree => 34 ) Old-fashion for backward compatibility – Analyze table Fall ITEC 450

E XECUTION P LAN (E XPLAIN P LAN ) A statements execution plan is the sequence of operations Oracle performs to run the statement. The row source tree is the core of the execution plan. It shows the following information: An ordering of the tables referenced by the statement An access method for each table mentioned in the statement A join method for tables affected by join operations in the statement Data operations like filter, sort, or aggregation Fall ITEC 450

R UNNING E XPLAIN P LAN Using autotrace utilities To generate the execution plan only and doesnt execute the query itself SQL> set autotrace on explain To show only the execution statistics for the SQL statement SQL> set autotrace on statistics To show both the execution plan and execution statistics SQL> set autotrace on Using PLAN_TABLE To explain a SQL statement: SQL> EXPLAIN PLAN FOR SELECT last_name FROM employees; This explains the plan into the PLAN_TABLE table. You can then select the execution plan from PLAN_TABLE. Fall ITEC 450

R UNNING E XPLAIN P LAN U SING T OOLS Using Oracle SQL Developer Fall ITEC 450 Using Other Tools TOAD Many Others

E XAMPLE OF E XECUTION P LAN An example of SQL statement SQL> select i.product_id, i.product_name, d.translated_name from oe.product_information i, oe.product_descriptions d where i.product_id = d.product_id and rownum < 5; The execution plan is 0 SELECT STATEMENT Optimizer=ALL_ROWS (Cost=6 Card=4 Bytes=228) 1 0 COUNT (STOPKEY) 2 1 NESTED LOOPS (Cost=6 Card=4 Bytes=228) 3 2 TABLE ACCESS (FULL) OF 'PRODUCT_DESCRIPTIONS' (TABLE)(Cost=2 Card=4 Bytes=148) 4 2 TABLE ACCESS (BY INDEX ROWID) OF 'PRODUCT_INFORMATION (TABLE) (Cost=1 Card=1 Bytes=20) 5 4 INDEX (UNIQUE SCAN) OF 'PRODUCT_INFORMATION_PK' (INDEX (UNIQUE)) (Cost=0 Card=1) Fall ITEC 450

E XECUTION P LAN U SING SQL D EVELOPER Fall ITEC 450

W RAP U P Assignment 3-1-4: Lab4: Query Optimization Creation of execution plans Review and interpretation of execution Analysis of the differences between the two execution plans Clearly presented "Lessons Learned" section Fall ITEC 450