What are execution plans?

What are execution plans?

In the world of Oracle Database, an Execution Plan is the step-by-step "recipe" that the database follows to retrieve your data.

If your SQL query is the order you place at a restaurant ("I'd like a medium-rare steak"), the Execution Plan is the chef's instructions ("Go to the fridge, grab the ribeye, sear it for 4 minutes on each side, rest for 5 minutes").


1. What is an Execution Plan?

An execution plan is a set of operations that the Oracle Query Optimizer chooses to execute a SQL statement. Because SQL is a declarative language—meaning you describe what you want, not how to get it—the database must translate your words into a physical path.

The plan tells you:

  • The order in which tables are accessed.

  • The method used to access data (scanning a whole table vs. using an index).

  • The join logic used to combine data from different tables.

  • The estimated cost and time for each step.


2. Key Elements of a Plan

When you look at an execution plan, you will see a tree-like structure. Here are the most important terms you'll encounter:

A. Access Paths (How data is found)

  • TABLE ACCESS FULL: Oracle reads every single block in the table. (Fine for small tables, usually bad for massive ones).

  • INDEX RANGE SCAN: Oracle uses an index to find a range of values. (Fast for filtered queries).

  • INDEX UNIQUE SCAN: Finding exactly one row using a primary key. (The fastest possible access).

B. Join Methods (How tables are linked)

  • NESTED LOOPS: Good for small datasets; it takes one row from Table A and looks for a match in Table B.

  • HASH JOIN: Great for large datasets; it builds a "hash table" in memory to find matches quickly.


3. Why Should You Care?

As a developer or DBA, the execution plan is your primary troubleshooting tool.

If a query that used to take 1 second now takes 10 minutes, the execution plan will reveal why. Perhaps an index was dropped, causing a TABLE ACCESS FULL, or perhaps the Optimizer thinks there are 10 rows when there are actually 10 million, leading to the wrong join method.


4. How to Generate an Execution Plan

There are several ways to "peek" into the Optimizer's brain:

Method 1: The "Predictive" Plan (EXPLAIN PLAN)

This shows you what Oracle plans to do without actually running the query.

SQL
EXPLAIN PLAN FOR 
SELECT * FROM employees WHERE employee_id = 101;

SELECT * FROM TABLE(dbms_xplan.display);

Method 2: The "Actual" Plan (AWR/V$)

This shows you what Oracle actually did when the query ran. This is more reliable because it includes real-world timings.

SQL
SELECT * FROM TABLE(dbms_xplan.display_cursor('sql_id_here'));

5. Reading the Plan: The "Inside-Out" Rule

A common point of confusion is how to read the plan. Execution plans are hierarchical.

The Rule: Look for the most indented operation. That is usually the first thing that happens. You generally read from the bottom-up and inside-out.


6. Summary: Plan Health Check

Good SignsRed Flags
Index Scans on high-volume tables.Full Table Scans on tables with millions of rows.
Low "Cost" values.Cartesian Products (joining tables with no join condition).
Accurate Row Estimates (matches real data).Huge discrepancies between "Estimated" and "Actual" rows.

Pro-Tip: The "Cardinality" Clue

The most important column in an execution plan is often "Rows" (Cardinality). If the plan says it expects 1 row, but your query actually returns 100,000, the Optimizer's "cost" calculation will be completely wrong. This is usually fixed by gathering fresh statistics.

Looking for servers Rental ?

Call Our Expert :


  • (call for rental enquiries)

Email us :