Oracle Autotrace Commands: SQL Execution Plan Analysis

Oracle Database Autotrace Commands: Complete Guide to SQL Execution Plan Analysis

Autotrace is a SQL*Plus setting that shows the execution plan and runtime statistics for each statement you run.

What is Oracle Autotrace?

Oracle autotrace is a SQL*Plus feature that provides detailed information about how Oracle executes SQL statements. It shows the optimizer's execution path and runtime statistics.

Setting Up Autotrace Environment

Set the display width first:

1column plan_plus_exp format a100

This command formats the execution plan output to display properly within a 100-character width.

Core Autotrace Commands Breakdown

1. Display Execution Plan Only

1set autotrace on explain

Purpose: This command runs the SQL statement and prints its results; the AUTOTRACE report that follows shows only the optimizer execution path.

2. Show Plan Without Query Execution

1set autotrace traceonly explain

Purpose: The traceonly modifier hides the query results and prints only the plan. Use it when you don't need the result set, for example a query that returns millions of rows.

3. Complete Execution Analysis

1set autotrace on

Purpose: This mode runs the statement and shows the results, the execution plan and the statistics.

4. Statistics Only Mode

1set autotrace on statistics

Purpose: Executes the query and shows only performance statistics without displaying the execution plan.

Key Metrics Displayed:

  • Logical and physical reads
  • Redo size
  • Sorts in memory and on disk
  • Network roundtrips

5. Full Trace Without Results

1set autotrace traceonly

Purpose: Executes the statement but suppresses result output, showing only the execution plan and performance statistics.

Disabling Autotrace

1set autotrace off

Purpose: Turns autotrace off.

Best Practices and Implementation Tips

Performance Tuning Workflow

  1. Initial Analysis: Use set autotrace on explain to review execution plans
  2. Detailed Investigation: Apply set autotrace traceonly for comprehensive performance metrics
  3. Comparative Testing: Use set autotrace on statistics to compare two versions of a query.

Production Environment Considerations

  • Run autotrace on production during off-peak hours.
  • Document baseline performance metrics for future comparison

References

Posts in this series