Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explain Plan for Query in a Stored Procedure

Tags:

oracle

I have a stored procedure that consists of a single select query used to insert into another table based on some minor math that is done to the arguments in the procedure. Can I generate the plan used for this query by referencing the procedure somehow, or do I have to copy and paste the query and create bind variables for the input parameters?

like image 792
Mark Roddy Avatar asked Sep 23 '08 18:09

Mark Roddy


1 Answers

Use SQL Trace and TKPROF. For example, open SQL*Plus, and then issue the following code:-

alter session set tracefile_identifier = 'something-unique'
alter session set sql_trace = true;
alter session set events '10046 trace name context forever, level 8';

select 'right-before-my-sp' from dual;
exec your_stored_procedure

alter session set sql_trace = false;

Once this has been done, go look in your database's UDUMP directory for a TRC file with "something-unique" in the filename. Format this TRC file with TKPROF, and then open the formatted file and search for the string "right-before-my-sp". The SQL command issued by your stored procedure should be shortly after this section, and immediately under that SQL statement will be the plan for the SQL statement.

Edit: For the purposes of full disclosure, I should thank all those who gave me answers on this thread last week that helped me learn how to do this.

like image 181
3 revs Avatar answered Oct 18 '22 04:10

3 revs