Sub topic 4
Choosing a DBMS_XPLAN Format
Assume you know basic SQL, joins, tables, indexes, and primary keys. You also need access to an Oracle database and permission to run EXPLAIN PLAN. This chapter focuses on choosing the output format, not on interpreting every operation in a plan.
DBMS_XPLAN formats an execution plan for display. The format argument controls how much information Oracle prints. The main choices are BASIC, TYPICAL, and ALL.
The three main formats
| Format | Best use | Information shown |
|---|---|---|
| `BASIC` | A quick overview | Operation, object name, and estimated rows |
| `TYPICAL` | Normal investigation | The plan tree, costs, predicates, and useful notes |
| `ALL` | Detailed analysis | TYPICAL information plus additional plan details |
TYPICAL is the default for many DBMS_XPLAN functions. It usually gives enough information to understand the plan without producing a very wide result.
BASIC is useful when you only need to confirm the shape of a plan. It can hide details that explain why an operation was chosen.
ALL is useful when diagnosing a difficult query. It can include information such as projections, aliases, outline data, and other optimizer details. The exact sections depend on the DBMS_XPLAN function and the format modifiers.
Using format modifiers
A format modifier adds or removes a section. For example, +PREDICATE requests the Predicate Information section:
EXPLAIN PLAN FOR
SELECT last_name
FROM hr.employees
WHERE department_id = 50;
SELECT *
FROM TABLE(DBMS_XPLAN.DISPLAY(
format => 'BASIC +PREDICATE'
));The plus sign enables a section. A minus sign disables one when that section is included by the base format. Common modifiers include:
+PREDICATEshows access and filter predicates.+PROJECTIONshows the expressions produced by each operation.+ALIASshows query block and table aliases.+NOTEshows optimizer notes when available.+OUTLINEshows hints that reproduce the displayed plan.-NOTEsuppresses the Note section.ALLSTATS LASTrequests runtime statistics for the last execution of a cursor.
The format string is a space-separated list. For example, TYPICAL +PREDICATE -NOTE starts with the typical layout, adds predicates, and suppresses notes.
Choosing a format by task
Use this decision path:
For a first look, use TYPICAL. If predicates are missing from a reduced display, add +PREDICATE. If you are comparing estimated and actual behavior, use ALLSTATS LAST with DISPLAY_CURSOR, after executing the statement with row-source statistics enabled.
SELECT /*+ GATHER_PLAN_STATISTICS */
last_name
FROM hr.employees
WHERE department_id = 50;
SELECT *
FROM TABLE(DBMS_XPLAN.DISPLAY_CURSOR(
format => 'ALLSTATS LAST'
));LAST means the last execution represented by the cursor. The hint tells Oracle to collect the row-source statistics needed for the display.
Exercise
Which format is a sensible starting point for investigating a query, and which modifier adds predicate details to a minimal display?
Show answer
Start with TYPICAL. Add +PREDICATE, or use BASIC +PREDICATE when you want a minimal plan with predicate information.