SlideShare a Scribd company logo
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'));
An Approach to Sql tuning - Part 1
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
An Approach to Sql tuning - Part 1
An Approach to Sql tuning - Part 1
From OEM
In the Next Session.. 
• Interpreting Execution Plan 
• 10046 Trace 
• CBO Basics 
• Finding out the bottlenecks 
• Much More…
An Approach to Sql tuning - Part 1
Ad

Recommended

Oracle sql high performance tuning
Oracle sql high performance tuning
Guy Harrison
 
Top 10 Oracle SQL tuning tips
Top 10 Oracle SQL tuning tips
Nirav Shah
 
Oracle database performance tuning
Oracle database performance tuning
Yogiji Creations
 
Top 10 tips for Oracle performance
Top 10 tips for Oracle performance
Guy Harrison
 
Oracle SQL Tuning
Oracle SQL Tuning
Alex Zaballa
 
Using AWR for SQL Analysis
Using AWR for SQL Analysis
Texas Memory Systems, and IBM Company
 
In Search of Plan Stability - Part 1
In Search of Plan Stability - Part 1
Enkitec
 
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Exploring Oracle Database Performance Tuning Best Practices for DBAs and Deve...
Aaron Shilo
 
Think Exa!
Think Exa!
Enkitec
 
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_sfsf
Mao Geng
 
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
John Beresniewicz
 
Oracle Sql Tuning
Oracle Sql Tuning
Chris Adkin
 
Oracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance Tuning
OracleTrainings
 
Oracle Data Redaction - EOUC
Oracle Data Redaction - EOUC
Alex Zaballa
 
Oracle Database 12c - Data Redaction
Oracle Database 12c - Data Redaction
Alex Zaballa
 
Oracle Database Performance Tuning Basics
Oracle Database Performance Tuning Basics
nitin anjankar
 
Oracle SQL Tuning
Oracle SQL Tuning
Alex Zaballa
 
Oracle DB Performance Tuning Tips
Oracle DB Performance Tuning Tips
Asanka Dilruk
 
Fatkulin hotsos 2014
Fatkulin hotsos 2014
Enkitec
 
Advanced t sql - querying and programming inside sql server
Advanced t sql - querying and programming inside sql server
Vinod Kumar
 
Oracle Data Redaction
Oracle Data Redaction
Alex Zaballa
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the Trade
Enkitec
 
Exadata and the Oracle Optimizer: The Untold Story
Exadata and the Oracle Optimizer: The Untold Story
Enkitec
 
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 Know
Alex Zaballa
 
Indexing Strategies for Oracle Databases - Beyond the Create Index Statement
Indexing Strategies for Oracle Databases - Beyond the Create Index Statement
Sean Scott
 
Query optimizer vivek sharma
Query optimizer vivek sharma
aioughydchapter
 
resource governor
resource governor
Aaron Shilo
 
Advanced tips for making Oracle databases faster
Advanced tips for making Oracle databases faster
SolarWinds
 
O_Need-for-Speed_Top-Five-Oracle-Performance-Tuning-Tips_NYOUG.pdf
O_Need-for-Speed_Top-Five-Oracle-Performance-Tuning-Tips_NYOUG.pdf
cookie1969
 

More Related Content

What's hot (20)

Think Exa!
Think Exa!
Enkitec
 
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_sfsf
Mao Geng
 
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
John Beresniewicz
 
Oracle Sql Tuning
Oracle Sql Tuning
Chris Adkin
 
Oracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance Tuning
OracleTrainings
 
Oracle Data Redaction - EOUC
Oracle Data Redaction - EOUC
Alex Zaballa
 
Oracle Database 12c - Data Redaction
Oracle Database 12c - Data Redaction
Alex Zaballa
 
Oracle Database Performance Tuning Basics
Oracle Database Performance Tuning Basics
nitin anjankar
 
Oracle SQL Tuning
Oracle SQL Tuning
Alex Zaballa
 
Oracle DB Performance Tuning Tips
Oracle DB Performance Tuning Tips
Asanka Dilruk
 
Fatkulin hotsos 2014
Fatkulin hotsos 2014
Enkitec
 
Advanced t sql - querying and programming inside sql server
Advanced t sql - querying and programming inside sql server
Vinod Kumar
 
Oracle Data Redaction
Oracle Data Redaction
Alex Zaballa
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the Trade
Enkitec
 
Exadata and the Oracle Optimizer: The Untold Story
Exadata and the Oracle Optimizer: The Untold Story
Enkitec
 
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 Know
Alex Zaballa
 
Indexing Strategies for Oracle Databases - Beyond the Create Index Statement
Indexing Strategies for Oracle Databases - Beyond the Create Index Statement
Sean Scott
 
Query optimizer vivek sharma
Query optimizer vivek sharma
aioughydchapter
 
resource governor
resource governor
Aaron Shilo
 
Think Exa!
Think Exa!
Enkitec
 
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_sfsf
Mao Geng
 
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
John Beresniewicz
 
Oracle Sql Tuning
Oracle Sql Tuning
Chris Adkin
 
Oracle Performance Tuning Training | Oracle Performance Tuning
Oracle Performance Tuning Training | Oracle Performance Tuning
OracleTrainings
 
Oracle Data Redaction - EOUC
Oracle Data Redaction - EOUC
Alex Zaballa
 
Oracle Database 12c - Data Redaction
Oracle Database 12c - Data Redaction
Alex Zaballa
 
Oracle Database Performance Tuning Basics
Oracle Database Performance Tuning Basics
nitin anjankar
 
Oracle DB Performance Tuning Tips
Oracle DB Performance Tuning Tips
Asanka Dilruk
 
Fatkulin hotsos 2014
Fatkulin hotsos 2014
Enkitec
 
Advanced t sql - querying and programming inside sql server
Advanced t sql - querying and programming inside sql server
Vinod Kumar
 
Oracle Data Redaction
Oracle Data Redaction
Alex Zaballa
 
Oracle Performance Tools of the Trade
Oracle Performance Tools of the Trade
Enkitec
 
Exadata and the Oracle Optimizer: The Untold Story
Exadata and the Oracle Optimizer: The Untold Story
Enkitec
 
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 Know
Alex Zaballa
 
Indexing Strategies for Oracle Databases - Beyond the Create Index Statement
Indexing Strategies for Oracle Databases - Beyond the Create Index Statement
Sean Scott
 
Query optimizer vivek sharma
Query optimizer vivek sharma
aioughydchapter
 
resource governor
resource governor
Aaron Shilo
 

Similar to An Approach to Sql tuning - Part 1 (20)

Advanced tips for making Oracle databases faster
Advanced tips for making Oracle databases faster
SolarWinds
 
O_Need-for-Speed_Top-Five-Oracle-Performance-Tuning-Tips_NYOUG.pdf
O_Need-for-Speed_Top-Five-Oracle-Performance-Tuning-Tips_NYOUG.pdf
cookie1969
 
31063115_1679409488310Developer_Tuning_Tips_-_UTOUG_Mar_2023.pdf
31063115_1679409488310Developer_Tuning_Tips_-_UTOUG_Mar_2023.pdf
TricantinoLopezPerez
 
SQL Tuning 101
SQL Tuning 101
Carlos Sierra
 
sqltuning101-170419021007-2.pdf
sqltuning101-170419021007-2.pdf
TricantinoLopezPerez
 
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
cookie1969
 
Microsoft SQL Server Query Tuning
Microsoft SQL Server Query Tuning
Mark Ginnebaugh
 
SQL Server Query Tuning Tips - Get it Right the First Time
SQL Server Query Tuning Tips - Get it Right the First Time
Dean Richards
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
Mark Ginnebaugh
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
guest9d79e073
 
Performance Tuning with Execution Plans
Performance Tuning with Execution Plans
Grant Fritchey
 
05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptx
KareemBullard1
 
Part3 Explain the Explain Plan
Part3 Explain the Explain Plan
Maria Colgan
 
SQL Optimization With Trace Data And Dbms Xplan V6
SQL Optimization With Trace Data And Dbms Xplan V6
Mahesh Vallampati
 
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Guatemala User Group
 
Discovering the Plan Cache (#SQLSat 206)
Discovering the Plan Cache (#SQLSat 206)
Jason Strate
 
SQL Server Tuning to Improve Database Performance
SQL Server Tuning to Improve Database Performance
Mark Ginnebaugh
 
Sql tuning
Sql tuning
Wilson Harawoola
 
Sql query analyzer & maintenance
Sql query analyzer & maintenance
nspyrenet
 
Discovering the plan cache (#SQLSat211)
Discovering the plan cache (#SQLSat211)
Jason Strate
 
Advanced tips for making Oracle databases faster
Advanced tips for making Oracle databases faster
SolarWinds
 
O_Need-for-Speed_Top-Five-Oracle-Performance-Tuning-Tips_NYOUG.pdf
O_Need-for-Speed_Top-Five-Oracle-Performance-Tuning-Tips_NYOUG.pdf
cookie1969
 
31063115_1679409488310Developer_Tuning_Tips_-_UTOUG_Mar_2023.pdf
31063115_1679409488310Developer_Tuning_Tips_-_UTOUG_Mar_2023.pdf
TricantinoLopezPerez
 
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
NOCOUG_201311_Fine_Tuning_Execution_Plans.pdf
cookie1969
 
Microsoft SQL Server Query Tuning
Microsoft SQL Server Query Tuning
Mark Ginnebaugh
 
SQL Server Query Tuning Tips - Get it Right the First Time
SQL Server Query Tuning Tips - Get it Right the First Time
Dean Richards
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
Mark Ginnebaugh
 
Brad McGehee Intepreting Execution Plans Mar09
Brad McGehee Intepreting Execution Plans Mar09
guest9d79e073
 
Performance Tuning with Execution Plans
Performance Tuning with Execution Plans
Grant Fritchey
 
05_DP_300T00A_Optimize.pptx
05_DP_300T00A_Optimize.pptx
KareemBullard1
 
Part3 Explain the Explain Plan
Part3 Explain the Explain Plan
Maria Colgan
 
SQL Optimization With Trace Data And Dbms Xplan V6
SQL Optimization With Trace Data And Dbms Xplan V6
Mahesh Vallampati
 
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Understanding Query Optimization with ‘regular’ and ‘Exadata’ Oracle
Guatemala User Group
 
Discovering the Plan Cache (#SQLSat 206)
Discovering the Plan Cache (#SQLSat 206)
Jason Strate
 
SQL Server Tuning to Improve Database Performance
SQL Server Tuning to Improve Database Performance
Mark Ginnebaugh
 
Sql query analyzer & maintenance
Sql query analyzer & maintenance
nspyrenet
 
Discovering the plan cache (#SQLSat211)
Discovering the plan cache (#SQLSat211)
Jason Strate
 
Ad

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...
Navneet Upneja
 
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's
Navneet Upneja
 
Role of-analytics-in-db as-life
Role of-analytics-in-db as-life
Navneet Upneja
 
Oracle Dataguard
Oracle Dataguard
Navneet Upneja
 
ORACLE 12C-New-Features
ORACLE 12C-New-Features
Navneet Upneja
 
Flashback - The Time Machine..
Flashback - The Time Machine..
Navneet Upneja
 
Oracle 12 c new-features
Oracle 12 c new-features
Navneet Upneja
 
DataGuard - Oracle's Time Machine
DataGuard - Oracle's Time Machine
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...
Navneet Upneja
 
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's
Navneet Upneja
 
Role of-analytics-in-db as-life
Role of-analytics-in-db as-life
Navneet Upneja
 
ORACLE 12C-New-Features
ORACLE 12C-New-Features
Navneet Upneja
 
Flashback - The Time Machine..
Flashback - The Time Machine..
Navneet Upneja
 
Oracle 12 c new-features
Oracle 12 c new-features
Navneet Upneja
 
DataGuard - Oracle's Time Machine
DataGuard - Oracle's Time Machine
Navneet Upneja
 
Ad

Recently uploaded (20)

SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
Precisely
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
Precisely
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Viral>Wondershare Filmora 14.5.18.12900 Crack Free Download
Puppy jhon
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Integration of Utility Data into 3D BIM Models Using a 3D Solids Modeling Wor...
Safe Software
 
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Seminar: New Data: Passkey Adoption in the Workforce.pptx
FIDO Alliance
 
Down the Rabbit Hole – Solving 5 Training Roadblocks
Down the Rabbit Hole – Solving 5 Training Roadblocks
Rustici Software
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Bridging the divide: A conversation on tariffs today in the book industry - T...
Bridging the divide: A conversation on tariffs today in the book industry - T...
BookNet Canada
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Floods in Valencia: Two FME-Powered Stories of Data Resilience
Safe Software
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 

An Approach to Sql tuning - Part 1

  • 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'));
  • 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
  • 33. In the Next Session.. • Interpreting Execution Plan • 10046 Trace • CBO Basics • Finding out the bottlenecks • Much More…