How to measure the sql run time? [message #513299] |
Sun, 26 June 2011 04:41 |
snowball
Messages: 229 Registered: April 2006 Location: China
|
Senior Member |
|
|
Hi, guys
Is there any other ways to measure a sql run time more accurate and more efficient?
I meant using a spool and set timming on like this.
[oracle@milo ~]$ cat measure_sql.sql
spool result.txt;
set timing on;
select * from t3 where empno=7788;
set timing off;
spool off;
[oracle@milo ~]$ sqlplus scott/tiger @measure_sql.sql
SQL*Plus: Release 10.2.0.1.0 - Production on Mon Jun 27 01:36:32 2011
Copyright (c) 1982, 2005, Oracle. All rights reserved.
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- --------- ---------- ---------- ----------
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
16 rows selected.
Elapsed: 00:00:00.01
Thanks very much.
BR,
Milo
|
|
|
|
|
|
|
Re: How to measure the sql run time? [message #513304 is a reply to message #513303] |
Sun, 26 June 2011 08:12 |
|
Michel Cadot
Messages: 68675 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
It depends on what yu want, CPU time or elapsed time to execute?
Here have a resolution of 1 second, what do you expect when you have a time of 1 second, it can be 0 and 1.
If you want more details you want to activate SQL_TRACE, this is what I meant not SQL*Plus autotrace that, in addition, does not give execution time but estimated execution time from an exlain plan.
See How to set trace for others sessions, for your own session and at instance level from Pete Finnigan.
Regards
Michel
|
|
|
Re: How to measure the sql run time? [message #513316 is a reply to message #513303] |
Sun, 26 June 2011 14:33 |
John Watson
Messages: 8944 Registered: January 2010 Location: Global Village
|
Senior Member |
|
|
The dynamic performance view v$sqlstats can be helpful:
orcl> select count(*) from emp;
COUNT(*)
----------
14
orcl> select elapsed_time from v$sqlstats where sql_text='select count(*) from emp';
ELAPSED_TIME
------------
29855
elapsed_time is in microseconds, there are several other useful columns.
|
|
|
|
|
|
|
|
Re: How to measure the sql run time? [message #514308 is a reply to message #513358] |
Sun, 03 July 2011 16:11 |
|
LNossov
Messages: 318 Registered: July 2011 Location: Germany
|
Senior Member |
|
|
Hello,
I think, the method via sql tracing is a little bit laborious. It is a good way to measure sql's, which you cannot execute. But if you can, you can do the following:
alter session set statistics_level=all;
select * from t3 where empno=7788;
select plan_table_output from table ( sys.dbms_xplan.display_cursor( '','','ALLSTATS LAST'));
You will get the runtime statistics not only for entire sql but also for certain steps of execution plan.
Regards
Leonid
|
|
|