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
- Initial Analysis: Use
set autotrace on explainto review execution plans - Detailed Investigation: Apply
set autotrace traceonlyfor comprehensive performance metrics - Comparative Testing: Use
set autotrace on statisticsto 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
- Oracle Database SQL Language Reference - Official documentation covering autotrace functionality and SQL*Plus commands
- Oracle Database Performance Tuning Guide - Comprehensive guide to Oracle performance optimization techniques
- Oracle SQL*Plus User's Guide and Reference - Complete reference for SQL*Plus commands including autotrace options
Posts in this series
- Oracle PLAN_TABLE Setup and EXPLAIN PLAN Usage Guide
- Oracle Autotrace Commands: SQL Execution Plan Analysis
- Oracle EXPLAIN PLAN: SQL Performance Analysis Guide
- Oracle Database: Find Query Hash Value Using V$SQLAREA
- Oracle SQL Hash Lookup: Retrieve SQL Text from V$SQLAREA
- Oracle SQL Execution Statistics Query with v$sqlarea
- Get the Actual Execution Plan with DBMS_XPLAN.DISPLAY_CURSOR
- Watch Long-Running SQL in Real Time with V$SQL_MONITOR
- List Oracle SQL Plan Baselines with DBA_SQL_PLAN_BASELINES