Agenda Overview of the optimizer How SQL is executed Identifying statements that need tuning Explain Plan Modifying the plan.

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
Introduction to SQL Tuning Brown Bag Three essential concepts.
SQL Tuning Briefing Null is not equal to null but null is null.
M ODULE 4 D ATABASE T UNING Section 3 Application Performance 1 ITEC 450 Fall 2012.
Jonathan Lewis EOUG Jun 2000 Execution Plans Agenda What are execution plans Where do you find execution plans Key mechanisms of execution Understanding.
What Happens when a SQL statement is issued?
1 Copyright © 2011, Oracle and/or its affiliates. All rights reserved.
INTRODUCTION TO ORACLE Lynnwood Brown System Managers LLC Performance And Tuning – Lecture 7 Copyright System Managers LLC 2007 all rights reserved.
1 Theory, Practice & Methodology of Relational Database Design and Programming Copyright © Ellis Cohen Query & Application Performance These.
1 King Saud University College of Computer & Information Sciences IS 335 Database Management System Lecture 6 Query Processing and Optimization (Practice)
David Konopnicki Choosing Access Path ä The basic methods. ä The access paths and when they are available. ä How the optimizer chooses among the.
1 The Optimizer How ORACLE optimizes SQL statements David Konopnicky 1997, Revised by Mordo Shalom 2004.
Oracle Optimizer. Types of Optimizers There are different modes for the optimizer RULE: Rule-based optimizer (RBO) –Deprecated; not updated since 1994.
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.
Access Path Selection in a Relation Database Management System (summarized in section 2)
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
Relational Database Performance CSCI 6442 Copyright 2013, David C. Roberts, all rights reserved.
Executing Explain Plans and Explaining Execution Plans Craig Martin 01/20/2011.
A few things about the Optimizer Thomas Kyte
Oracle Database Administration Lecture 6 Indexes, Optimizer, Hints.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
Ashwani Roy Understanding Graphical Execution Plans Level 200.
Oracle Database Administration Lecture 2 SQL language.
1 Optimizing Your ColdFusion Applications for Oracle Justin Fidler, CNA, CPS, CCFD Chief Technology Officer Bantu, Inc. 8 May 2001.
1 Oracle Architectural Components. 1-2 Objectives Listing the structures involved in connecting a user to an Oracle server Listing the stages in processing.
Basic Optimization DB Workshop for LHC online/offline developers CERN January
11-1 Improve response time of interactive programs. Improve batch throughput. To ensure scalability of applications load vs. performance. Reduce system.
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.
Database Systems Design, Implementation, and Management Coronel | Morris 11e ©2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or.
Module 4 Database SQL Tuning Section 3 Application Performance.
SQL Tuning 101 excerpt: Explain Plan A Logical Approach Michael Ruckdaschel Affinion Group International.
© IBM Corporation 2005 Informix User Forum 2005 John F. Miller III Explaining SQLEXPLAIN ®
1 DBS201: More on SQL Lecture 3. 2 Agenda How to use SQL to update table definitions How to update data in a table How to join tables together.
1 Chapter 13 Parallel SQL. 2 Understanding Parallel SQL Enables a SQL statement to be: – Split into multiple threads – Each thread processed simultaneously.
10g Tuning Highlights Presenter JEREMY SCHNEIDER Senior Consultant, ITC Technology Services.
1 Chapter 9 Tuning Table Access. 2 Overview Improve performance of access to single table Explain access methods – Full Table Scan – Index – Partition-level.
David Konopnicki –1997, Rev. MS Optimizing Join Statements To choose an execution plan for a join statement, the optimizer must choose: ä Access.
DB Tuning : Chapter 10. Optimizer Center for E-Business Technology Seoul National University Seoul, Korea 이상근 Intelligent Database Systems Lab School of.
Sorting and Joining.
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.
1 Presentation Outline SQL Writing Process SQL Standards Using Indexes The Optimizer FROM, WHERE Clauses EXPLAIN SQL Trace Sub-Selects and Joins Tips and.
Optimization and Administartion of a Database Management Systems Krystian Zieja.
1 Chapter 8 Execution Plan Management. 2 Overview of Execution Plan Management Review techniques to – override optimizer – Improve optimizer’s decisions.
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.
Scott Fallen Sales Engineer, SQL Sentry Blog: scottfallen.blogspot.com.
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.
Tuning Oracle SQL The Basics of Efficient SQL Common Sense Indexing
SQL Trace and TKPROF.
SQL Tuning.
EXPLAIN and AUTOTRACE.
Choosing Access Path The basic methods.
Introduction to Execution Plans
JULIE McLAIN-HARPER LINKEDIN: JM HARPER
Introduction to Execution Plans
Diving into Query Execution Plans
Introduction to Execution Plans
Introduction to the Optimizer
Introduction to Execution Plans
Performance Tuning ETL Process
Presentation transcript:

Agenda Overview of the optimizer How SQL is executed Identifying statements that need tuning Explain Plan Modifying the plan

Optimizer Attempts to find best path Mode is set in init.ora file (can also be set for a session) –Rule Based Init.ora optimizer_mode = rule Based on set of rules executed in order –Cost Based Init.ora optimizer_mode = choose and table(s) analyzed (uses rule otherwise) Based on statistics logged in tables Tables analyzed by DBA - this generates the statistics –NOTE that these must be updated regularly to be meaningful

Processing SQL Optimizer looks at the following: –details of the syntax –any conditions to satisfy (where) –the tables and indexes (if any) –any “hints” –any stats via the ANALYZE function –WHERE clause - least restrictive to most restrictive

SQL Execution Stages Parse –SQL syntax is checked –Placed into cursor cache in the SGA –Execution plan is built Describe/Bind –program variables are associated with the cursor Open/Execute –SQL is run until the first row returns Fetch

Tuning SQL – identifying statements –Set timing on –V$sqlarea DEFINE threshold = 100 SELECT parsing_user_id, command_type, disk_reads, buffer_gets, executions, sql_text FROM v$sqlarea WHERE disk_reads > &threshold ORDER BY disk_reads DESC; –explain plan –set autotrace on set autotrace traceonly explain statistics

Explain Plan Overview Explain Plan provides explanation of path taken to retrieve data (SQL execution path) Set up Explain plan environment –Create the PLAN_TABLE –run explain plan by preceeding SQL with explain plan set statement_id=user||’_1’ -- identify your SQL statements for

Explain Plan Overview (con’d) Read the plan by selecting from PLAN_TABLE SELECT LPAD(‘ ’,2*Level)||Operation||’ ’ || Options || ‘ ’ || decode(object_owner, null, ‘ ’, object_owner||‘.’||object_name) || ‘ ’ ||initcap(optimizer)||decode(cost, null, ‘ ’, ‘Cost=‘||cost)|| decode(cardinality, null, ‘ ’, ‘Rows Expected=‘ ||cardinality|| ‘Result Set Size=‘||bytes|| ‘ Bytes’) Q_Plan FROM PLAN_TABLE CONNECT BY prior ID = Parent_ID AND Statement_ID=user||’_1’ START WITH ID=0 and Statement_ID=user||‘_1’;

Operations and options –index range scan, unique scan –table access full, by rowid –join operations nested loops, merge join Delete from PLAN_TABLE when done tuning by changing the plan –add/modify indexes –optimizer hints –rewrite SQL Explain Plan Overview (con’d)

Sample Output SQL> Explain plan set statement_id='demo' for 2 select ename, loc, sal, hiredate 3 from emp, dept 4 where emp.deptno=dept.deptno; Explained. SQL> SELECT LPAD(' ',2*(level-1)) || operation operation, 2 Options, object_name, position 3 FROM plan_table 4 CONNECT BY PRIOR id=parent_id 5 and statement_id='demo' 6 START WITH id=1 and statement_id='demo'; OPERATION OPTIONS OBJECT_NAME POSITION MERGE JOIN 1 SORT JOIN 1 TABLE ACCESS FULL DEPT 1 SORT JOIN 2 TABLE ACCESS FULL EMP 1

Changing the PLAN Change order of tables in from clause suppress indexes where applicable –concatenate a null to a char column or add zero to number column will suppress the index –use FULL hint use complete key for joins don’t use function calls on columns in the where clause unless you have a function based index (possible with 8i) improve the index scheme to match access pattern

SQL tuning tips try EXISTS instead of IN try NOT EXISTS instead of NOT IN use joins in place of EXISTS use most selective index use rowid if possible? -careful remember the cache! Full table scans aren’t always bad… timing information

Hints /*+ and */ after a SELECT designate a hint to the optimizer if you don’t include the +, Oracle will not give you an error - just becomes a comment many available hints –index select /*+ INDEX(COMPANY) */ Name, City, State from COMPANY where City = 'Roanoke' and State = 'VA'; –full, all_rows, first_rows, index_desc, use_nl, many others...

Lab: Explain Plan Setup PLAN_TABLE run explain plan query PLAN_TABLE delete from PLAN_TABLE (or change statement_id) modify query and re-run