SlideShare una empresa de Scribd logo
1 de 49
Descargar para leer sin conexión
SQL Tuning 101
The three pillars of SQL Tuning:
Diagnostics Collection, Root Cause Analysis and
Remediation
Carlos Sierra
Agenda
• Motivation
• Methodology
– Diagnostics Collection
– Root Cause Analysis
– Remediation
• Some Important Topics
– Execution Plan
– Cost-based Optimizer
– Plan Stability
• Free Tools
Motivation
• One bad SQL can degrade overall DB performance!
• SQL Tuning is:
– A Complex Task
– Part Science and part Art
– The Responsibility of WHO?
• DBA?
• Developer?
• Oracle?
• Application Vendor?
Methodology
The three pillars of SQL Tuning
1. Good Practices
2. Diagnostics Collection
3. Root Cause Analysis (RCA)
4. Remediation
I. Good Practices
• The forgotten pillar of SQL Tuning
• Quid pro Quo (e.g. This for That or Give and Take)
– Be nice to the CBO and the CBO will be nice to you
• A healthy environment requires less SQL Tuning
• A win-win!
• Except for Consultants like myself!
Some Good Practices
• Start with a modern and solid database release
• Reset all CBO related parameters (and some more)
• Gather CBO Statistics as per Application or Product
– Automatic task does a decent job on 11.2.0.4+
• Write reasonable SQL
– Use the product as designed and avoid weird SQL
– If SQL is too long or too complex the CBO will struggle
Partial list of Parameters to Reset
• optimizer_features_enable
• optimizer_index_cost_adj
• optimizer_index_caching
• db_file_multiblock_read_count (not CBO exclusive)
• cursor_sharing (not an optimizer parameter)
• optimizer_dynamic_sampling
• optimizer_mode
II. Diagnostics Collection
a) Identify SQL_ID
b) Use Oracle-product base Tools
c) Supplement with specialized Tools
II.a Identify SQL_ID
• Oracle Enterprise Manager (OEM)
– [ OEM] [ Database | Grid | Cloud ] Control
• Automatic Workload Repository (AWR)
• Statspack (SP)
• SQL Trace (and TKPROF)
• V$ dynamic views (e.g. V$SQL and V$SESSION)
II.b Oracle-product base Tools
• SQL Trace (and TKPROF)
• Active Session History (ASH)
• EXPLAIN PLAN FOR
• AUTOTRACE
• SQL Developer
• DBMS_XPLAN
• SQL Monitor
SQL Trace
• ALTER SESSION SET
– SQL_TRACE = [ TRUE | FALSE ]
– EVENTS ‘10046 trace name context forever, level N’
• N = 1: all executions (10g-) or 1st execution (11g+)
• N = 4: Binds
• N = 8: Waits
• N = 12 = 4 + 8
• N = 16: each execution (11g+)
• N = 64: 1st + each where DB time > 1min (11.2.0.2+)
Where is my Trace?
• V$DIAG_INFO (11.1+)
• USER_DUMP_DEST (deprecated 12c)
TKPROF: SQL Text and DB Calls
TKPROF: Execution Plan and Wait Events
Active Session History (ASH)
• 1 sec snapshots of V$SESSION
• Every 10 ASH samples into AWR (10 sec granularity)
• Sessions “ON CPU” or “WAITING” (non-idle)
• Multiple Dimensions
• Excellent repository for performance data mining
• Requires Oracle Diagnostics Pack!
SQL Trace vs. ASH
Pros
• Precise
• Free
Pros
• Always available
• Multi-dimensional repository
• Plan line granularity (11g+)
Cons
• Re-execute transaction
• Waits per cursor
– No plan line granularity
Cons
• Requires Diagnostics Pack
EXPLAIN PLAN FOR
• Actual SQL is not executed
• Blind to Bind Peeking, thus unreliable with Binds
SET AUTOTRACE ON
• Actual SQL is executed
• Includes small subset of Session Statistics
Query Output and Execution Plan
Predicate Information and Session Stats
SQL Developer
DBMS_XPLAN
• DISPLAY (from PLAN_TABLE)
• DISPLAY_CURSOR
• DISPLAY_AWR
• DISPLAY_SQL_PLAN_BASELINE
• DISPLAY_SQL_SET
• SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY%());
DBMS_XPLAN.DISPLAY_CURSOR
• SQL_ID
• CURSOR_CHILD_NO (defaults to 0!)
• FORMAT
– TYPICAL = DEFAULT
– ALL = TYPICAL + QB + PROJECTION + ALIAS + REMOTE
– ADVANCED = ALL + OUTLINE + BINDS
– ALLSTATS = IOSTATS + MEMSTATS (all executions)
– ALLSTATS LAST (last execution)
– ADAPTIVE (12c)
Sample query with hints and binds
SQL Monitor
• Part of the Oracle Tuning Pack
• Tabular and Graphical Execution Plan
• Timeline per Plan Line
• Binds and Predicates
• Nice and intuitive
• Executed from OEM or SQL*Plus
II.c Specialized Tools
• SQLTXPLAIN (a.k.a. SQLT)
– My Oracle Support (MOS) 215187.1
• SQLHC
– MOS 1366133.1
• SQLd360
– By Mauro Pagano
• Others?
III. Root Cause Analysis
• This is where you want to spend your time!
• Go over all the output of your specialized tool
• Look for correlations and possible causation
• Put yourself in the shoes of the Optimizer
• Question everything (is there a better way?)
• Ask for help after you have done your homework
• Enjoy the ride!
Typical Steps
1. Find where the time is spent (plan line)
– Too many executions or too much time per exec?
2. Validate estimated rows versus actual rows
– If off determine why (deficient statistics maybe?)
3. What is the history of this SQL?
– Can you find a better performing plan?
4. Can you make perfect sense of the SQL and plan?
IV. Remediation
• Explore multiple possibilities
– And try to prove yourself wrong!
• Implement the smallest-scope fix
– Avoid system-wide changes unless you are rock solid!
• Avoid guesses and assumptions (piñata method)
– Too many people out there are “tuning” blind-folded!
• Trust nobody! (be skeptic and test thoroughly)
Three Important Topics
1. Execution Plan
2. Cost-based Optimizer
3. Plan Stability
1. Execution Plan
• If you do not understand the SQL or the Execution
Plan stop right there!
• From SQL text you can draw a diagram if that helps
• To understand the Execution Plan start small
– Review a two-tables query and review plan
– Move to a three-tables query and review plan
– Introduce subqueries and more complex constructions
2. Cost-based Optimizer
• CBO was released on 7.3 (circa February 1996)
• A large and complex piece of software enhanced
for two decades
• By design the CBO produces an optimal execution
plan according to some representation of the data
– This means: execution plans are expected to change!
– Breathe deep and embrace the change!
3. Plan Stability
• Most DBAs hate Execution Plan changes
– They never hear of changes for the better!
• To remediate undesired plan changes we do have
several Plan Stability techniques
– SQL Plan Management (Baselines) from 11g
– SQL Profiles from 10g
– Deprecated Stored Outlines from 9i
– And then some others (SQL Patches and CBO Hints)
Popular Free Diagnostics Tools
• SQLTXPLAIN
• SQLHC
• SQLd360
• Stand-alone scripts
SQLTXPLAIN
SQLd360
SQLd360 Plan Tree
SQLT XPLAIN vs. SQLd360
Pros
• Oracle Support Standard
• Free (requires MOS account)
• Comprehensive and mature
Pros
• Free Software (no strings)
• Installs nothing on database
• Graphical visualization of data
Cons
• Requires installation
• HTML Tables (no charts)
Cons
• Still young (frequent releases)
SQL Tuning Road Map
1. Start with a clean and healthy environment
2. Identify SQL_ID
3. Collect diagnostics using comprehensive tools
4. Spend time analyzing diagnostics collected
5. Determine root cause
6. Explore remediation actions
7. Test and implement solution
Questions
The End
• http://carlos-sierra.net/
– Blog and downloads
• carlos.sierra.usa@gmail.com
– Questions and follow-up
• SQL Tuning is more about understanding
what your eyes see at first

Más contenido relacionado

Similar a sqltuning101-170419021007-2.pdf

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
 
Winning performance challenges in oracle standard editions
Winning performance challenges in oracle standard editionsWinning performance challenges in oracle standard editions
Winning performance challenges in oracle standard editionsPini Dibask
 
Collaborate 2019 - How to Understand an AWR Report
Collaborate 2019 - How to Understand an AWR ReportCollaborate 2019 - How to Understand an AWR Report
Collaborate 2019 - How to Understand an AWR ReportAlfredo Krieg
 
Oracle Database Performance Tuning Basics
Oracle Database Performance Tuning BasicsOracle Database Performance Tuning Basics
Oracle Database Performance Tuning Basicsnitin anjankar
 
Winning performance challenges in oracle standard editions
Winning performance challenges in oracle standard editionsWinning performance challenges in oracle standard editions
Winning performance challenges in oracle standard editionsPini Dibask
 
Performance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and UnderscoresPerformance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and UnderscoresJitendra Singh
 
Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsEnkitec
 
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
 
In Search of Plan Stability - Part 1
In Search of Plan Stability - Part 1In Search of Plan Stability - Part 1
In Search of Plan Stability - Part 1Enkitec
 
Understanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginnersUnderstanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginnersCarlos Sierra
 
collab2011-tuning-ebusiness-421966.pdf
collab2011-tuning-ebusiness-421966.pdfcollab2011-tuning-ebusiness-421966.pdf
collab2011-tuning-ebusiness-421966.pdfElboulmaniMohamed
 
Getting optimal performance from oracle e business suite
Getting optimal performance from oracle e business suiteGetting optimal performance from oracle e business suite
Getting optimal performance from oracle e business suiteaioughydchapter
 
Getting optimal performance from oracle e business suite(aioug aug2015)
Getting optimal performance from oracle e business suite(aioug aug2015)Getting optimal performance from oracle e business suite(aioug aug2015)
Getting optimal performance from oracle e business suite(aioug aug2015)pasalapudi123
 
A data driven etl test framework sqlsat madison
A data driven etl test framework sqlsat madisonA data driven etl test framework sqlsat madison
A data driven etl test framework sqlsat madisonTerry Bunio
 
Collaborate 2011-tuning-ebusiness-416502
Collaborate 2011-tuning-ebusiness-416502Collaborate 2011-tuning-ebusiness-416502
Collaborate 2011-tuning-ebusiness-416502kaziul Islam Bulbul
 
Oracle OpenWorld 2016 Review - Focus on Data, BigData, Streaming Data, Machin...
Oracle OpenWorld 2016 Review - Focus on Data, BigData, Streaming Data, Machin...Oracle OpenWorld 2016 Review - Focus on Data, BigData, Streaming Data, Machin...
Oracle OpenWorld 2016 Review - Focus on Data, BigData, Streaming Data, Machin...Lucas Jellema
 
AWS Redshift Introduction - Big Data Analytics
AWS Redshift Introduction - Big Data AnalyticsAWS Redshift Introduction - Big Data Analytics
AWS Redshift Introduction - Big Data AnalyticsKeeyong Han
 
T sql performance guidelines for better db stress powers
T sql performance guidelines for better db stress powersT sql performance guidelines for better db stress powers
T sql performance guidelines for better db stress powersShehap Elnagar
 

Similar a sqltuning101-170419021007-2.pdf (20)

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
 
Breaking data
Breaking dataBreaking data
Breaking data
 
Winning performance challenges in oracle standard editions
Winning performance challenges in oracle standard editionsWinning performance challenges in oracle standard editions
Winning performance challenges in oracle standard editions
 
Collaborate 2019 - How to Understand an AWR Report
Collaborate 2019 - How to Understand an AWR ReportCollaborate 2019 - How to Understand an AWR Report
Collaborate 2019 - How to Understand an AWR Report
 
Oracle Database Performance Tuning Basics
Oracle Database Performance Tuning BasicsOracle Database Performance Tuning Basics
Oracle Database Performance Tuning Basics
 
Winning performance challenges in oracle standard editions
Winning performance challenges in oracle standard editionsWinning performance challenges in oracle standard editions
Winning performance challenges in oracle standard editions
 
Performance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and UnderscoresPerformance Stability, Tips and Tricks and Underscores
Performance Stability, Tips and Tricks and Underscores
 
Oracle Performance Tuning Fundamentals
Oracle Performance Tuning FundamentalsOracle Performance Tuning Fundamentals
Oracle Performance Tuning Fundamentals
 
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
 
In Search of Plan Stability - Part 1
In Search of Plan Stability - Part 1In Search of Plan Stability - Part 1
In Search of Plan Stability - Part 1
 
Understanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginnersUnderstanding SQL Trace, TKPROF and Execution Plan for beginners
Understanding SQL Trace, TKPROF and Execution Plan for beginners
 
collab2011-tuning-ebusiness-421966.pdf
collab2011-tuning-ebusiness-421966.pdfcollab2011-tuning-ebusiness-421966.pdf
collab2011-tuning-ebusiness-421966.pdf
 
Getting optimal performance from oracle e business suite
Getting optimal performance from oracle e business suiteGetting optimal performance from oracle e business suite
Getting optimal performance from oracle e business suite
 
Getting optimal performance from oracle e business suite(aioug aug2015)
Getting optimal performance from oracle e business suite(aioug aug2015)Getting optimal performance from oracle e business suite(aioug aug2015)
Getting optimal performance from oracle e business suite(aioug aug2015)
 
A data driven etl test framework sqlsat madison
A data driven etl test framework sqlsat madisonA data driven etl test framework sqlsat madison
A data driven etl test framework sqlsat madison
 
Collaborate 2011-tuning-ebusiness-416502
Collaborate 2011-tuning-ebusiness-416502Collaborate 2011-tuning-ebusiness-416502
Collaborate 2011-tuning-ebusiness-416502
 
Oow2016 review-db-dev-bigdata-BI
Oow2016 review-db-dev-bigdata-BIOow2016 review-db-dev-bigdata-BI
Oow2016 review-db-dev-bigdata-BI
 
Oracle OpenWorld 2016 Review - Focus on Data, BigData, Streaming Data, Machin...
Oracle OpenWorld 2016 Review - Focus on Data, BigData, Streaming Data, Machin...Oracle OpenWorld 2016 Review - Focus on Data, BigData, Streaming Data, Machin...
Oracle OpenWorld 2016 Review - Focus on Data, BigData, Streaming Data, Machin...
 
AWS Redshift Introduction - Big Data Analytics
AWS Redshift Introduction - Big Data AnalyticsAWS Redshift Introduction - Big Data Analytics
AWS Redshift Introduction - Big Data Analytics
 
T sql performance guidelines for better db stress powers
T sql performance guidelines for better db stress powersT sql performance guidelines for better db stress powers
T sql performance guidelines for better db stress powers
 

Más de TricantinoLopezPerez

Oracle Wait Events That Everyone Should Know.ppt
Oracle Wait Events That Everyone Should Know.pptOracle Wait Events That Everyone Should Know.ppt
Oracle Wait Events That Everyone Should Know.pptTricantinoLopezPerez
 
pdfslide.net_em12c-capacity-planning-with-oem-metrics_2.pdf
pdfslide.net_em12c-capacity-planning-with-oem-metrics_2.pdfpdfslide.net_em12c-capacity-planning-with-oem-metrics_2.pdf
pdfslide.net_em12c-capacity-planning-with-oem-metrics_2.pdfTricantinoLopezPerez
 
exadata-database-machine-kpis-3224944.pdf
exadata-database-machine-kpis-3224944.pdfexadata-database-machine-kpis-3224944.pdf
exadata-database-machine-kpis-3224944.pdfTricantinoLopezPerez
 
kscope2013vst-130627142814-phpapp02.pdf
kscope2013vst-130627142814-phpapp02.pdfkscope2013vst-130627142814-phpapp02.pdf
kscope2013vst-130627142814-phpapp02.pdfTricantinoLopezPerez
 
TGorman Collab16 UnixTools 20160411.pdf
TGorman Collab16 UnixTools 20160411.pdfTGorman Collab16 UnixTools 20160411.pdf
TGorman Collab16 UnixTools 20160411.pdfTricantinoLopezPerez
 

Más de TricantinoLopezPerez (11)

con9578-2088758.pdf
con9578-2088758.pdfcon9578-2088758.pdf
con9578-2088758.pdf
 
linux-memory-explained.pdf
linux-memory-explained.pdflinux-memory-explained.pdf
linux-memory-explained.pdf
 
Oracle Wait Events That Everyone Should Know.ppt
Oracle Wait Events That Everyone Should Know.pptOracle Wait Events That Everyone Should Know.ppt
Oracle Wait Events That Everyone Should Know.ppt
 
pdfslide.net_em12c-capacity-planning-with-oem-metrics_2.pdf
pdfslide.net_em12c-capacity-planning-with-oem-metrics_2.pdfpdfslide.net_em12c-capacity-planning-with-oem-metrics_2.pdf
pdfslide.net_em12c-capacity-planning-with-oem-metrics_2.pdf
 
exadata-database-machine-kpis-3224944.pdf
exadata-database-machine-kpis-3224944.pdfexadata-database-machine-kpis-3224944.pdf
exadata-database-machine-kpis-3224944.pdf
 
TA110_System_Capacity_Plan.doc
TA110_System_Capacity_Plan.docTA110_System_Capacity_Plan.doc
TA110_System_Capacity_Plan.doc
 
kscope2013vst-130627142814-phpapp02.pdf
kscope2013vst-130627142814-phpapp02.pdfkscope2013vst-130627142814-phpapp02.pdf
kscope2013vst-130627142814-phpapp02.pdf
 
TGorman Collab16 UnixTools 20160411.pdf
TGorman Collab16 UnixTools 20160411.pdfTGorman Collab16 UnixTools 20160411.pdf
TGorman Collab16 UnixTools 20160411.pdf
 
BrownbagIntrotosqltuning.ppt
BrownbagIntrotosqltuning.pptBrownbagIntrotosqltuning.ppt
BrownbagIntrotosqltuning.ppt
 
sqltuningcardinality1(1).ppt
sqltuningcardinality1(1).pptsqltuningcardinality1(1).ppt
sqltuningcardinality1(1).ppt
 
ash-1-130820122404-phpapp01.pdf
ash-1-130820122404-phpapp01.pdfash-1-130820122404-phpapp01.pdf
ash-1-130820122404-phpapp01.pdf
 

Último

Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Colleen Farrelly
 
9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home ServiceSapana Sha
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsappssapnasaifi408
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfgstagge
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改yuu sss
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPramod Kumar Srivastava
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 217djon017
 
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSINGmarianagonzalez07
 
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...limedy534
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfSocial Samosa
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort servicejennyeacort
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...Boston Institute of Analytics
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...Florian Roscheck
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.natarajan8993
 
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一fhwihughh
 
Identifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanIdentifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanMYRABACSAFRA2
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一F sss
 
Multiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdfMultiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdfchwongval
 

Último (20)

Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024Generative AI for Social Good at Open Data Science East 2024
Generative AI for Social Good at Open Data Science East 2024
 
9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
 
RadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdfRadioAdProWritingCinderellabyButleri.pdf
RadioAdProWritingCinderellabyButleri.pdf
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
 
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2Easter Eggs From Star Wars and in cars 1 and 2
Easter Eggs From Star Wars and in cars 1 and 2
 
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
2006_GasProcessing_HB (1).pdf HYDROCARBON PROCESSING
 
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
Effects of Smartphone Addiction on the Academic Performances of Grades 9 to 1...
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.
 
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
办理学位证纽约大学毕业证(NYU毕业证书)原版一比一
 
Identifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population MeanIdentifying Appropriate Test Statistics Involving Population Mean
Identifying Appropriate Test Statistics Involving Population Mean
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
 
Multiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdfMultiple time frame trading analysis -brianshannon.pdf
Multiple time frame trading analysis -brianshannon.pdf
 

sqltuning101-170419021007-2.pdf

  • 1. SQL Tuning 101 The three pillars of SQL Tuning: Diagnostics Collection, Root Cause Analysis and Remediation Carlos Sierra
  • 2. Agenda • Motivation • Methodology – Diagnostics Collection – Root Cause Analysis – Remediation • Some Important Topics – Execution Plan – Cost-based Optimizer – Plan Stability • Free Tools
  • 3. Motivation • One bad SQL can degrade overall DB performance! • SQL Tuning is: – A Complex Task – Part Science and part Art – The Responsibility of WHO? • DBA? • Developer? • Oracle? • Application Vendor?
  • 4. Methodology The three pillars of SQL Tuning 1. Good Practices 2. Diagnostics Collection 3. Root Cause Analysis (RCA) 4. Remediation
  • 5. I. Good Practices • The forgotten pillar of SQL Tuning • Quid pro Quo (e.g. This for That or Give and Take) – Be nice to the CBO and the CBO will be nice to you • A healthy environment requires less SQL Tuning • A win-win! • Except for Consultants like myself!
  • 6. Some Good Practices • Start with a modern and solid database release • Reset all CBO related parameters (and some more) • Gather CBO Statistics as per Application or Product – Automatic task does a decent job on 11.2.0.4+ • Write reasonable SQL – Use the product as designed and avoid weird SQL – If SQL is too long or too complex the CBO will struggle
  • 7. Partial list of Parameters to Reset • optimizer_features_enable • optimizer_index_cost_adj • optimizer_index_caching • db_file_multiblock_read_count (not CBO exclusive) • cursor_sharing (not an optimizer parameter) • optimizer_dynamic_sampling • optimizer_mode
  • 8. II. Diagnostics Collection a) Identify SQL_ID b) Use Oracle-product base Tools c) Supplement with specialized Tools
  • 9. II.a Identify SQL_ID • Oracle Enterprise Manager (OEM) – [ OEM] [ Database | Grid | Cloud ] Control • Automatic Workload Repository (AWR) • Statspack (SP) • SQL Trace (and TKPROF) • V$ dynamic views (e.g. V$SQL and V$SESSION)
  • 10. II.b Oracle-product base Tools • SQL Trace (and TKPROF) • Active Session History (ASH) • EXPLAIN PLAN FOR • AUTOTRACE • SQL Developer • DBMS_XPLAN • SQL Monitor
  • 11. SQL Trace • ALTER SESSION SET – SQL_TRACE = [ TRUE | FALSE ] – EVENTS ‘10046 trace name context forever, level N’ • N = 1: all executions (10g-) or 1st execution (11g+) • N = 4: Binds • N = 8: Waits • N = 12 = 4 + 8 • N = 16: each execution (11g+) • N = 64: 1st + each where DB time > 1min (11.2.0.2+)
  • 12. Where is my Trace? • V$DIAG_INFO (11.1+) • USER_DUMP_DEST (deprecated 12c)
  • 13. TKPROF: SQL Text and DB Calls
  • 14. TKPROF: Execution Plan and Wait Events
  • 15. Active Session History (ASH) • 1 sec snapshots of V$SESSION • Every 10 ASH samples into AWR (10 sec granularity) • Sessions “ON CPU” or “WAITING” (non-idle) • Multiple Dimensions • Excellent repository for performance data mining • Requires Oracle Diagnostics Pack!
  • 16. SQL Trace vs. ASH Pros • Precise • Free Pros • Always available • Multi-dimensional repository • Plan line granularity (11g+) Cons • Re-execute transaction • Waits per cursor – No plan line granularity Cons • Requires Diagnostics Pack
  • 17. EXPLAIN PLAN FOR • Actual SQL is not executed • Blind to Bind Peeking, thus unreliable with Binds
  • 18.
  • 19. SET AUTOTRACE ON • Actual SQL is executed • Includes small subset of Session Statistics
  • 20. Query Output and Execution Plan
  • 21. Predicate Information and Session Stats
  • 23.
  • 24. DBMS_XPLAN • DISPLAY (from PLAN_TABLE) • DISPLAY_CURSOR • DISPLAY_AWR • DISPLAY_SQL_PLAN_BASELINE • DISPLAY_SQL_SET • SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY%());
  • 25. DBMS_XPLAN.DISPLAY_CURSOR • SQL_ID • CURSOR_CHILD_NO (defaults to 0!) • FORMAT – TYPICAL = DEFAULT – ALL = TYPICAL + QB + PROJECTION + ALIAS + REMOTE – ADVANCED = ALL + OUTLINE + BINDS – ALLSTATS = IOSTATS + MEMSTATS (all executions) – ALLSTATS LAST (last execution) – ADAPTIVE (12c)
  • 26. Sample query with hints and binds
  • 27.
  • 28. SQL Monitor • Part of the Oracle Tuning Pack • Tabular and Graphical Execution Plan • Timeline per Plan Line • Binds and Predicates • Nice and intuitive • Executed from OEM or SQL*Plus
  • 29.
  • 30.
  • 31. II.c Specialized Tools • SQLTXPLAIN (a.k.a. SQLT) – My Oracle Support (MOS) 215187.1 • SQLHC – MOS 1366133.1 • SQLd360 – By Mauro Pagano • Others?
  • 32. III. Root Cause Analysis • This is where you want to spend your time! • Go over all the output of your specialized tool • Look for correlations and possible causation • Put yourself in the shoes of the Optimizer • Question everything (is there a better way?) • Ask for help after you have done your homework • Enjoy the ride!
  • 33. Typical Steps 1. Find where the time is spent (plan line) – Too many executions or too much time per exec? 2. Validate estimated rows versus actual rows – If off determine why (deficient statistics maybe?) 3. What is the history of this SQL? – Can you find a better performing plan? 4. Can you make perfect sense of the SQL and plan?
  • 34. IV. Remediation • Explore multiple possibilities – And try to prove yourself wrong! • Implement the smallest-scope fix – Avoid system-wide changes unless you are rock solid! • Avoid guesses and assumptions (piñata method) – Too many people out there are “tuning” blind-folded! • Trust nobody! (be skeptic and test thoroughly)
  • 35. Three Important Topics 1. Execution Plan 2. Cost-based Optimizer 3. Plan Stability
  • 36. 1. Execution Plan • If you do not understand the SQL or the Execution Plan stop right there! • From SQL text you can draw a diagram if that helps • To understand the Execution Plan start small – Review a two-tables query and review plan – Move to a three-tables query and review plan – Introduce subqueries and more complex constructions
  • 37. 2. Cost-based Optimizer • CBO was released on 7.3 (circa February 1996) • A large and complex piece of software enhanced for two decades • By design the CBO produces an optimal execution plan according to some representation of the data – This means: execution plans are expected to change! – Breathe deep and embrace the change!
  • 38. 3. Plan Stability • Most DBAs hate Execution Plan changes – They never hear of changes for the better! • To remediate undesired plan changes we do have several Plan Stability techniques – SQL Plan Management (Baselines) from 11g – SQL Profiles from 10g – Deprecated Stored Outlines from 9i – And then some others (SQL Patches and CBO Hints)
  • 39. Popular Free Diagnostics Tools • SQLTXPLAIN • SQLHC • SQLd360 • Stand-alone scripts
  • 42.
  • 44.
  • 45.
  • 46. SQLT XPLAIN vs. SQLd360 Pros • Oracle Support Standard • Free (requires MOS account) • Comprehensive and mature Pros • Free Software (no strings) • Installs nothing on database • Graphical visualization of data Cons • Requires installation • HTML Tables (no charts) Cons • Still young (frequent releases)
  • 47. SQL Tuning Road Map 1. Start with a clean and healthy environment 2. Identify SQL_ID 3. Collect diagnostics using comprehensive tools 4. Spend time analyzing diagnostics collected 5. Determine root cause 6. Explore remediation actions 7. Test and implement solution
  • 49. The End • http://carlos-sierra.net/ – Blog and downloads • carlos.sierra.usa@gmail.com – Questions and follow-up • SQL Tuning is more about understanding what your eyes see at first