SlideShare a Scribd company logo
1 of 34
Download to read offline
An Approach to SQL Tuning 
Part - I
Who AM I? 
 Navneet Upneja (Oracle DBA) 
7 Years of Experience in Oracle Databases and 
Middleware Applications 
 Oracle Certified Professional 
 Hand on experience on OLTP, Datawarehouse, 
Oracle BI, APEX… 
Member of North India Chapter.
Agenda 
• SQL 
• Execution Process 
• Scope of Tuning 
• Set of Actions 
• Generation of Explain Plan 
• Discussing Various Techniques for 
Execution Plan generation 
• We are not tuning anything today
What is SQL? 
• Stands for "Structured Query Language," 
• pronounced as either "sequel" or "S-Q-L. 
• created by IBM in 1975 
In Oracle: 
• Way to query database. 
• Identified by SQL ID 
• 310rmwf1kf334 (13 Character Base 32 
encod)
Types of SQL 
• QUERY 
– Select 
• DML 
– Insert 
– Update 
– Delete 
– Merge 
• DDL 
– Create 
– ALTER 
– DROP 
• …..
Steps in SQL Execution 
Parse 
• Syntax 
• Symantec 
• Optimization 
• Execution 
Plan(s) 
Execute 
• Bind 
Variable to 
Bind Values 
• Execution of 
Query with 
Select 
Execution 
Plan 
Fetch 
• Data 
Fetched to 
be returned 
back to 
users (Only 
for Quries)
Scope of Tuning 
• Parse 
– Hard Parsing 
– Soft Parsing 
– Optimization 
• Object Statistics 
• Latch Contention 
• Execute 
– IO Waits (Physical IO’s) 
– CPU waits (Logical IO’s) 
• Fetch 
– Network Waits (Sql*net message to client)
Scenarios 
• Someone complains of Application Slow or 
some report is slow. 
• Query from somewhere suddenly pops 
that making things go bad. 
• Your scheduled database program like 
ETL Load starts taking longer. 
• Some Ad hoc queries. 
• New queries from development team.
Action Plan 
• Find the offending session 
– v$session 
– OEM 
• Find the bad SQL 
– OEM 
– AWR 
– ASH 
– Data Dictionary Views (v$SQL,v$SQLSTATS,DBA_HIST_SQLSTAT…) 
• Generate Execution Plan 
– Explain Plan for 
– DBMS_XPLAN 
• Display_Cursor 
• Display_AWR 
– SQL Monitoring from OEM 
– DBMS_SQLTUNE.REPORT_SQL_MONITOR 
• Interpret the Plan 
– Go through the plan 
– Look out for suspicious steps that may be causing Issue 
– Cardinality 
• Apply your fixes 
– Optimizer Statistics 
– Missing Indexes (Be careful) 
– SQL Profile 
– SQL Baseline
Finding Long Running 
Sessions 
• From SQL Script
• From OEM Top Activity
Finding Bad SQL 
• From OEM Top 
Activity
From AWR
From SQL Monitoring
Or More Conventional Way
Execution Plan 
• Detailed Steps required 
to execute a SQL. 
• Combination of various 
database operations. 
• Designed by Query 
Optimizer 
• Tree Shaped 
• For better usability, 
shown in Tabular form. 
• OEM shows both plans.
Generating Explain plan 
• Explain plan for .. <SQL Statement> 
– Populated plan_table 
– Captured plan can be viewed using SQL 
Statsment 
– select plan_table_output from 
table(dbms_xplan.display('plan_table',null,'serial')) 
– @?rdbmsadminutlxpls 
– Not always right specifically if SQL Statement 
contains BIND Variables
Example of Explain plan… 
• Explain plan for a simple select with one Bind Variable 
• Resulted plan shows Index Range scan.
• Lets run the same query with Literal 
select * from employees where department_id=50 
Optimizer decided to perform Full table scan instead of using Index 
Check the difference in Number of Rows returned against FTS
So, Then What if not Explain 
plan? 
• DBMS_XPLAN 
– Display Plan from Cursor 
Cache 
– From AWR 
– From SQL Plan Baseline 
– From SQL Set
DBMS_XPLAN 
• DBMS_XPLAN.DISPLAY 
• DBMS_XPLAN.DISPLAY_CURSOR 
• DBMS_XPLAN.DISPLAY_AWR 
• DBMS_XPLAN.DISPLAY_SQL_PLAN_BA 
SELINE 
• DBMS_XPLAN.DISPLAY_SQLSET
DBMS_XPLAN.DISPLAY_CURSOR 
– Display from GV$SQL_PLAN (or 
GV$SQL_PLAN_STATISTICS_ALL) 
– Useful in providing real statistics for SQL 
execution 
– Various options to display different details like 
Advanced, Allstats, IOSTATS etc.. 
– Is NOT RAC Aware
Is it Sufficient? 
Estimates ..not 
Real
Rowsource Statistics 
• More detailed statistics 
• Provide real picture but 
after execution of query 
• Must to find out exact 
cause of problem 
• v$sql_plan_statistics_all 
• Provides Real Numbers 
for : 
– Rows returned 
– CPU 
– Physical IO 
– LIO 
– Elapsed Time 
Pre-requisite: 
STATISTICS_LEVEL=ALL 
(At session level) 
OR 
/*+ gather_plan_statistics */ 
Hint in SQL
With 
STATISTICS_LEVEL=ALL
DBMS_XPLAN.DISPLAY_AWR 
– Display Execution plan for SQL_ID’s captured 
in AWR 
– Can show details of Peeked Bind Values. 
– Useful to troubleshoot performance of SQL 
from the past 
– Can be used to compare the execution plan 
from the past 
– Is definitely a next step after AWR Report.
Example.. 
• select * from table(dbms_xplan.display_awr('86bh2bn3gtmm0',null, 
null, 'ALL +peeked_binds'));
SQL Monitor 
• Real Time Monitoring 
• Identify run time problems 
• Useful for long running Queries 
• Provide actual run time values for each step in execution 
plan. 
• Easy to access through OEM. 
• DBMS_SQLTUNE.report_sql_monitor 
• STATISTICS_LEVEL=TYPICAL/ALL 
• control_management_pack_access 
=DIAGNOSTIC+TUNING
From OEM
In the Next Session.. 
• Interpreting Execution Plan 
• 10046 Trace 
• CBO Basics 
• Finding out the bottlenecks 
• Much More…
SQL Tuning Part 1 - Understanding SQL Execution and Generating Execution Plans

More Related Content

What's hot

Think Exa!
Think Exa!Think Exa!
Think Exa!Enkitec
 
Top 10 tips for Oracle performance (Updated April 2015)
Top 10 tips for Oracle performance (Updated April 2015)Top 10 tips for Oracle performance (Updated April 2015)
Top 10 tips for Oracle performance (Updated April 2015)Guy Harrison
 
Oracle performance tuning_sfsf
Oracle performance tuning_sfsfOracle performance tuning_sfsf
Oracle performance tuning_sfsfMao Geng
 
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentalsDB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentalsJohn Beresniewicz
 
Oracle Sql Tuning
Oracle Sql TuningOracle Sql Tuning
Oracle Sql TuningChris Adkin
 
Oracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance TuningOracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance TuningOracleTrainings
 
Oracle Data Redaction - EOUC
Oracle Data Redaction - EOUCOracle Data Redaction - EOUC
Oracle Data Redaction - EOUCAlex Zaballa
 
Oracle Database 12c - Data Redaction
Oracle Database 12c - Data RedactionOracle Database 12c - Data Redaction
Oracle Database 12c - Data RedactionAlex Zaballa
 
Oracle Database Performance Tuning Basics
Oracle Database Performance Tuning BasicsOracle Database Performance Tuning Basics
Oracle Database Performance Tuning Basicsnitin anjankar
 
Oracle DB Performance Tuning Tips
Oracle DB Performance Tuning TipsOracle DB Performance Tuning Tips
Oracle DB Performance Tuning TipsAsanka Dilruk
 
Fatkulin hotsos 2014
Fatkulin hotsos 2014Fatkulin hotsos 2014
Fatkulin hotsos 2014Enkitec
 
Advanced t sql - querying and programming inside sql server
Advanced t sql - querying and programming inside sql serverAdvanced t sql - querying and programming inside sql server
Advanced t sql - querying and programming inside sql serverVinod Kumar
 
Oracle Data Redaction
Oracle Data RedactionOracle Data Redaction
Oracle Data RedactionAlex Zaballa
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the TradeOracle Performance Tools of the Trade
Oracle Performance Tools of the TradeEnkitec
 
Exadata and the Oracle Optimizer: The Untold Story
Exadata and the Oracle Optimizer: The Untold StoryExadata and the Oracle Optimizer: The Untold Story
Exadata and the Oracle Optimizer: The Untold StoryEnkitec
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowAlex Zaballa
 
Indexing Strategies for Oracle Databases - Beyond the Create Index Statement
Indexing Strategies for Oracle Databases - Beyond the Create Index StatementIndexing Strategies for Oracle Databases - Beyond the Create Index Statement
Indexing Strategies for Oracle Databases - Beyond the Create Index StatementSean Scott
 
Query optimizer vivek sharma
Query optimizer vivek sharmaQuery optimizer vivek sharma
Query optimizer vivek sharmaaioughydchapter
 
resource governor
resource governorresource governor
resource governorAaron Shilo
 

What's hot (20)

Think Exa!
Think Exa!Think Exa!
Think Exa!
 
Top 10 tips for Oracle performance (Updated April 2015)
Top 10 tips for Oracle performance (Updated April 2015)Top 10 tips for Oracle performance (Updated April 2015)
Top 10 tips for Oracle performance (Updated April 2015)
 
Oracle performance tuning_sfsf
Oracle performance tuning_sfsfOracle performance tuning_sfsf
Oracle performance tuning_sfsf
 
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentalsDB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
 
Oracle Sql Tuning
Oracle Sql TuningOracle Sql Tuning
Oracle Sql Tuning
 
Oracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance TuningOracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance Tuning
 
Oracle Data Redaction - EOUC
Oracle Data Redaction - EOUCOracle Data Redaction - EOUC
Oracle Data Redaction - EOUC
 
Oracle Database 12c - Data Redaction
Oracle Database 12c - Data RedactionOracle Database 12c - Data Redaction
Oracle Database 12c - Data Redaction
 
Oracle Database Performance Tuning Basics
Oracle Database Performance Tuning BasicsOracle Database Performance Tuning Basics
Oracle Database Performance Tuning Basics
 
Oracle SQL Tuning
Oracle SQL TuningOracle SQL Tuning
Oracle SQL Tuning
 
Oracle DB Performance Tuning Tips
Oracle DB Performance Tuning TipsOracle DB Performance Tuning Tips
Oracle DB Performance Tuning Tips
 
Fatkulin hotsos 2014
Fatkulin hotsos 2014Fatkulin hotsos 2014
Fatkulin hotsos 2014
 
Advanced t sql - querying and programming inside sql server
Advanced t sql - querying and programming inside sql serverAdvanced t sql - querying and programming inside sql server
Advanced t sql - querying and programming inside sql server
 
Oracle Data Redaction
Oracle Data RedactionOracle Data Redaction
Oracle Data Redaction
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the TradeOracle Performance Tools of the Trade
Oracle Performance Tools of the Trade
 
Exadata and the Oracle Optimizer: The Untold Story
Exadata and the Oracle Optimizer: The Untold StoryExadata and the Oracle Optimizer: The Untold Story
Exadata and the Oracle Optimizer: The Untold Story
 
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should KnowDBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
DBA Brasil 1.0 - DBA Commands and Concepts That Every Developer Should Know
 
Indexing Strategies for Oracle Databases - Beyond the Create Index Statement
Indexing Strategies for Oracle Databases - Beyond the Create Index StatementIndexing Strategies for Oracle Databases - Beyond the Create Index Statement
Indexing Strategies for Oracle Databases - Beyond the Create Index Statement
 
Query optimizer vivek sharma
Query optimizer vivek sharmaQuery optimizer vivek sharma
Query optimizer vivek sharma
 
resource governor
resource governorresource governor
resource governor
 

Similar to SQL Tuning Part 1 - Understanding SQL Execution and Generating Execution Plans

Oracle Query Optimizer - An Introduction
Oracle Query Optimizer - An IntroductionOracle Query Optimizer - An Introduction
Oracle Query Optimizer - An Introductionadryanbub
 
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdfNOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdfcookie1969
 
Database Fundamental Concepts- Series 1 - Performance Analysis
Database Fundamental Concepts- Series 1 - Performance AnalysisDatabase Fundamental Concepts- Series 1 - Performance Analysis
Database Fundamental Concepts- Series 1 - Performance AnalysisDAGEOP LTD
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cRonald Francisco Vargas Quesada
 
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsOracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsZohar Elkayam
 
Jss 2015 in memory and operational analytics
Jss 2015   in memory and operational analyticsJss 2015   in memory and operational analytics
Jss 2015 in memory and operational analyticsDavid Barbarin
 
[JSS2015] In memory and operational analytics
[JSS2015] In memory and operational analytics[JSS2015] In memory and operational analytics
[JSS2015] In memory and operational analyticsGUSS
 
Oracle vs. SQL Server- War of the Indices
Oracle vs. SQL Server- War of the IndicesOracle vs. SQL Server- War of the Indices
Oracle vs. SQL Server- War of the IndicesKellyn Pot'Vin-Gorman
 
Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsTeamstudio
 
3 CityNetConf - sql+c#=u-sql
3 CityNetConf - sql+c#=u-sql3 CityNetConf - sql+c#=u-sql
3 CityNetConf - sql+c#=u-sqlŁukasz Grala
 
Java Developers, make the database work for you (NLJUG JFall 2010)
Java Developers, make the database work for you (NLJUG JFall 2010)Java Developers, make the database work for you (NLJUG JFall 2010)
Java Developers, make the database work for you (NLJUG JFall 2010)Lucas Jellema
 
Adapting and adopting spm v04
Adapting and adopting spm v04Adapting and adopting spm v04
Adapting and adopting spm v04Carlos Sierra
 
Optimizing applications and database performance
Optimizing applications and database performanceOptimizing applications and database performance
Optimizing applications and database performanceInam Bukhary
 
Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...
Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...
Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...MediaMongrels Ltd
 
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle SQL Tuning for Day-to-Day Data Warehouse SupportOracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle SQL Tuning for Day-to-Day Data Warehouse Supportnkarag
 

Similar to SQL Tuning Part 1 - Understanding SQL Execution and Generating Execution Plans (20)

SQL Tuning 101
SQL Tuning 101SQL Tuning 101
SQL Tuning 101
 
sqltuning101-170419021007-2.pdf
sqltuning101-170419021007-2.pdfsqltuning101-170419021007-2.pdf
sqltuning101-170419021007-2.pdf
 
Oracle Query Optimizer - An Introduction
Oracle Query Optimizer - An IntroductionOracle Query Optimizer - An Introduction
Oracle Query Optimizer - An Introduction
 
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdfNOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
 
Database Fundamental Concepts- Series 1 - Performance Analysis
Database Fundamental Concepts- Series 1 - Performance AnalysisDatabase Fundamental Concepts- Series 1 - Performance Analysis
Database Fundamental Concepts- Series 1 - Performance Analysis
 
Breaking data
Breaking dataBreaking data
Breaking data
 
Presentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12cPresentación Oracle Database Migración consideraciones 10g/11g/12c
Presentación Oracle Database Migración consideraciones 10g/11g/12c
 
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsOracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
 
Jss 2015 in memory and operational analytics
Jss 2015   in memory and operational analyticsJss 2015   in memory and operational analytics
Jss 2015 in memory and operational analytics
 
[JSS2015] In memory and operational analytics
[JSS2015] In memory and operational analytics[JSS2015] In memory and operational analytics
[JSS2015] In memory and operational analytics
 
Oracle vs. SQL Server- War of the Indices
Oracle vs. SQL Server- War of the IndicesOracle vs. SQL Server- War of the Indices
Oracle vs. SQL Server- War of the Indices
 
Access Data from XPages with the Relational Controls
Access Data from XPages with the Relational ControlsAccess Data from XPages with the Relational Controls
Access Data from XPages with the Relational Controls
 
11g nf sql_anlz
11g nf sql_anlz11g nf sql_anlz
11g nf sql_anlz
 
3 CityNetConf - sql+c#=u-sql
3 CityNetConf - sql+c#=u-sql3 CityNetConf - sql+c#=u-sql
3 CityNetConf - sql+c#=u-sql
 
Java Developers, make the database work for you (NLJUG JFall 2010)
Java Developers, make the database work for you (NLJUG JFall 2010)Java Developers, make the database work for you (NLJUG JFall 2010)
Java Developers, make the database work for you (NLJUG JFall 2010)
 
Adapting and adopting spm v04
Adapting and adopting spm v04Adapting and adopting spm v04
Adapting and adopting spm v04
 
Plantilla oracle
Plantilla oraclePlantilla oracle
Plantilla oracle
 
Optimizing applications and database performance
Optimizing applications and database performanceOptimizing applications and database performance
Optimizing applications and database performance
 
Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...
Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...
Efficient working with Databases in LabVIEW - Sam Sharp (MediaMongrels Ltd) -...
 
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle SQL Tuning for Day-to-Day Data Warehouse SupportOracle SQL Tuning for Day-to-Day Data Warehouse Support
Oracle SQL Tuning for Day-to-Day Data Warehouse Support
 

More from Navneet Upneja

Database option SDO mismatch: PDB installed version 12.1.0.2.0. CDB installed...
Database option SDO mismatch: PDB installed version 12.1.0.2.0. CDB installed...Database option SDO mismatch: PDB installed version 12.1.0.2.0. CDB installed...
Database option SDO mismatch: PDB installed version 12.1.0.2.0. CDB installed...Navneet Upneja
 
Effecitvely testing Oracle SQL (sql tuning)
Effecitvely testing Oracle SQL (sql tuning)Effecitvely testing Oracle SQL (sql tuning)
Effecitvely testing Oracle SQL (sql tuning)Navneet Upneja
 
Sql developer - Powerful Free tool for Developers and DBA's
Sql developer - Powerful Free tool for Developers and DBA'sSql developer - Powerful Free tool for Developers and DBA's
Sql developer - Powerful Free tool for Developers and DBA'sNavneet Upneja
 
Role of-analytics-in-db as-life
Role of-analytics-in-db as-lifeRole of-analytics-in-db as-life
Role of-analytics-in-db as-lifeNavneet Upneja
 
ORACLE 12C-New-Features
ORACLE 12C-New-FeaturesORACLE 12C-New-Features
ORACLE 12C-New-FeaturesNavneet Upneja
 
Flashback - The Time Machine..
Flashback - The Time Machine..Flashback - The Time Machine..
Flashback - The Time Machine..Navneet Upneja
 
Oracle 12 c new-features
Oracle 12 c new-featuresOracle 12 c new-features
Oracle 12 c new-featuresNavneet Upneja
 
DataGuard - Oracle's Time Machine
DataGuard - Oracle's Time MachineDataGuard - Oracle's Time Machine
DataGuard - Oracle's Time MachineNavneet Upneja
 

More from Navneet Upneja (9)

Database option SDO mismatch: PDB installed version 12.1.0.2.0. CDB installed...
Database option SDO mismatch: PDB installed version 12.1.0.2.0. CDB installed...Database option SDO mismatch: PDB installed version 12.1.0.2.0. CDB installed...
Database option SDO mismatch: PDB installed version 12.1.0.2.0. CDB installed...
 
Effecitvely testing Oracle SQL (sql tuning)
Effecitvely testing Oracle SQL (sql tuning)Effecitvely testing Oracle SQL (sql tuning)
Effecitvely testing Oracle SQL (sql tuning)
 
Sql developer - Powerful Free tool for Developers and DBA's
Sql developer - Powerful Free tool for Developers and DBA'sSql developer - Powerful Free tool for Developers and DBA's
Sql developer - Powerful Free tool for Developers and DBA's
 
Role of-analytics-in-db as-life
Role of-analytics-in-db as-lifeRole of-analytics-in-db as-life
Role of-analytics-in-db as-life
 
Oracle Dataguard
Oracle DataguardOracle Dataguard
Oracle Dataguard
 
ORACLE 12C-New-Features
ORACLE 12C-New-FeaturesORACLE 12C-New-Features
ORACLE 12C-New-Features
 
Flashback - The Time Machine..
Flashback - The Time Machine..Flashback - The Time Machine..
Flashback - The Time Machine..
 
Oracle 12 c new-features
Oracle 12 c new-featuresOracle 12 c new-features
Oracle 12 c new-features
 
DataGuard - Oracle's Time Machine
DataGuard - Oracle's Time MachineDataGuard - Oracle's Time Machine
DataGuard - Oracle's Time Machine
 

Recently uploaded

Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 

Recently uploaded (20)

Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 

SQL Tuning Part 1 - Understanding SQL Execution and Generating Execution Plans

  • 1. An Approach to SQL Tuning Part - I
  • 2. Who AM I?  Navneet Upneja (Oracle DBA) 7 Years of Experience in Oracle Databases and Middleware Applications  Oracle Certified Professional  Hand on experience on OLTP, Datawarehouse, Oracle BI, APEX… Member of North India Chapter.
  • 3. Agenda • SQL • Execution Process • Scope of Tuning • Set of Actions • Generation of Explain Plan • Discussing Various Techniques for Execution Plan generation • We are not tuning anything today
  • 4. What is SQL? • Stands for "Structured Query Language," • pronounced as either "sequel" or "S-Q-L. • created by IBM in 1975 In Oracle: • Way to query database. • Identified by SQL ID • 310rmwf1kf334 (13 Character Base 32 encod)
  • 5. Types of SQL • QUERY – Select • DML – Insert – Update – Delete – Merge • DDL – Create – ALTER – DROP • …..
  • 6. Steps in SQL Execution Parse • Syntax • Symantec • Optimization • Execution Plan(s) Execute • Bind Variable to Bind Values • Execution of Query with Select Execution Plan Fetch • Data Fetched to be returned back to users (Only for Quries)
  • 7. Scope of Tuning • Parse – Hard Parsing – Soft Parsing – Optimization • Object Statistics • Latch Contention • Execute – IO Waits (Physical IO’s) – CPU waits (Logical IO’s) • Fetch – Network Waits (Sql*net message to client)
  • 8. Scenarios • Someone complains of Application Slow or some report is slow. • Query from somewhere suddenly pops that making things go bad. • Your scheduled database program like ETL Load starts taking longer. • Some Ad hoc queries. • New queries from development team.
  • 9. Action Plan • Find the offending session – v$session – OEM • Find the bad SQL – OEM – AWR – ASH – Data Dictionary Views (v$SQL,v$SQLSTATS,DBA_HIST_SQLSTAT…) • Generate Execution Plan – Explain Plan for – DBMS_XPLAN • Display_Cursor • Display_AWR – SQL Monitoring from OEM – DBMS_SQLTUNE.REPORT_SQL_MONITOR • Interpret the Plan – Go through the plan – Look out for suspicious steps that may be causing Issue – Cardinality • Apply your fixes – Optimizer Statistics – Missing Indexes (Be careful) – SQL Profile – SQL Baseline
  • 10. Finding Long Running Sessions • From SQL Script
  • 11. • From OEM Top Activity
  • 12. Finding Bad SQL • From OEM Top Activity
  • 16. Execution Plan • Detailed Steps required to execute a SQL. • Combination of various database operations. • Designed by Query Optimizer • Tree Shaped • For better usability, shown in Tabular form. • OEM shows both plans.
  • 17. Generating Explain plan • Explain plan for .. <SQL Statement> – Populated plan_table – Captured plan can be viewed using SQL Statsment – select plan_table_output from table(dbms_xplan.display('plan_table',null,'serial')) – @?rdbmsadminutlxpls – Not always right specifically if SQL Statement contains BIND Variables
  • 18. Example of Explain plan… • Explain plan for a simple select with one Bind Variable • Resulted plan shows Index Range scan.
  • 19. • Lets run the same query with Literal select * from employees where department_id=50 Optimizer decided to perform Full table scan instead of using Index Check the difference in Number of Rows returned against FTS
  • 20. So, Then What if not Explain plan? • DBMS_XPLAN – Display Plan from Cursor Cache – From AWR – From SQL Plan Baseline – From SQL Set
  • 21. DBMS_XPLAN • DBMS_XPLAN.DISPLAY • DBMS_XPLAN.DISPLAY_CURSOR • DBMS_XPLAN.DISPLAY_AWR • DBMS_XPLAN.DISPLAY_SQL_PLAN_BA SELINE • DBMS_XPLAN.DISPLAY_SQLSET
  • 22. DBMS_XPLAN.DISPLAY_CURSOR – Display from GV$SQL_PLAN (or GV$SQL_PLAN_STATISTICS_ALL) – Useful in providing real statistics for SQL execution – Various options to display different details like Advanced, Allstats, IOSTATS etc.. – Is NOT RAC Aware
  • 23. Is it Sufficient? Estimates ..not Real
  • 24. Rowsource Statistics • More detailed statistics • Provide real picture but after execution of query • Must to find out exact cause of problem • v$sql_plan_statistics_all • Provides Real Numbers for : – Rows returned – CPU – Physical IO – LIO – Elapsed Time Pre-requisite: STATISTICS_LEVEL=ALL (At session level) OR /*+ gather_plan_statistics */ Hint in SQL
  • 26. DBMS_XPLAN.DISPLAY_AWR – Display Execution plan for SQL_ID’s captured in AWR – Can show details of Peeked Bind Values. – Useful to troubleshoot performance of SQL from the past – Can be used to compare the execution plan from the past – Is definitely a next step after AWR Report.
  • 27. Example.. • select * from table(dbms_xplan.display_awr('86bh2bn3gtmm0',null, null, 'ALL +peeked_binds'));
  • 28.
  • 29. SQL Monitor • Real Time Monitoring • Identify run time problems • Useful for long running Queries • Provide actual run time values for each step in execution plan. • Easy to access through OEM. • DBMS_SQLTUNE.report_sql_monitor • STATISTICS_LEVEL=TYPICAL/ALL • control_management_pack_access =DIAGNOSTIC+TUNING
  • 30.
  • 31.
  • 33. In the Next Session.. • Interpreting Execution Plan • 10046 Trace • CBO Basics • Finding out the bottlenecks • Much More…