Systems Engineering and RDBMS

EXPLAIN PLAN, V$SQL_PLAN and DBMS_XPLAN

Posted by decipherinfosys on February 29, 2008

In some of our previous posts, we have talked about DBMS_XPLAN package in Oracle and have demonstrated it’s usage. One of the recent questions from our readers was: “What is the difference between using “EXPLAIN PLAN command” vs using the dictionary view: V$SQL_PLAN? And can you elaborate a bit on the different options available in dbms_xplan package along with some examples?

This blog post is to address those questions. The answer to the first question is pretty straight forward. EXPLAIN PLAN command is used to display the execution plan of a SQL statement without actually executing it. On the other hand, v$sql_plan dictionary view is used to show the execution plan of the SQL statement that has been compiled into a cursor in the cache. Besides this difference, another difference is that the EXPLAIN PLAN command does not take the bind variables into consideration whereas v$sql_plan displays the plan that takes the bind variables into account.

The answer to the second question is a little detailed and rather than going into each and every option, we will point you to the Oracle documentation in this regard:

http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28419/d_xplan.htm#sthref15004

However, we would like to point out a couple of things that we have seen that people typically miss out on. As you probably already know, dbms_xplan package has several functions that help to display the plan from: a) EXPLAIN PLAN command, b) v$sql_plan, c) AWR (Automatic Workload Repository), and d) STS (SQL Tuning Set). The functions to read up on in the documentation link above are:

a) display
b) display_cursor
c) display_sql_plan_baseline
d) display_awr
e) display_sqlset

One thing that we want to point out is regarding the format argument. This argument allows you to see a lot of details about the SQL command’s plan. There are three high level options that most of you must already be familiar with (if not, the link above is all that you need to read): Basic, Typical and All. The low level options are the ones that are often missed by people. Here is a description of those options:

1) Predicates, cost, bytes, note are some of the options that you might want to use and in order to specify that you wish to include them in the plan, you would need to use the + sign and in order to exclude them from the plan, you can use the – sign. Example:

select plan_table_output
from table(dbms_xplan.display(‘plan_table’,null,’basic +cost’));

or

select plan_table_output
from table(dbms_xplan.display(‘plan_table’,null,’typical -cost’));

2) Another important addition that was made to the low level options was in the 10gR2 release: PEEKED_BINDS. This option is available when you use display_cursor(). This option allows for the display of the bind variables that were used to generate a particular plan. We had blogged about bind variable peeking before and you can read more on it here.

Example:

select plan_table_output
from table(dbms_xplan.display_cursor(null,null,’basic +PEEKED_BINDS’));

Sorry, the comment form is closed at this time.

 
%d bloggers like this: