SQL
Elapsed Time
  Analysis


  Craig A. Shallahamer
 Founder - OraPub, Inc.
   craig@orapub.com


                SQL	
  Elapsed	
  Time	
  Analysis	
  
OraPub is about Oracle performance.
•  OraPub is all about Oracle performance           Resources	
  
   management; systematic and quantitative
   firefighting and predictive analysis.
                                                    • 	
  Training	
  
•  Web site started in 1995 and the company was
   founded in 1998 by Craig Shallahamer.            • 	
  Unique	
  Blog	
  
•  OraPub has always been about disseminating       • 	
  Free	
  Tools	
  
   Oracle database centric technical information.

•  Consulting, training, books, papers, and         • 	
  Free	
  Papers	
  
   products are now being offered.
                                                    • 	
  Books	
  
•  We have been on-site in 24 countries and our
   resources have been received in probably         • 	
  Products	
  
   every country where there are DBAs.
                                                    • 	
  Consul8ng	
  
                                                               SQL	
  Elapsed	
  Time	
  Analysis	
  
Short resume...kind of...
•  Studies economics, mathematics, and computer science at
   university in California, US.
•  Started working with Oracle technology in 1989 as a Forms 2.3
   developer on Oracle version 5.
•  Soon after started performance firefighting...daily!
•  Co-found both Oracle’s Core Technology and System
   Performance Groups.
•  Left Oracle to start OraPub, Inc. in 1998.
•  Authored 24 technical papers and worked in 24 countries.
•  Authors and teaches his classes Oracle Performance
   Firefighting, Adv Oracle Performance Analysis, and Oracle
   Forecasting & Predictive Analysis.
•  Authored the books, Forecasting Oracle Performance and
   Oracle Performance Firefighting.
•  Oracle ACE Director.
•  Frequent blog contributor: A Wider View

                                                                   SQL	
  Elapsed	
  Time	
  Analysis	
  
My two books...




      OraPub	
  discount	
  code:	
  IS11	
  




                                                SQL	
  Elapsed	
  Time	
  Analysis	
  
One presentation with two parts.


•  “The average” can be misleading.

•  Modeling E time leads to insights.




                              SQL	
  Elapsed	
  Time	
  Analysis	
  
Working with limited information.
SQL ordered by Elapsed DB/Inst: LOOK/LOOK   Snaps: 80298-80310!
-> Resources reported for PL/SQL code includes the resources used by all SQL!
   statements called by the code.!
-> Total DB CPU (s):          22,800!
-> Captured SQL accounts for 109.8% of Total DB CPU!
-> SQL reported below exceeded 1.0% of Total DB CPU!
!
    CPU                  CPU per             Elapsd                     Old!
  Time (s)   Executions Exec (s) %Total     Time (s) Physical Reads Hash Value!
---------- ------------ ---------- ------ ---------- --------------- ----------!
    474.59       38,479       0.01    19.9 479909.89     923,822,548 4166296332!
BEGIN pkg_com_unite.st_execute_commune( i_daemon_id => :daemon_id, !
i_reload_subult_true_false => :reload_subult_true_false, !
i_dump_caches => :dump_caches, i_add_seq2_id => :add_seq2_id, !
i_dump_seq2_id => :dump_seq2_id, i_remove_seq2_id => :remove_seq2_id, !
i_multi_seq2_chg_true_false => :multi_seq2!




        Total	
  Elapsed	
  Time	
  :	
  479,909.89	
  seconds	
  
        Total	
  ExecuFons	
  	
  	
  	
  	
  	
  :	
  38,479	
  exec	
  

                                                                   SQL	
  Elapsed	
  Time	
  Analysis	
  
So the average E time is...
E = 479909.89 secs / 38,479 exec!
  = 12.47 sec/exec!




                           source:	
  Init	
  Hist	
  Work	
  2.nb	
  
                            SQL	
  Elapsed	
  Time	
  Analysis	
  
It’s more likely to be like this...




                             More?	
  “log	
  normal”	
  
                                SQL	
  Elapsed	
  Time	
  Analysis	
  
Even more likely...




                      SQL	
  Elapsed	
  Time	
  Analysis	
  
What can we do?

 We don’t want to mislead others.

  We need to truly understand the
situation if we are making decisions
     based on this information.

                                SQL	
  Elapsed	
  Time	
  Analysis	
  
We have a variety of collection options.
 •    SQL Trace. Valid option.
       –  Must have ability to parse the trace files producing E times.
       –  Can trace on sql_id.
       –  Must be the production system.
 •    Instrument SQL. Valid option.
       –  May not be practical or possible.
 •    Stopwatch. Risky.
       –  Limited scope and very few samples.
       –  OK for a specific user situation.
 •    Benchmark or Isolated Testing. Very risky.
       –  If you want real results, you need a real situation (HW, data, arrivals, concurrency).
 •    OraPub E Time Collector. Valid, but grabs a core.
       –  Free tool. OraPub search: “sql elapsed time”
       –  Gathers at sql_id and plan_hash_value level.
       –  Grabs and holds a CPU core, ouch!
 •    OraPub E Sampler. Valid but not free.
       –    Un-noticeable impact with same results as tracing or instrumentation!
       –    Gathers at sql_id level and samples stored in Oracle table.
       –    Licensed like a box of candy.
       –    Beta version available for Insync attendees....free!
                                                                                 More?	
  “SQL	
  sampler”	
  
                                                                                      SQL	
  Elapsed	
  Time	
  Analysis	
  
How good is sampled data?

        This	
  is	
  smoothed	
  histogram	
  of	
  elapsed	
  Fmes	
  for	
  a	
  
        specific	
  sql_id	
  (query)	
  collected	
  using	
  SQL	
  
        Trace,	
  instrumentaFon,	
  and	
  OP	
  Elapsed	
  Fme	
  
        Sampler	
  (normal).	
  Over	
  a	
  5	
  minute	
  period,	
  around	
  
        80	
  samples	
  where	
  gathered	
  from	
  each	
  collecFon	
  
        method.	
  
        	
  	
  


                    All	
  three	
  collecFons	
  methods	
  
                    produce	
  the	
  same	
  results!	
  



                                                                    More?	
  True	
  SQL	
  Elapsed	
  

                                                                 SQL	
  Elapsed	
  Time	
  Analysis	
  
Let’s take a look at some

     real data
          from

 real systems.
                      SQL	
  Elapsed	
  Time	
  Analysis	
  
#1: Showing all samples.


            Samples :        230!
            Mean     :     57168!
            Median   :     60000!
            Max      :    793996!
            Collector: OP E Time!




                                     source:	
  Aber3129	
  

                           SQL	
  Elapsed	
  Time	
  Analysis	
  
#1: Showing most samples.

              Samples :        230!
              Mean     :     57168!
              Median   :     60000!
              Max      :    793996!
              Collector: OP E Time!
              !




                                    source:	
  Aber3129	
  

                          SQL	
  Elapsed	
  Time	
  Analysis	
  
#2: Showing most samples.


             Samples :        368!
             Mean     :       158!
             Median   :        23!
             Max      :      2840!
             Collector: OP E Time!




                                    source:	
  Garret1jqj	
  

                          SQL	
  Elapsed	
  Time	
  Analysis	
  
#3: Showing all samples.


             Samples :        506!
             Mean     :        48!
             Median   :        26!
             Max      :       476!
             Collector: OP E Time!




                                    source:	
  Garret8qt	
  

                          SQL	
  Elapsed	
  Time	
  Analysis	
  
#4: Showing all samples.


           Samples :     179!
           Mean     :     38.72 ms!
           Median   :     38.04 ms!
           Max      :     58.40 ms!
           Collector: OP E Sampler!




                                   source:	
  Garret	
  0u2t	
  

                          SQL	
  Elapsed	
  Time	
  Analysis	
  
Experimental Examples.




                    source:	
  E	
  Analysis	
  1a	
  (final).nb	
  

                          SQL	
  Elapsed	
  Time	
  Analysis	
  
Conclusions about average E.
•  Average elapsed time for a specific SQL
   statement can be very misleading.
•  Elapsed times are not normally distributed.
•  The average elapsed time is not the typical
   elapsed time.
•  The modes are the typical elapsed times.
•  If the mode is not available, then the median
   can be used, in some cases.
•  If you need to communicate typical elapsed
   times, you need to gather real data.
                                        More?	
  “SQL	
  elapsed”	
  
                                             SQL	
  Elapsed	
  Time	
  Analysis	
  
Modeling elapsed time

E = units of work x time per unit

E (time/exec) = WL(work/exec) x RT(time/work)




                                      SQL	
  Elapsed	
  Time	
  Analysis	
  
Example of elapsed time.

   Supposed	
  a	
  query	
  must	
  access	
  100,000	
  logical	
  IOs	
  
   and	
  each	
  LIO	
  takes	
  0.020ms.	
  Therefore,	
  the	
  
   elapsed	
  Fme	
  will	
  be	
  2,000ms	
  or	
  2.0	
  seconds.	
  

E (ms/exec) = units of work (LIO/exec) X time per work (ms/LIO)!
!
2000 ms/exec = 100,000 LIO/exec X 0.020 ms/LIO !




                                                               SQL	
  Elapsed	
  Time	
  Analysis	
  
When we tune, WL is reduced.
•  SQL tuning fundamentally reduces the
   work required to execute a statement.
•  Since less work is required then generally,
   the elapsed time will decrease!
•  If your tuning prowess reduces the work
   from 100,000 PIOs to 50,000 PIOs then
   you can expect the elapsed time to
   decrease by 50%.
•  But does this really occur in reality? hum...

                                         SQL	
  Elapsed	
  Time	
  Analysis	
  
Experimental results!
                                                                 Median	
  
           Stmt	
                     Median	
  
Tuned	
               Stmt	
  LIO	
                              Elapsed	
  
          Logical	
                   Elapsed	
                                  Samples	
  
 SQL	
                 Change	
                                  Time	
  (s)	
  
            IO	
                      Time	
  (s)	
  
                                                                 Change	
  
     No	
      355289	
             -­‐	
        14.22	
               -­‐	
                                 243	
  
     Yes	
     161495	
   -­‐54.55%	
             5.88	
         -­‐58.67%	
                                 339	
  

•    CollecFon	
  interval	
  was	
  2	
  hours.	
  
•    OraPub’s	
  Elapsed	
  Time	
  Sampler	
  was	
  used	
  to	
  collect	
  elapsed	
  Fmes.	
  
•    LIO	
  numbers	
  gathered	
  from	
  v$sysstat.	
  
•    Time	
  based	
  on	
  Fmestamp	
  data	
  type.	
  
                                                                                 source:	
  E	
  Analysis	
  1a.xlsx,	
  256	
  latches	
  

                                                                                                 SQL	
  Elapsed	
  Time	
  Analysis	
  
Ways to reduce UOW process time.
 •  There are many ways to reduce the time it
    takes to process a single unit of work.
 •  There are direct methods and indirect
    methods.
 •  Indirect: Because processes share and
    compete for resources, when the big issue is
    resolved, many other issues become less
    intense.
 •  Direct: Tuning Oracle directly reduces the
    time required to process a piece of work.
    Hum...

                                          SQL	
  Elapsed	
  Time	
  Analysis	
  
Experimental results!
                                                 SQL	
  Stmt	
  
            Instance	
              Instance	
  
  CBC	
                                           Median	
  
               RT	
      Change	
      WL	
                       Change	
   Samples	
  
Latches	
                                         Elapsed	
  
            (ms/lio)	
              (lio/ms)	
  
                                                  Time	
  (s)	
  
      256	
       0.03623	
             -­‐	
         120	
          14.224	
                  -­‐	
                      243	
  

32768	
   0.00856	
   -­‐76.36%	
                     227	
           2.968	
        -­‐79.13%	
                          399	
  



 •      CollecFon	
  interval	
  was	
  2	
  hours.	
  
 •      OraPub’s	
  Elapsed	
  Time	
  Sampler	
  was	
  used	
  to	
  collect	
  elapsed	
  Fmes.	
  
 •      RT	
  components	
  gathered	
  from	
  v$sysstat,	
  v$sys_Fme_model,	
  and	
  v$system_event.	
  
 •      Time	
  based	
  on	
  Fmestamp	
  data	
  type.	
  

                                                                                       source:	
  E	
  Analysis	
  1a.xlsx,	
  not	
  tuned	
  

                                                                                                         SQL	
  Elapsed	
  Time	
  Analysis	
  
This graph shows the work process time.




                                   +96%	
  WL	
  Change	
  


      -­‐76%	
  RT	
  Change	
  




                                                              source:	
  More	
  Latches	
  RT	
  Compare...xlsx	
  

                                                                                SQL	
  Elapsed	
  Time	
  Analysis	
  
All situations elapsed times.




                          SQL	
  Elapsed	
  Time	
  Analysis	
  
The point? #1 – Average is misleading.
•  It is easy to calculate the average elapsed
   time...even from Statspack.
•  But saying, “The average elapsed time is X.”
   will most likely mislead everyone.

•  The median or mode(s) is a much better
   representation of the typical elapsed times.
•  If you need to communicate typical elapsed
   times, you need to gather real data.

                                         SQL	
  Elapsed	
  Time	
  Analysis	
  
The point? #2 – Modeling SQL E.
•  Two basic ways to reduce elapsed times:
  –  Reduce work to be done.
  –  Reduce time to process each piece of work.

•  SQL statement elapsed time can be
   simply modeled.
•  SQL statement elapsed time can be
   anticipated.

                                          SQL	
  Elapsed	
  Time	
  Analysis	
  
Want to dig deeper?
•  Craig’s Blog – A W i d e r V i e w
•  Training from OraPub
                                               Melbourne	
  
   –  Oracle Performance Firefighting (I)
                                               &	
  Perth	
  in	
  
   –  Adv Oracle Performance Analysis (II)      Q2	
  2012    	
  
•  Books
   –  Oracle Performance Firefighting (C. Shallahamer)
      •  Chapter 9 is FREE to download




                                                      SQL	
  Elapsed	
  Time	
  Analysis	
  
Thank
 You!
    SQL	
  Elapsed	
  Time	
  Analysis	
  

More Related Content

PDF
Database & Technology 1 _ Craig Shallahamer _ Unit of work time based perform...
PPTX
Dev nexus 2017
PPTX
Devnexus 2018
PDF
Performance Test Driven Development with Oracle Coherence
PPTX
Apache Storm
PPTX
Past, Present, and Future of Apache Storm
PDF
Effective testing for spark programs Strata NY 2015
PPTX
Smart Data Conference: DL4J and DataVec
Database & Technology 1 _ Craig Shallahamer _ Unit of work time based perform...
Dev nexus 2017
Devnexus 2018
Performance Test Driven Development with Oracle Coherence
Apache Storm
Past, Present, and Future of Apache Storm
Effective testing for spark programs Strata NY 2015
Smart Data Conference: DL4J and DataVec

What's hot (6)

PPTX
Python Raster Function - Esri Developer Conference - 2015
PDF
Adding Transparency and Automation into the Galaxy Tool Installation Process
PDF
All Your IOPS Are Belong To Us - A Pinteresting Case Study in MySQL Performan...
PDF
Storm Real Time Computation
PPTX
Prometheus (Monitorama 2016)
PDF
Search-time Parallelism: Presented by Shikhar Bhushan, Etsy
Python Raster Function - Esri Developer Conference - 2015
Adding Transparency and Automation into the Galaxy Tool Installation Process
All Your IOPS Are Belong To Us - A Pinteresting Case Study in MySQL Performan...
Storm Real Time Computation
Prometheus (Monitorama 2016)
Search-time Parallelism: Presented by Shikhar Bhushan, Etsy
Ad

Similar to Database & Technology 1 _ Craig Shallahamer _ SQL Elapsed Time Analhysis.pdf (20)

PDF
Oracle trace data collection errors: the story about oceans, islands, and rivers
PDF
Calculating SQL Runtime Using Raw ASH Data.pdf
PDF
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
PDF
Average Active Sessions - OaktableWorld 2013
PDF
Performance tuning a quick intoduction
PDF
Average Active Sessions RMOUG2007
PDF
Oracle database performance diagnostics - before your begin
PDF
kharchenko-outliers-140211120833-phpapp01.pdf
DOC
Analyzing awr report
PPTX
Oracle database performance tuning
PPT
Oracle Tracing
PDF
pdf-download-db-time-based-oracle-performance-tuning-theory-and.pdf
PDF
How to find and fix your Oracle application performance problem
PDF
Ebs dba con4696_pdf_4696_0001
PPT
Oracle 10g Performance: chapter 00 statspack
PDF
Ebs performance tune2_con9030_pdf_9030_0002
PDF
Presentation maximizing database performance performance tuning with db time
PDF
Oracle database performance are database users telling me the truth
PDF
553: Oracle Database Performance: Are Database Users Telling Me The Truth?
PDF
Ebs performance tune_con9030_pdf_9030_0001
Oracle trace data collection errors: the story about oceans, islands, and rivers
Calculating SQL Runtime Using Raw ASH Data.pdf
DB Time, Average Active Sessions, and ASH Math - Oracle performance fundamentals
Average Active Sessions - OaktableWorld 2013
Performance tuning a quick intoduction
Average Active Sessions RMOUG2007
Oracle database performance diagnostics - before your begin
kharchenko-outliers-140211120833-phpapp01.pdf
Analyzing awr report
Oracle database performance tuning
Oracle Tracing
pdf-download-db-time-based-oracle-performance-tuning-theory-and.pdf
How to find and fix your Oracle application performance problem
Ebs dba con4696_pdf_4696_0001
Oracle 10g Performance: chapter 00 statspack
Ebs performance tune2_con9030_pdf_9030_0002
Presentation maximizing database performance performance tuning with db time
Oracle database performance are database users telling me the truth
553: Oracle Database Performance: Are Database Users Telling Me The Truth?
Ebs performance tune_con9030_pdf_9030_0001
Ad

More from InSync2011 (20)

PDF
Developer & Fusion Middleware 2 _ Scott Robertson _ SOA, Portals and Enterpri...
PDF
New & Emerging _ KrisDowney _ Simplifying the Change Process.pdf
PDF
Oracle Systems _ Kevin McIsaac _The IT landscape has changed.pdf
PDF
Reporting _ Scott Tunbridge _ Op Mgmt to Perf Excel.pdf
PDF
Developer and Fusion Middleware 2 _ Scott Robertson _ SOA, portals and entepr...
PDF
Primavera _ Loretta Bayliss _ Implementing EPPM in rapidly changing and compe...
PDF
Database & Technology 1 _ Martin Power _ Delivering Oracles hight availabilit...
PDF
Database & Technology 1 _ Marcelle Kratchvil _ Why you should be storing unst...
PDF
Database & Technology 1 _ Milina Ristic _ Why use oracle data guard.pdf
PDF
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
PDF
Database & Technology 1 _ Clancy Bufton _ Flashback Query - oracle total reca...
PDF
Databse & Technology 2 _ Francisco Munoz Alvarez _ Oracle Security Tips - Som...
PDF
Databse & Technology 2 _ Francisco Munoz alvarez _ 11g new functionalities fo...
PDF
Databse & Technology 2 | Connor McDonald | Managing Optimiser Statistics - A ...
PDF
Databse & Technology 2 _ Shan Nawaz _ Oracle 11g Top 10 features - not your u...
PDF
Databse & Technology 2 _ Paul Guerin _ The biggest looser database - a boot c...
PDF
Developer and Fusion Middleware 1 _ Kevin Powe _ Log files - a wealth of fore...
PDF
Developer and Fusion Middleware 2 _ Aaron Blishen _ Event driven SOA Integrat...
PDF
Developer and Fusion Middleware 2 _Greg Kirkendall _ How Australia Post teach...
PDF
Developer and Fusion Middleware 1 _ Paul Ricketts _ Paper Process Automation ...
Developer & Fusion Middleware 2 _ Scott Robertson _ SOA, Portals and Enterpri...
New & Emerging _ KrisDowney _ Simplifying the Change Process.pdf
Oracle Systems _ Kevin McIsaac _The IT landscape has changed.pdf
Reporting _ Scott Tunbridge _ Op Mgmt to Perf Excel.pdf
Developer and Fusion Middleware 2 _ Scott Robertson _ SOA, portals and entepr...
Primavera _ Loretta Bayliss _ Implementing EPPM in rapidly changing and compe...
Database & Technology 1 _ Martin Power _ Delivering Oracles hight availabilit...
Database & Technology 1 _ Marcelle Kratchvil _ Why you should be storing unst...
Database & Technology 1 _ Milina Ristic _ Why use oracle data guard.pdf
Database & Technology 1 _ Tom Kyte _ SQL Techniques.pdf
Database & Technology 1 _ Clancy Bufton _ Flashback Query - oracle total reca...
Databse & Technology 2 _ Francisco Munoz Alvarez _ Oracle Security Tips - Som...
Databse & Technology 2 _ Francisco Munoz alvarez _ 11g new functionalities fo...
Databse & Technology 2 | Connor McDonald | Managing Optimiser Statistics - A ...
Databse & Technology 2 _ Shan Nawaz _ Oracle 11g Top 10 features - not your u...
Databse & Technology 2 _ Paul Guerin _ The biggest looser database - a boot c...
Developer and Fusion Middleware 1 _ Kevin Powe _ Log files - a wealth of fore...
Developer and Fusion Middleware 2 _ Aaron Blishen _ Event driven SOA Integrat...
Developer and Fusion Middleware 2 _Greg Kirkendall _ How Australia Post teach...
Developer and Fusion Middleware 1 _ Paul Ricketts _ Paper Process Automation ...

Recently uploaded (20)

PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
Architecture types and enterprise applications.pdf
PPTX
Benefits of Physical activity for teenagers.pptx
PDF
August Patch Tuesday
PPTX
Web Crawler for Trend Tracking Gen Z Insights.pptx
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
PDF
Getting started with AI Agents and Multi-Agent Systems
PDF
Five Habits of High-Impact Board Members
PPTX
Chapter 5: Probability Theory and Statistics
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PPTX
Modernising the Digital Integration Hub
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
The various Industrial Revolutions .pptx
PPT
Geologic Time for studying geology for geologist
PDF
Developing a website for English-speaking practice to English as a foreign la...
PPTX
observCloud-Native Containerability and monitoring.pptx
Hindi spoken digit analysis for native and non-native speakers
Architecture types and enterprise applications.pdf
Benefits of Physical activity for teenagers.pptx
August Patch Tuesday
Web Crawler for Trend Tracking Gen Z Insights.pptx
A comparative study of natural language inference in Swahili using monolingua...
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
Getting started with AI Agents and Multi-Agent Systems
Five Habits of High-Impact Board Members
Chapter 5: Probability Theory and Statistics
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Modernising the Digital Integration Hub
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
A Late Bloomer's Guide to GenAI: Ethics, Bias, and Effective Prompting - Boha...
WOOl fibre morphology and structure.pdf for textiles
Group 1 Presentation -Planning and Decision Making .pptx
The various Industrial Revolutions .pptx
Geologic Time for studying geology for geologist
Developing a website for English-speaking practice to English as a foreign la...
observCloud-Native Containerability and monitoring.pptx

Database & Technology 1 _ Craig Shallahamer _ SQL Elapsed Time Analhysis.pdf

  • 1. SQL Elapsed Time Analysis Craig A. Shallahamer Founder - OraPub, Inc. craig@orapub.com SQL  Elapsed  Time  Analysis  
  • 2. OraPub is about Oracle performance. •  OraPub is all about Oracle performance Resources   management; systematic and quantitative firefighting and predictive analysis. •   Training   •  Web site started in 1995 and the company was founded in 1998 by Craig Shallahamer. •   Unique  Blog   •  OraPub has always been about disseminating •   Free  Tools   Oracle database centric technical information. •  Consulting, training, books, papers, and •   Free  Papers   products are now being offered. •   Books   •  We have been on-site in 24 countries and our resources have been received in probably •   Products   every country where there are DBAs. •   Consul8ng   SQL  Elapsed  Time  Analysis  
  • 3. Short resume...kind of... •  Studies economics, mathematics, and computer science at university in California, US. •  Started working with Oracle technology in 1989 as a Forms 2.3 developer on Oracle version 5. •  Soon after started performance firefighting...daily! •  Co-found both Oracle’s Core Technology and System Performance Groups. •  Left Oracle to start OraPub, Inc. in 1998. •  Authored 24 technical papers and worked in 24 countries. •  Authors and teaches his classes Oracle Performance Firefighting, Adv Oracle Performance Analysis, and Oracle Forecasting & Predictive Analysis. •  Authored the books, Forecasting Oracle Performance and Oracle Performance Firefighting. •  Oracle ACE Director. •  Frequent blog contributor: A Wider View SQL  Elapsed  Time  Analysis  
  • 4. My two books... OraPub  discount  code:  IS11   SQL  Elapsed  Time  Analysis  
  • 5. One presentation with two parts. •  “The average” can be misleading. •  Modeling E time leads to insights. SQL  Elapsed  Time  Analysis  
  • 6. Working with limited information. SQL ordered by Elapsed DB/Inst: LOOK/LOOK Snaps: 80298-80310! -> Resources reported for PL/SQL code includes the resources used by all SQL! statements called by the code.! -> Total DB CPU (s): 22,800! -> Captured SQL accounts for 109.8% of Total DB CPU! -> SQL reported below exceeded 1.0% of Total DB CPU! ! CPU CPU per Elapsd Old! Time (s) Executions Exec (s) %Total Time (s) Physical Reads Hash Value! ---------- ------------ ---------- ------ ---------- --------------- ----------! 474.59 38,479 0.01 19.9 479909.89 923,822,548 4166296332! BEGIN pkg_com_unite.st_execute_commune( i_daemon_id => :daemon_id, ! i_reload_subult_true_false => :reload_subult_true_false, ! i_dump_caches => :dump_caches, i_add_seq2_id => :add_seq2_id, ! i_dump_seq2_id => :dump_seq2_id, i_remove_seq2_id => :remove_seq2_id, ! i_multi_seq2_chg_true_false => :multi_seq2! Total  Elapsed  Time  :  479,909.89  seconds   Total  ExecuFons            :  38,479  exec   SQL  Elapsed  Time  Analysis  
  • 7. So the average E time is... E = 479909.89 secs / 38,479 exec! = 12.47 sec/exec! source:  Init  Hist  Work  2.nb   SQL  Elapsed  Time  Analysis  
  • 8. It’s more likely to be like this... More?  “log  normal”   SQL  Elapsed  Time  Analysis  
  • 9. Even more likely... SQL  Elapsed  Time  Analysis  
  • 10. What can we do? We don’t want to mislead others. We need to truly understand the situation if we are making decisions based on this information. SQL  Elapsed  Time  Analysis  
  • 11. We have a variety of collection options. •  SQL Trace. Valid option. –  Must have ability to parse the trace files producing E times. –  Can trace on sql_id. –  Must be the production system. •  Instrument SQL. Valid option. –  May not be practical or possible. •  Stopwatch. Risky. –  Limited scope and very few samples. –  OK for a specific user situation. •  Benchmark or Isolated Testing. Very risky. –  If you want real results, you need a real situation (HW, data, arrivals, concurrency). •  OraPub E Time Collector. Valid, but grabs a core. –  Free tool. OraPub search: “sql elapsed time” –  Gathers at sql_id and plan_hash_value level. –  Grabs and holds a CPU core, ouch! •  OraPub E Sampler. Valid but not free. –  Un-noticeable impact with same results as tracing or instrumentation! –  Gathers at sql_id level and samples stored in Oracle table. –  Licensed like a box of candy. –  Beta version available for Insync attendees....free! More?  “SQL  sampler”   SQL  Elapsed  Time  Analysis  
  • 12. How good is sampled data? This  is  smoothed  histogram  of  elapsed  Fmes  for  a   specific  sql_id  (query)  collected  using  SQL   Trace,  instrumentaFon,  and  OP  Elapsed  Fme   Sampler  (normal).  Over  a  5  minute  period,  around   80  samples  where  gathered  from  each  collecFon   method.       All  three  collecFons  methods   produce  the  same  results!   More?  True  SQL  Elapsed   SQL  Elapsed  Time  Analysis  
  • 13. Let’s take a look at some real data from real systems. SQL  Elapsed  Time  Analysis  
  • 14. #1: Showing all samples. Samples : 230! Mean : 57168! Median : 60000! Max : 793996! Collector: OP E Time! source:  Aber3129   SQL  Elapsed  Time  Analysis  
  • 15. #1: Showing most samples. Samples : 230! Mean : 57168! Median : 60000! Max : 793996! Collector: OP E Time! ! source:  Aber3129   SQL  Elapsed  Time  Analysis  
  • 16. #2: Showing most samples. Samples : 368! Mean : 158! Median : 23! Max : 2840! Collector: OP E Time! source:  Garret1jqj   SQL  Elapsed  Time  Analysis  
  • 17. #3: Showing all samples. Samples : 506! Mean : 48! Median : 26! Max : 476! Collector: OP E Time! source:  Garret8qt   SQL  Elapsed  Time  Analysis  
  • 18. #4: Showing all samples. Samples : 179! Mean : 38.72 ms! Median : 38.04 ms! Max : 58.40 ms! Collector: OP E Sampler! source:  Garret  0u2t   SQL  Elapsed  Time  Analysis  
  • 19. Experimental Examples. source:  E  Analysis  1a  (final).nb   SQL  Elapsed  Time  Analysis  
  • 20. Conclusions about average E. •  Average elapsed time for a specific SQL statement can be very misleading. •  Elapsed times are not normally distributed. •  The average elapsed time is not the typical elapsed time. •  The modes are the typical elapsed times. •  If the mode is not available, then the median can be used, in some cases. •  If you need to communicate typical elapsed times, you need to gather real data. More?  “SQL  elapsed”   SQL  Elapsed  Time  Analysis  
  • 21. Modeling elapsed time E = units of work x time per unit E (time/exec) = WL(work/exec) x RT(time/work) SQL  Elapsed  Time  Analysis  
  • 22. Example of elapsed time. Supposed  a  query  must  access  100,000  logical  IOs   and  each  LIO  takes  0.020ms.  Therefore,  the   elapsed  Fme  will  be  2,000ms  or  2.0  seconds.   E (ms/exec) = units of work (LIO/exec) X time per work (ms/LIO)! ! 2000 ms/exec = 100,000 LIO/exec X 0.020 ms/LIO ! SQL  Elapsed  Time  Analysis  
  • 23. When we tune, WL is reduced. •  SQL tuning fundamentally reduces the work required to execute a statement. •  Since less work is required then generally, the elapsed time will decrease! •  If your tuning prowess reduces the work from 100,000 PIOs to 50,000 PIOs then you can expect the elapsed time to decrease by 50%. •  But does this really occur in reality? hum... SQL  Elapsed  Time  Analysis  
  • 24. Experimental results! Median   Stmt   Median   Tuned   Stmt  LIO   Elapsed   Logical   Elapsed   Samples   SQL   Change   Time  (s)   IO   Time  (s)   Change   No   355289   -­‐   14.22   -­‐   243   Yes   161495   -­‐54.55%   5.88   -­‐58.67%   339   •  CollecFon  interval  was  2  hours.   •  OraPub’s  Elapsed  Time  Sampler  was  used  to  collect  elapsed  Fmes.   •  LIO  numbers  gathered  from  v$sysstat.   •  Time  based  on  Fmestamp  data  type.   source:  E  Analysis  1a.xlsx,  256  latches   SQL  Elapsed  Time  Analysis  
  • 25. Ways to reduce UOW process time. •  There are many ways to reduce the time it takes to process a single unit of work. •  There are direct methods and indirect methods. •  Indirect: Because processes share and compete for resources, when the big issue is resolved, many other issues become less intense. •  Direct: Tuning Oracle directly reduces the time required to process a piece of work. Hum... SQL  Elapsed  Time  Analysis  
  • 26. Experimental results! SQL  Stmt   Instance   Instance   CBC   Median   RT   Change   WL   Change   Samples   Latches   Elapsed   (ms/lio)   (lio/ms)   Time  (s)   256   0.03623   -­‐   120   14.224   -­‐   243   32768   0.00856   -­‐76.36%   227   2.968   -­‐79.13%   399   •  CollecFon  interval  was  2  hours.   •  OraPub’s  Elapsed  Time  Sampler  was  used  to  collect  elapsed  Fmes.   •  RT  components  gathered  from  v$sysstat,  v$sys_Fme_model,  and  v$system_event.   •  Time  based  on  Fmestamp  data  type.   source:  E  Analysis  1a.xlsx,  not  tuned   SQL  Elapsed  Time  Analysis  
  • 27. This graph shows the work process time. +96%  WL  Change   -­‐76%  RT  Change   source:  More  Latches  RT  Compare...xlsx   SQL  Elapsed  Time  Analysis  
  • 28. All situations elapsed times. SQL  Elapsed  Time  Analysis  
  • 29. The point? #1 – Average is misleading. •  It is easy to calculate the average elapsed time...even from Statspack. •  But saying, “The average elapsed time is X.” will most likely mislead everyone. •  The median or mode(s) is a much better representation of the typical elapsed times. •  If you need to communicate typical elapsed times, you need to gather real data. SQL  Elapsed  Time  Analysis  
  • 30. The point? #2 – Modeling SQL E. •  Two basic ways to reduce elapsed times: –  Reduce work to be done. –  Reduce time to process each piece of work. •  SQL statement elapsed time can be simply modeled. •  SQL statement elapsed time can be anticipated. SQL  Elapsed  Time  Analysis  
  • 31. Want to dig deeper? •  Craig’s Blog – A W i d e r V i e w •  Training from OraPub Melbourne   –  Oracle Performance Firefighting (I) &  Perth  in   –  Adv Oracle Performance Analysis (II) Q2  2012   •  Books –  Oracle Performance Firefighting (C. Shallahamer) •  Chapter 9 is FREE to download SQL  Elapsed  Time  Analysis  
  • 32. Thank You! SQL  Elapsed  Time  Analysis