11-1 Improve response time of interactive programs. Improve batch throughput. To ensure scalability of applications load vs. performance. Reduce system.

Slides:



Advertisements
Similar presentations
Tuning Oracle SQL The Basics of Efficient SQLThe Basics of Efficient SQL Common Sense Indexing The Optimizer –Making SQL Efficient Finding Problem Queries.
Advertisements

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
Understanding SQL Server Query Execution Plans
Copyright © SoftTree Technologies, Inc. DB Tuning Expert.
SQL Tuning Briefing Null is not equal to null but null is null.
Chapter 9. Performance Management Enterprise wide endeavor Research and ascertain all performance problems – not just DBMS Five factors influence DB performance.
Module 13: Performance Tuning. Overview Performance tuning methodologies Instance level Database level Application level Overview of tools and techniques.
M ODULE 4 D ATABASE T UNING Section 3 Application Performance 1 ITEC 450 Fall 2012.
© Bharati Vidyapeeths Institute of Computer Applications and Management, New Delhi © Bharati Vidyapeeths Institute of Computer Applications and.
1 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
Finding the Performance Bottlenecks in Your Application Ian Jones and Roger Schrag Database Specialists, Inc. IOUG-A Live! 1999 Paper.
INTRODUCTION TO ORACLE Lynnwood Brown System Managers LLC Performance And Tuning – Lecture 7 Copyright System Managers LLC 2007 all rights reserved.
Agenda Overview of the optimizer How SQL is executed Identifying statements that need tuning Explain Plan Modifying the plan.
David Konopnicki Choosing Access Path ä The basic methods. ä The access paths and when they are available. ä How the optimizer chooses among the.
Virtual techdays INDIA │ 9-11 February 2011 SQL 2008 Query Tuning Praveen Srivatsa │ Principal SME – StudyDesk91 │ Director, AsthraSoft Consulting │ Microsoft.
Query Optimization 3 Cost Estimation R&G, Chapters 12, 13, 14 Lecture 15.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Optimization Exercises. Question 1 How do you think the following query should be computed? What indexes would you suggest to use? SELECT E.ename, D.mgr.
Top tips for Oracle SQL tuning Guy Harrison Senior Software Architect, Quest Software BUY QUEST PRODUCTS BUY GUY’S BOOK BUY QUEST PRODUCTS.
AN INTRODUCTION TO EXECUTION PLAN OF QUERIES These slides have been adapted from a presentation originally made by ORACLE. The full set of original slides.
ORACLE ONLINE TRAINING Contact our Support Team : SOFTNSOL India: Skype id : softnsoltrainings id:
SQL Tuning Ohio Oracle User’s Group October 2002 © Copyright, Kris T. Mason, 2002.
Dale Roberts 8/20/ Department of Computer and Information Science, School of Science, IUPUI Dale Roberts, Lecturer Computer Science, IUPUI
Executing Explain Plans and Explaining Execution Plans Craig Martin 01/20/2011.
Database Systems: Design, Implementation, and Management Tenth Edition Chapter 11 Database Performance Tuning and Query Optimization.
Database Systems: Design, Implementation, and Management Eighth Edition Chapter 10 Database Performance Tuning and Query Optimization.
IT The Relational DBMS Section 06. Relational Database Theory Physical Database Design.
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.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
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.
Oracle9i Performance Tuning Chapter 1 Performance Tuning Overview.
The Self-Managing Database: Guided Application and SQL Tuning Mohamed Ziauddin Consulting Member of Technical Staff Oracle Corporation Session id:
RBO RIP George Lumpkin Director Product Management Oracle Corporation Session id:
Chapter 2: SQL – The Basics Objectives: 1.The SQL execution environment 2.SELECT statement 3.SQL Developer & SQL*Plus.
Basic Optimization DB Workshop for LHC online/offline developers CERN January
Oracle9i Performance Tuning Chapter 12 Tuning Tools.
Star Transformations Tony Hasler, UKOUG Birmingham 2012 Tony Hasler, Anvil Computer Services Ltd.
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.
© IBM Corporation 2005 Informix User Forum 2005 John F. Miller III Explaining SQLEXPLAIN ®
Query Optimization CMPE 226 Database Systems By, Arjun Gangisetty
1 Copyright © 2005, Oracle. All rights reserved. Following a Tuning Methodology.
Last Updated : 27 th April 2004 Center of Excellence Data Warehousing Group Teradata Performance Optimization.
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.
Ad Hoc User or Application Cost-based Data Dictionary Statistics Rule-based Execution Plan Asks the question: All people and their grades in a list giving.
Query Processing – Implementing Set Operations and Joins Chap. 19.
Optimization and Administartion of a Database Management Systems Krystian Zieja.
Oracle9i Developer: PL/SQL Programming Chapter 11 Performance Tuning.
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.
LAB: Web-scale Data Management on a Cloud Lab 11. Query Execution Plan 2011/05/27.
Diving into Query Execution Plans ED POLLACK AUTOTASK CORPORATION DATABASE OPTIMIZATION ENGINEER.
Closing the Query Processing Loop in Oracle 11g Allison Lee, Mohamed Zait.
Tuning Oracle SQL The Basics of Efficient SQL Common Sense Indexing
SQL Tuning.
EVOLUTION OF THE ORACLE OPTIMIZER THINKING
Database Performance Tuning &
Database Performance Tuning and Query Optimization
JULIE McLAIN-HARPER LINKEDIN: JM HARPER
Execution Plans Demystified
Chapter 11 Database Performance Tuning and Query Optimization
Introduction to the Optimizer
Performance Tuning ETL Process
Presentation transcript:

11-1 Improve response time of interactive programs. Improve batch throughput. To ensure scalability of applications load vs. performance. Reduce system load for other uses besides DB. Avoid hardware upgrades. Why Tune SQL Statements

11-2 Scalability Well-tuned applications deliver good performance as number of users or data volume increases. Applications which have a linear degradation pattern degrade predictably, usually they are problems responsive to hardware upgrades. Exponential degradation patterns are more serious. They tend to be problems that creep up over time, starting benign and unrecognized, later becoming huge problems. Bottlenecks are performance problems which are abrupt, like “hitting a brick wall”. Usually no warning, and no hardware solution.

11-3 “The Oracle optimizer will tune my statements for me automatically.” “I’m not a SQL programmer, I’m a... VB/PowerBuilder/C++/Java programmer.” “I’ll write the SQL, someone else (DBA) can tune it for me later.” “I’ll tune it later” “We can’t afford to tune it” Objections to SQL Tuning

11-4 When to Tune SQL Early is least costly & better. Changing SQL/table designs in the design phase means that no applications need to be re-written. Tuning SQL performance when SQL is first written usually means lower testing costs. In production systems, testing SQL can sometimes be difficult... change control, production system availability, extra time to deal with larger data volumes. Tune SQL early as possible to be most effective and economical.

11-5 Overview of Query Processing Query Decomposition Query Optimization Code Generation Query Execution System Catalog Database Statistics Database Tables SQL Parsed SQL Execution Plan Generated Query Code Output

11-6 SQL Tuning Process

11-7 Retrieving Data:  Full Table Scan - gets data from row 1 to high water mark  Row ID - gets data by physical location. Quickest way to get a row.  Index Lookup - matches up key value with Row ID  Hash Key Lookup - computes a Row ID with a mathematical formula applied to key value. Joining Data:  Sort Merge Join 1)sorts each table’s key columns 2)merges data together 3)does not use indexes  Nested Loops Join 1)full table scan used on smaller table 2)key values of 1st table joined with the larger table’s index  Hash Join 1)hash key built for larger table, constructs index on the fly 2)smaller table is then fully scanned 3)data from smaller table is joined with the hash key index. Retrieving and Joining Data

11-8 Oracle Optimizers:  Rule Based Optimizer (RBO) older optimizer, used since first versions of Oracle. set of rules which rank access paths. always picks an index over doing full table scan.  Cost Based Optimizer (CBO) new in Oracle 7. uses database statistics to pick optimal access path. To collect table statistics: ANALYZE TABLE tablename CALCULATE STATISTICS; Optimizer Goals:  RULE, picks only rule based optimizer.  CHOOSE, picks cost based optimizer if any table in query has been analyzed.  ALL_ROWS, picks the cost based optimizer and finds an execution plan which is best for the entire query. Good for batch reporting.  FIRST_ROWS, pick the cost based optimizer and finds an execution plan which is best for the first row. Good for interactive applications. RBO and CBO

ways to change the Oracle optimizer goal: 1.Change the database configuration file (init.ora). OPTIMIZER_MODE=FIRST_ROWS 2.Change settings for your session in SQL*Plus. ALTER SESSION SET OPTIMIZER_GOAL=RULE; 3.“Influence” the optimizer with “hints”. Example, recommend use of rule based optimizer: SELECT /*+ RULE */ * FROM EMPLOYEE WHERE SALARY > ; Setting the Optimizer Goal

11-10 Other Common Hints Example, use full table scans: select /*+ FULL(E) FULL(D) */ e.employee_id, e.surname, e.firstname from employee e, department d where d.location=‘Indianapolis’ and d.dept_id = e.dept_id; Example, recommend any index: select /*+ index(E) */ e.employee_id, e.surname, e.firstname from employee e, department d where d.location=‘Indianapolis’ and d.dept_id = e.dept_id; Example, recommend a specific index: select /*+ index(E, emp_dept_idx) */ e.employee_id, e.surname, e.firstname from employee e, department d where d.location=‘Indianapolis’ and d.dept_id = e.dept_id;

11-11  EXPLAIN PLAN, shows the execution plan.  SQL_TRACE, generates a trace file containing SQL executed by your session and resources used.  tkprof, formats SQL_TRACE output.  AUTOTRACE, SQL*Plus command to show execution plans and statistics in your SQL*Plus session.  3rd Party Tools. Numerous GUI tools to quickly show this information, usually expensive. Example below. Tuning Tools

11-12 Executing: explain plan for select /*+RULE */ e.surname, e.firstname, e.date_of_birth from employee e, customers c where e.surname=c.contact_surname and e.firstname=c.contact_firstname and e.date_of_birth=c.date_of_birth order by e.surname, e.firstname; Formatting Plan Table in a Query: select rtrim(lpad(‘ ‘,2*level)|| rtrim(operation)||‘ ‘|| rtrim(options)||‘ ‘|| object_name) as query_plan from plan_table connect by prior id=parent_id start with id=0; Execution Plan Query: query_plan SELECT STATEMENT SORT ORDER BY NETED LOOPS TABLE ACCESS FULL CUSTOMERS TABLE ACCESS BY ROWID EMPLOYEES INDEX RANGE SCAN EMP_BOTH_IDX Explain Plan