Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get runtime execution plan of a query

I have an application that executes some sql queries. How can I get execution plan for currently executing query from sqlplus or some other oracle client? I can amend oracle session that is used in application, if that is necessary.

I do not want to use explain plan and execute that query by hand, I need to get actual execution plan that is used for query.

like image 425
michael nesterenko Avatar asked Jan 23 '13 12:01

michael nesterenko


People also ask

How do I get the execution plan of a query in SQL Developer?

The estimated SQL execution plan The estimated execution plan is generated by the Optimizer without executing the SQL query. You can generate the estimated execution plan from any SQL client using EXPLAIN PLAN FOR or you can use Oracle SQL Developer for this task.

How do I view a query execution plan in SQL Server?

On the SQL Server Management Studio toolbar, click Database Engine Query. You can also open an existing query and display the estimated execution plan by clicking the Open File toolbar button and locating the existing query. Enter the query for which you would like to display the actual execution plan.

How do you get Sql_id of a query in Oracle?

The SQL_ID of a statement can be found in an AWR or ASH report or by selecting it from the database data dictionary using the V$SQL view. If the SQL can be identified with a particular identifiable string or by some kind of unique comment such as: /* TARGET SQL */ then this will make it easier to locate.


1 Answers

You can run explain plain on historical queries from the SGA -examples

And listing B.

Example:

SELECT username, prev_sql_id
FROM v$session
WHERE username = 'RDEVALL'  -- example user

SQL ID returned

RDEVALL a1d4z5ruduzrd
RDEVALL avmbutuknvb6j
RDEVALL 75g0tqd9x743y
RDEVALL 5fnkh6c8mqqt3
RDEVALL 75g0tqd9x743y

Pick query ID and use here:

SELECT *
  FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR('a1d4z5ruduzrd')); -- replace with sql ID as needed
like image 79
OldProgrammer Avatar answered Sep 30 '22 14:09

OldProgrammer