Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 

Find Sub-optimal Oracle SQL

Oracle Tips by Burleson Consulting
July 15, 2003
Don Burleson

Before you can identify problem SQL in your database, you have to ask the question of what is bad SQL?  What criteria do you use when you begin the hunt for problem SQL in your critical systems? 

Understand that even the seasoned experts disagree on what constitutes efficient and inefficient SQL; so there?s no way to sufficiently answer this question to every Oracle professional?s satisfaction.  What follows are some general criteria you can use when evaluating the output from various database monitors or personal diagnostic scripts:   

  • Overall Response (Elapsed) Time ? This is how much time the query took to parse, execute, and fetch the data needed to satisfy the query.  It should not include the network time needed to make the round trip from the requesting client workstation to the database server.

  • CPU Time ? This is how much CPU time the query took to parse, execute, and fetch the data needed to satisfy the query.

  • Physical I/O ? Often used as the major statistic in terms of identifying good vs. bad SQL, this is a measure of how many disk reads the query caused to satisfy the user?s request.  While you certainly want to control disk I/O where possible, it?s important that you not focus solely on physical I/O as the single benchmark of inefficient SQL.  Make no mistake, disk access is slower than memory access and also consumes processing time making the physical to logical transition, but you need to look at the entire I/O picture of a SQL statement, which includes looking at a statements? logical I/O as well. 

  • Logical I/O ? This is a measure of how many memory reads the query took to satisfy the user?s request.  The goal of tuning I/O for a query should be to examine both logical and physical I/O, and use appropriate mechanisms to keep both to a minimum.

  • Repetition ? This is a measure of how often the query has been executed.  A problem in this area isn?t as easy to spot as the others unless you know your application well.  A query that takes a fraction of a second to execute may still be causing a headache on your system if it?s executed erroneously (for example, a query that executes in a runaway PL/SQL loop) over and over again 

There are other criteria that you can examine, like sort activity or access plan statistics (that show items such as Cartesian joins  and the like), but more often than not, these measures are reflected in the criteria listed above.

Fortunately, Oracle records all the above measures, which makes tracking the SQL that?s been submitted against an Oracle database a lot easier.

The following script will find all current ?slow? SQL statements with a high execution time. 

You pass the minimum execution time as the exec_time argument:  

select
    sql_id,
    sql_exec_id,
    sql_exec_start,
    max(tm) tm,
    (sysdate-sql_exec_start) * 3600*24 ela_tm
from
    (select
       sql_id,
       sql_exec_id,
       sql_exec_start,
       ( ( Cast(sample_time AS DATE) ) -
             ( Cast(sql_exec_start AS DATE) ) ) * ( 3600 * 24 ) tm
     from
         v$active_session_history
     where
see code depot for full script       
order by
     sql_exec_start;

 



 

 

��  
 
 
 
 

 
 
 

 
 
Oracle performance tuning software 
 
oracle dba poster
Oracle Linux poster
 
 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright ? 1996 -  2014

All rights reserved by Burleson

Oracle ? is the registered trademark of Oracle Corporation.