Oracle query execution time

后端 未结 4 556
暖寄归人
暖寄归人 2021-01-03 18:31

I would like to get the query execution time in Oracle. I don\'t want the time Oracle needs to print the results - just the execution time.

In MySQL it is easy to ge

相关标签:
4条回答
  • 2021-01-03 18:41

    One can issue the SQL*Plus command SET TIMING ON to get wall-clock times, but one can't take, for example, fetch time out of that trivially.

    The AUTOTRACE setting, when used as SET AUTOTRACE TRACEONLY will suppress output, but still perform all of the work to satisfy the query and send the results back to SQL*Plus, which will suppress it.

    Lastly, one can trace the SQL*Plus session, and manually calculate the time spent waiting on events which are client waits, such as "SQL*Net message to client", "SQL*Net message from client".

    0 讨论(0)
  • 2021-01-03 18:43

    Use:

    set serveroutput on
    variable n number
    exec :n := dbms_utility.get_time;
    select ......
    exec dbms_output.put_line( (dbms_utility.get_time-:n)/100) || ' seconds....' );
    

    Or possibly:

    SET TIMING ON;
    
    -- do stuff
    
    SET TIMING OFF;
    

    ...to get the hundredths of seconds that elapsed.

    In either case, time elapsed can be impacted by server load/etc.

    Reference:

    • ASKTOM - SET TIMING ON/OFF
    0 讨论(0)
  • 2021-01-03 19:01
    select LAST_LOAD_TIME, ELAPSED_TIME, MODULE, SQL_TEXT elapsed from v$sql
      order by LAST_LOAD_TIME desc
    

    More complicated example (don't forget to delete or to substitute PATTERN):

    select * from (
      select LAST_LOAD_TIME, to_char(ELAPSED_TIME/1000, '999,999,999.000') || ' ms' as TIME,
             MODULE, SQL_TEXT from SYS."V_\$SQL"
        where SQL_TEXT like '%PATTERN%'
        order by LAST_LOAD_TIME desc
      ) where ROWNUM <= 5;
    
    0 讨论(0)
  • 2021-01-03 19:02

    I'd recommend looking at consistent gets/logical reads as a better proxy for 'work' than run time. The run time can be skewed by what else is happening on the database server, how much stuff is in the cache etc.

    But if you REALLY want SQL executing time, the V$SQL view has both CPU_TIME and ELAPSED_TIME.

    0 讨论(0)
提交回复
热议问题