Advanced SQL tips - reading an execution plan


When Codd and Date created the relational data model, the execution plan was an afterthought, largely because the SQL optimizer was always supposed to generate the best execution plan, and hence, there was not real need to understand the internal machinations of Oracle execution plans.

However, in the real world, all SQL tuning experts must be proficient in reading Oracle execution plans and understand the steps within an explain plan and the sequence in which the steps are executed. To successfully understand an explain plan, you must be able to know the order that the plan steps are executed. Reading an explain plan is important for many reasons, and Oracle SQL tuning experts use the explain plans to check many things. For example:

Reading SQL execution plans has always been difficult, but there are some tricks to help determine the correct order that the explain plan steps are executed.

Ordering the sequence of execution plan steps

SQL execution plans are interpreted using a preorder (reverse) transversal algorithm. This is a fancy way of saying:

1 - To read an execution plan, look for the innermost indented statement. That is generally the first statement executed.
2 - In most cases, if there are two statements at the same level, the first statement is executed first.

In other words, execution plans are read inside-out, starting with the most indented operation. There are some general rules for reading an explain plan.

Read on and learn how to read the sequence of steps in any SQL execution plan:

more