Toad for Oracle
Explain Plan
Explain Plan (also called Execution Plan) displays steps that will occur in the selected SQL statement. This lets you visually see the steps. The purpose of
Explain Plan is to determine the execution plan Oracle follows to execute a specified SQL statement. The Explain Plan function inserts a row describing each step of the execution plan into a specified plan table. If you are using cost-based optimization, Explain Plan also determines the cost of executing the statement based on the statistics that have been stored for the table.
Viewing previous Explain Plans via View | Explain Plan will not work unless you first create the tables needed for storage and retrieval of Explain Plans which you do automatically via the Server Side Object wizard (see the
Getting Started Guide). <CTRL> E Explain Plans in the SQL Editor will work regardless, but it you have not created the tables needed you must set the
View | Options | Oracle | Explain Plan Table name option to point your own plan table (Plan_Table). Make sure the View Options | Oracle | Save
Previous Explain Plan Results option is checked.
To execute Explain Plan on a SQL Statement
In the SQL Editor, place the cursor on a SQL statement, go to SQL Window|
Explain Plan Current SQL (OR <CTRL>E).
If View| Options| Oracle| Save previous Explain Plan results is checked, then Explain Plans are stored in:
Toad_PLAN_SQL and
Toad_PLAN_TABLE
52
SQL Editor
To run Explain Plan
1.
Load a SQL Script into the SQL Editor.
2.
Click on a SQL statement such as Select, Insert, Update, or Delete.
3.
Select SQL Editor| Explain Plan Current SQL menu item.
4.
Explain Plan results display in the results grid.
Notice the Explain Plan results have expand and collapse buttons. They let you display the details that you need to see.
If you attempt to activate an Explain Plan and you have not created the needed
Toad temp tables (which you can do automatically via the Server Side Object wizard during the install or from the Tools menu (see the Getting Started Guide), you get an error message telling you the table or view does not exist.
You can copy the Explain Plan hierarchy to the Windows clipboard or send it to the printer with a right-click over the Explain Plan output and selecting either the
Copy to Clipboard or Print Results menu item
View Explain Plan
View Explain Plan displays a list of the previous Explain Plans that you've executed.
To Access View Explain Plan
1.
Go to the View| Explain Plan menu item.
2.
Click the Explain Plan item.
3.
A list of previous Explain Plans displays.
You must have the View | Options | Oracle | Explain Plan Table Name menu item entered, or you will not be able to view previous plans. The default entry is Toad_PLAN_TABLE.
53
Toad for Oracle
Explain Plan Treeview
The Explain Plan treeview lists the contents of the Toad_PLAN_TABLE for the given statement id.
Operation
The concatenation of the OPERATION and OPTIONS columns of the plan table.
Object Name
The value of the OBJECT_NAME column of the plan table.
Rows
Number of rows accessed. This comes from the CARDINALITY column of the plan table. If appropriate, the number is converted to K (thousands), M
(millions), or G (1000 millions, or billions).
Bytes
Number of bytes accessed. This is the value of the BYTES column of the plan table. If appropriate, the number is displayed in Kilobytes, Megabytes, or
Gigabytes.
Cost
The value of the COST column of the plan table. If appropriate, the number is displayed in K (thousands), M (millions), or G (1000 millions, or billions). This column is not applicable to rule-based optimization.
Object Node
This column contains the contents of the OBJECT_NODE column used to keep track of the order in which operation's output is consumed for parallel queries.
54
SQL Editor
In/Out
The (abbreviated) value of the OTHER_TAG column in the plan table. It indicates how this step relates to the previous and subsequent steps with regard to parallel query execution.
ABBREVIATION
(blank)
P->S
P->P
PCWP
S->P
PCWC
MEANING
Serial execution
Parallel to Serial
Parallel to Parallel
Parallel combined with Parent
Parallel from Serial
Parallel Combined with Child
PStart
This column represents the DISTRIBUTION and PARTITION_START columns of the plan table.
ABBREVIATION FOR PSTART
ROWID
KEY
KEY(I) n n, m
MEANING
Row Location
KEY
KEY(INLIST)
Partition number for first partition in range
Partition and sub-partition number for first partition in range
55
Toad for Oracle
PStop
This column represents the PARTITION_STOP column of the plan table.
ABBREVIATION FOR PSTOP
ROW L
KEY n n, m
MEANING
Row Location
KEY
Partition number for first partition in range
Partition and sub-partition number for
last
partition in range
An operation's location in the treeview is determined by the values of LEVEL, ID,
PARENT_ID and POSITION for the row containing it.
Refer to Oracle documentation for more information on how to read and interpret an Explain Plan output.
56
SQL Editor
Recall and Add SQL
You access the Add and Recall SQL dialogs items through the SQL Editor menu.
The purpose of Add/Recall SQL is to create a list of previously executed SQL statements in order to recall them at a later date instead of having to retype them.
You can check the Save Only Statements that are Valid check box in the
View | Options | SQL Editor page. This check box item will only save those
SQL statements that execute successfully. This prevents the list from containing misspelled column names, etc.
SQL Recall Window
The SQL Recall window is dockable and can be pinned or hidden.
The SQL Recall window displays a list of the last X number of statements executed. The default number is 100, but you can change this in the options.
The maximum is 999.
Every statement executed in the SQL Editor is added to the statement recall list, unless you choose the option to only save valid ones. This list is organized with the most recent SQL at the top. You can select a statement from this list and run it, you can remove a statement from the list, and you can name your statements for easy recall. You can save a SQL statement as either a Personal SQL or Named
SQL.
All statements (to a maximum set in the SQL Options) are saved between sessions of Toad in the file Toad\User Files\savedsql.xml.
The SQL Recall window displays the Name of SQL (if any), SQL statement,
Connection information, and Date and time of last connection.
There are also tabs to display All SQL and Single SQL which show more detail of a long SQL statement.
You can search by clicking in the SQL Contains dropdown.
The SQL Recall window is dockable within Toad.
The SQL Recall Window toolbar is composed of two parts: the Main toolbar and the SQL Filter toolbar. You can hide or display each part.
Main SQL Statement Recall Toolbar
57
Toad for Oracle
The Main SQL Statement Recall toolbar includes commands for working with the
SQL statements that Toad has archived. You can save and copy SQL statements, remove selected SQL statements from the SQL list, Display connection information and the date last executed, edit via double-click in appropriate cell, and group by connection or SQL type.
SQL Filter Toolbar
The SQL Filter toolbar contains filtering options for your list of SQL statements.
The SQL Contains dropdown lets you filter the list by a character string contained within the SQL. The Database dropdown lets you filter by Database. The Show dropdown lets you display History, Named, or Personal SQL statements.
To recall a SQL command
• Press F8
– OR –
• Select SQL Command Recall from the View menu
Running a Recalled SQL Statement
After a SQL statement is recalled and placed in the SQL Editor, press
<CTRL><ENTER> or <SHIFT>F9. Toad will search backwards one line from the current cursor position to find a SQL statement to execute.
Add to Personal SQLs
Selecting this command from the SQL Editor menu adds the SQL statement that's in the SQL Editor to your Personal SQLs. You can later recall the statement by using the Recall Personal SQL command.
Toad saves all statements in this list between sessions of Toad in a file named savedsql.xml in the Toad\User Files folder.
To Add a SQL Statement to the Personal SQL List
1.
Select the statement by highlighting it in the editor.
2.
Click menu item SQL Editor| Add to Personal SQLs.
58
SQL Editor
Add to Named SQLs
This window lets you add a SQL statement to a user's Named list.
To Add a SQL Statement to the Named SQL List
1.
Select the statement by highlighting it in the editor.
2.
Click menu item SQL Editor| Add to Named SQLs.
3.
Type the name you want to assign.
4.
Click OK.
Recall Named SQL
Use this dialog to pick a SQL statement from your named list of SQLs, then copy it back to the SQL Edit window for execution. The Recall SQL window for Recall
Named SQL lists the names on the left panel and highlights the corresponding
SQL statement on the right panel.
The SQL statements are stored in the Toad\User Files\savedsql.xml file.
More about Recall
You can view recalled SQL statements in groups or individually and move them into editors.
To view all SQL statements
1.
From the View menu select SQL Command Recall.
2.
Click the All SQL tab.
To view Personal and Named SQL
1.
From the View menu, select SQL Command Recall.
2.
Click the All SQL tab.
3.
Use the SQL Filtering toolbar to filter out everything but the
Personal or Named SQL from the grid.
To view individual SQL
1.
From the View menu select SQL Command Recall.
2.
Select one or more SQL statements.
3.
Click the Single SQL tab.
In the single SQL tab, the operators F4, <CTRL> click, and right-click Describe are available.
You can open SQL statements in the SQL Editor or drag-and-drop them into the
Procedure Editor or Text Editor or by double-clicking them in the All SQL grid.
59
Toad for Oracle
To drag-and-drop SQL statements
1.
Select one or more SQL statements from the SQL Recall window.
2.
Drag the selection to one of the editors and drop the selection in the editing window.
If you want to open a SQL Statement in the SQL Editor, double-click on the desired SQL statement.
You can scroll through the previous statements directly within a SQL Editor edit panel by pressing <ALT> <UP> or <ALT> <DOWN>.
60