 |
|
SQL Internal Processing
Oracle Tips by Burleson Consulting |
This chapter is concerned with providing a
detailed understanding of how SQL is processed within the Oracle
database instance. We will be exploring the Oracle library cache,
and you will see how you can write queries to see exactly what is
happening to your SQL statements. We will also explore techniques
for investigating SQL sort activity and see how you can quickly find
SQL statements that are invoking disk sorts. Best of all, I will
show you how to get the execution plan for all SQL statements in the
library cache and create reports that show you exactly what your SQL
is doing. This chapter will include the following sections:
-
Oracle shared SQL and private SQL areas
-
SGA statistics for SQL
-
Monitoring and tuning Oracle sorting
-
Identifying high-impact SQL in the library
cache
-
Reporting on SQL in the library cache
Let’s begin with an in-depth overview of the
SQL areas.
Shared and Private SQL Areas
Within the
library cache, Oracle stores the source for your SQL statement as
well as the execution plan for the SQL. Within an individual SQL
statement, Oracle partitions the SQL into several areas, a shared
area and a private area (see Figure 5-1). In order to make all SQL
statements reusable, Oracle segments the parts of the SQL statement
that are generic into the shared area, specifically the original
parse tree for the SQL and the execution plan. The private SQL area,
which includes SQL information that is user-specific, is divided
into a persistent areas and a run-time area. The persistent area
remains in memory unless the corresponding cursor has been closed.
Hence, you should always close all open cursors that will not be
used again for better memory utilization within the private SQL
area. The run-time area is freed after the statement is executed.
Figure 1: The SQL
shared and private areas
The private area includes binding data,
run-time buffers, cursors, host variables, and other control
structures that are specific to the user. The separation of the SQL
areas allows Oracle SQL to remain fully reentrant and reusable while
allowing simultaneous execution of any SQL statement.
Next, let’s look at some system-wide SGA
statistics that can give us insight into our SQL behavior.
This is an excerpt from "Oracle High-Performance SQL Tuning" by
Donald K. Burleson, published by Oracle Press.