SlideShare a Scribd company logo
By Kai Liu McDOUG 7/15/2009
Main tools for Developers Autotrace SQL Trace Explain Plan Rule-based Optimization How I Approach Tuning a SQL Statement
Autotrace Get a report on the execution path used by the SQL optimizer and the statement execution statistics SET AUTOTRACE ON - The AUTOTRACE report includes both the optimizer execution path and the SQL statement execution statistics.  SET AUTOTRACE TRACE EXP – The AUTOTRACE report  only includes the optimizer execution path. $ORACLE_HOME/rdbms/admin/utlxpls.sql : script to format explain plans
Autotrace Continue SET AUTOTRACE OFF- No AUTOTRACE report is generated. This is the default.     SET AUTOTRACE ON EXPLAIN - The AUTOTRACE report shows only the optimizer execution path.     SET AUTOTRACE ON STATISTICS - The AUTOTRACE report shows only the SQL statement execution statistics.     SET AUTOTRACE ON - The AUTOTRACE report includes both the optimizer execution path and the SQL statement execution statistics.     SET AUTOTRACE TRACEONLY - Like SET AUTOTRACE ON, but suppresses the printing of the user's query output, if any.
SQL Trace alter session set sql_trace=true; 10g (sql_trace being deprecated) execute dbms_monitor.session_trace_enable Check /oracle/admin/dmsdev/udump ls –lrt *.trc execute dbms_monitor.session_trace_disable
Explain Plan Used to find out how the Oracle Optimizer processes a statement. The Optimizer is a program that examines the SQL statement as presented by a user and then devises an execution plan to execute the statement. Oracle's Cost Based Optimizer comes up with an execution plan that is hopefully the most efficient way to resolve the query, but for many reasons it will often choose a sub-optimal plan.
Explain Plan Continue Syntax of the explain plan command:  explain plan [set statement id = ’<name>’] for <statement>; Explain Plan set statement id = ‘<statement>’ for select ENAME, JOB, SAL, DNAME from EMP, DEPT where EMP.DEPTNO = DEPT.DEPTID and not exists (select  from SALGRADE where EMP.SAL between LOSAL and  HISAL);
Explain Plan Continue select statement to retrieve information about the (hierarchical) execution plan determined by the query optimizer: select lpad(’ ’, 2*(LEVEL-1)) “OPERATION”, substr(OPTIONS,1,9) “OPTIONS”, OBJECT NAME, ID, PARENT ID from PLAN TABLE start with ID = 0 [and STATEMENT ID = ’<statement>’] connect by prior ID = PARENT ID [and STATEMENT ID = ’<statement>’;] OPERATION OPTIONS OBJECT_NAME ID PARENT_ID --------------------- -------- ----------- -- --------- SELECT STATEMENT 0 FILTER 1 0 MERGE JOIN 2 1   SORT JOIN 3 2   TABLE ACCESS FULL DEPT 4 3   SORT JOIN 5 2 TABLE ACCESS FULL EMP 6 5 TABLE ACCESS FULL SALGRADE 7 1
Rule-based Optimization(RBO) Access Path Access row using Rowid (TID) Access row using Cluster-Join Access row Hash-Cluster-Key Access row using primary key Cluster-Join Hash-Cluster-Key Clusterkey with Index Composed Index Single-Row Index Search Index range Search Index without range Merge Join Use  min  or  max  on indexed column Use  order by  on Index Full Table Scan
How I Approach Tuning a SQL Statement Analyze the Statement Compare Plans Test it out Tuning Hints and Tips

More Related Content

ODP
My sql Syntax
ODP
Prabu's sql quries
PPT
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
PPT
Oracle PL/SQL Bulk binds
DOCX
Functions oracle (pl/sql)
PPTX
Oracle: Basic SQL
PPT
My sql Syntax
Prabu's sql quries
Tony jambu (obscure) tools of the trade for tuning oracle sq ls
Oracle PL/SQL Bulk binds
Functions oracle (pl/sql)
Oracle: Basic SQL

Viewers also liked (6)

PPT
CHX PYTHON INTRO
PPT
Sql Question #3
PPT
PL/SQL11g Question #1
PDF
Sql Question #5
PDF
Oracle10g External Tables
PPT
What is Listagg?
CHX PYTHON INTRO
Sql Question #3
PL/SQL11g Question #1
Sql Question #5
Oracle10g External Tables
What is Listagg?
Ad

Similar to SQL Tuning Overview (20)

PPTX
Plsql coding conventions
PPT
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
PPT
SQL Optimization With Trace Data And Dbms Xplan V6
PPT
Oracle tips and tricks
ODP
Mysqlppt
TXT
Oracle sql tuning
PPTX
Sql and PL/SQL Best Practices I
PPTX
DBMS UNIT 9.pptx..................................
PPT
Sydney Oracle Meetup - execution plans
PPT
Prog1 chap1 and chap 2
PPT
Utility Procedures in SAS
PDF
databases management system and other.pdf
PPT
Module04
PDF
Oracle Database 12c Application Development
PDF
Database Management System
PPTX
PLSQLmy Updated (1).pptx
PPT
PHP tips by a MYSQL DBA
PPT
Jsp And Jdbc
PPT
Do You Know The 11g Plan?
PDF
Dynamic websites lec3
Plsql coding conventions
Tony Jambu (obscure) tools of the trade for tuning oracle sq ls
SQL Optimization With Trace Data And Dbms Xplan V6
Oracle tips and tricks
Mysqlppt
Oracle sql tuning
Sql and PL/SQL Best Practices I
DBMS UNIT 9.pptx..................................
Sydney Oracle Meetup - execution plans
Prog1 chap1 and chap 2
Utility Procedures in SAS
databases management system and other.pdf
Module04
Oracle Database 12c Application Development
Database Management System
PLSQLmy Updated (1).pptx
PHP tips by a MYSQL DBA
Jsp And Jdbc
Do You Know The 11g Plan?
Dynamic websites lec3
Ad

More from Kai Liu (15)

PPT
QQ and Advance query
PDF
Schedulers
PPT
PL/SQL Example for IF .. ELSIF
PPT
Dms 2.0 Direction
PPT
Dms 2.0 Plan Proposal
PPT
Toad
PPT
Dms Emailing Reports
PPT
QQ And Advance Query
PPT
Troubleshooting Batch Reports
PPT
Dms Reporting Criteria
PPT
Dms Batch Reporting
PPT
Dms Reporting Overview
PPT
Dms 2 Direction
PPT
Dms Project
PPT
Dms Acknowledgements
QQ and Advance query
Schedulers
PL/SQL Example for IF .. ELSIF
Dms 2.0 Direction
Dms 2.0 Plan Proposal
Toad
Dms Emailing Reports
QQ And Advance Query
Troubleshooting Batch Reports
Dms Reporting Criteria
Dms Batch Reporting
Dms Reporting Overview
Dms 2 Direction
Dms Project
Dms Acknowledgements

Recently uploaded (20)

PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
Cloud computing and distributed systems.
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Machine learning based COVID-19 study performance prediction
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
cuic standard and advanced reporting.pdf
PPTX
Spectroscopy.pptx food analysis technology
PDF
Empathic Computing: Creating Shared Understanding
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
NewMind AI Weekly Chronicles - August'25 Week I
Cloud computing and distributed systems.
sap open course for s4hana steps from ECC to s4
Advanced methodologies resolving dimensionality complications for autism neur...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Understanding_Digital_Forensics_Presentation.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
MYSQL Presentation for SQL database connectivity
Network Security Unit 5.pdf for BCA BBA.
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Machine learning based COVID-19 study performance prediction
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Spectral efficient network and resource selection model in 5G networks
cuic standard and advanced reporting.pdf
Spectroscopy.pptx food analysis technology
Empathic Computing: Creating Shared Understanding
MIND Revenue Release Quarter 2 2025 Press Release
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

SQL Tuning Overview

  • 1. By Kai Liu McDOUG 7/15/2009
  • 2. Main tools for Developers Autotrace SQL Trace Explain Plan Rule-based Optimization How I Approach Tuning a SQL Statement
  • 3. Autotrace Get a report on the execution path used by the SQL optimizer and the statement execution statistics SET AUTOTRACE ON - The AUTOTRACE report includes both the optimizer execution path and the SQL statement execution statistics. SET AUTOTRACE TRACE EXP – The AUTOTRACE report only includes the optimizer execution path. $ORACLE_HOME/rdbms/admin/utlxpls.sql : script to format explain plans
  • 4. Autotrace Continue SET AUTOTRACE OFF- No AUTOTRACE report is generated. This is the default.   SET AUTOTRACE ON EXPLAIN - The AUTOTRACE report shows only the optimizer execution path.   SET AUTOTRACE ON STATISTICS - The AUTOTRACE report shows only the SQL statement execution statistics.   SET AUTOTRACE ON - The AUTOTRACE report includes both the optimizer execution path and the SQL statement execution statistics.   SET AUTOTRACE TRACEONLY - Like SET AUTOTRACE ON, but suppresses the printing of the user's query output, if any.
  • 5. SQL Trace alter session set sql_trace=true; 10g (sql_trace being deprecated) execute dbms_monitor.session_trace_enable Check /oracle/admin/dmsdev/udump ls –lrt *.trc execute dbms_monitor.session_trace_disable
  • 6. Explain Plan Used to find out how the Oracle Optimizer processes a statement. The Optimizer is a program that examines the SQL statement as presented by a user and then devises an execution plan to execute the statement. Oracle's Cost Based Optimizer comes up with an execution plan that is hopefully the most efficient way to resolve the query, but for many reasons it will often choose a sub-optimal plan.
  • 7. Explain Plan Continue Syntax of the explain plan command: explain plan [set statement id = ’<name>’] for <statement>; Explain Plan set statement id = ‘<statement>’ for select ENAME, JOB, SAL, DNAME from EMP, DEPT where EMP.DEPTNO = DEPT.DEPTID and not exists (select from SALGRADE where EMP.SAL between LOSAL and HISAL);
  • 8. Explain Plan Continue select statement to retrieve information about the (hierarchical) execution plan determined by the query optimizer: select lpad(’ ’, 2*(LEVEL-1)) “OPERATION”, substr(OPTIONS,1,9) “OPTIONS”, OBJECT NAME, ID, PARENT ID from PLAN TABLE start with ID = 0 [and STATEMENT ID = ’<statement>’] connect by prior ID = PARENT ID [and STATEMENT ID = ’<statement>’;] OPERATION OPTIONS OBJECT_NAME ID PARENT_ID --------------------- -------- ----------- -- --------- SELECT STATEMENT 0 FILTER 1 0 MERGE JOIN 2 1 SORT JOIN 3 2 TABLE ACCESS FULL DEPT 4 3 SORT JOIN 5 2 TABLE ACCESS FULL EMP 6 5 TABLE ACCESS FULL SALGRADE 7 1
  • 9. Rule-based Optimization(RBO) Access Path Access row using Rowid (TID) Access row using Cluster-Join Access row Hash-Cluster-Key Access row using primary key Cluster-Join Hash-Cluster-Key Clusterkey with Index Composed Index Single-Row Index Search Index range Search Index without range Merge Join Use min or max on indexed column Use order by on Index Full Table Scan
  • 10. How I Approach Tuning a SQL Statement Analyze the Statement Compare Plans Test it out Tuning Hints and Tips