Lesson 10
Using the EXPLAIN PLAN Utility Conclusion
Well, we should now have a firm grasp of the basic concepts behind running the EXPLAIN PLAN to see the access path to data. This module was not intended to make you an expert, and there is always more to learn, especially when you are working with complex SQL queries.
Declarative SQL
The following is a comprehensive list of the knowledge you should have before moving on to the next module.
- All SQL is declarative.
- There are many ways to write any SQL query, and some will retrieve rows faster than other methods.
- Oracle uses a table called PLAN to hold the access information about the query.
- You can create a PLAN table by running the SQL in $ORACLE_HOME/rdbms/admin/utlxplan.sql.
- EXPLAIN PLAN output is very cryptic and difficult to interpret. The output is read inside-out, bottom to top.
- You can easily identify full table scans in EXPLAIN PLAN output by looking for TABLE ACCESS FULL. Full-table scans on large tables take a huge amount of I/O, which can sometimes be alleviated by adding indexes to the target table.
- When you issue a table join or a non-correlated subquery, Oracle will use the nested loop method to join the tables together. This nested loop method requires a driving table and a probe table.
- Sometimes the use_hash hint will improve the speed of nested loop joins.
- Non-correlated subqueries should only be used with the NOT IN predicate.
- Index range scans commonly occur when a range comparison has been made against a numeric column in a table, and an index exists for that column.
- Oracle SQL Analyzer tool (an extra-cost add-on), Q diagnostic center, or SQLab can be used to simplify the reading of complex EXPLAIN PLAN output.
Protect the integrity of the data (Referential Integrity)
Another important benefit of programmability is the ability of the database server to protect the integrity of the data from malicious users and applications accessing the database across a network. While basic relational integrity rules such as referential integrity are generally best defined declaratively, as part of the database schema, database triggers make it possible for the server to actively enforce arbitrary business rules that require a procedural definition. By centralizing business logic in the database, it need not be coded in every application that accesses the database, thus avoiding redundancy and errors, and making it feasible to provide end users with direct access to the data.
For its part, Oracle Corporation used the Ada programming language as a model for PL/SQL, its own proprietary procedural language. Like Ada, PL/SQL includes language features like exception handling and parameter type declarations that facilitate the development of reliable, large-scale, and complex systems. The procedural language eventually added to the SQL standard resembles PL/SQL in many respects. PL/SQL first appeared for client-side use (in Oracle's SQL*Forms) in 1988, and with Oracle7 in 1992 for triggers and stored procedures that execute within the database.
The important concepts from this module include the ability to:
- Understand SQL as a declarative language
- Create a PLAN table
- Run the EXPLAIN PLAN utility
- Detect full-table scans with EXPLAIN PLAN
- Use EXPLAIN PLAN to diagnose table joins
- Read non-correlated subqueries
- Detect index range scans
- Analyze complex EXPLAIN PLAN output
New terms
Here are some terms that might have been new to you.
- EXPLAIN PLAN: This is an Oracle utility to show the access path.
- Index range scan: This is a scan of a table using an index.
- Nested loop: This is a join method that queries the driving table and then probes the other tables via an index.
- Non-correlated subquery : This is an SQL subquery that does not have a WHERE condition that references values in the outer query.
- Optimizer: This is an Oracle tool used to determine Oracle SQL execution plans.
- PLAN TABLE: This is an internal table that contains the display of the execution plan.
The next lesson delves into SQL optimizers.
Explain Plan - Quiz
Before moving on to the next module, click the Quiz link below to test your understanding of the EXPLAIN PLAN utility.
Explain Plan - Quiz