Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I obtain the execution plan of a SQL statement?

Status
Not open for further replies.

011179

Programmer
Mar 14, 2002
11
0
0
HK
Dear all,

I would like to obtain the execution plan of SQL statement in Oracle! How can I do that?!

Thanks!
 
hi,

For every DML statement that you would execute at SQL promp you can obtain the execution plan for it, provided you have the plan_table created in ur schema.
If you don't have this plan_table created, then u hve to run the script file called utlxplan.sql (The name of the file may be a little different like utilxplan or utl_xplan or something like that - that you will have to check)

After running this script file it should create the plan_table.

Then you give
SET AUTOTRACE ON EXPLAIN PLAN
or
SET AUTOTRACE ON EXPLAIN STATISTICS

In the first case it will only show you plan. In the second case it will also show the plan and it will also show the statistics.

hope this helps you,

abhivyakti
 
one more question:

do you know how to set:
AUTOTRACE ON EXPLAIN STATISTICS
during startup!?
 
hi

at sql prompt type set autotrace on explain plan
SQL> set autotrace on explain plan<enter>

this should work

 
Just in case you can't find it, the script is utlxplan.sql and it's located in $ORACLE_HOME/rdbms/admin
Good luck
 
Guys -
PLAN_TABLE output shows the execution plan that Oracle intend to use to execute the query. There is no gaurentee that this execution plan is THE plan that is used during execution. This is because the execution environment might be different for different users executing the same query. For instance the execution environment depends on &quot;SORT_AREA_SIZE&quot; , &quot;HASH_AREA_SIZE&quot; etc. Hence looking at the plan_table is a rough way of estimating what Oracle might use to execute the query.

However there is a new feature introduced in 9i where the actual plan used by Oracle can be viewed. This is by means of querying V$SQL_PLAN. Refer Oracle manual for 9i to know more about it.

Regards
Chaan
 
Just add
SET AUTOTRACE ON
to the end of glogin.sql script, located in your PLUS80 directory

But do you really need it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top