Previous | Table of Contents | Next |
Once the cursor is created, a determination is made about whether the SQL statement is already present in the shared SQL area in the shared pool. If the SQL statement has already been parsed and is in the shared pool, there is no further need for parsing and the execution of the SQL statement continues. By using stored procedures or carefully crafting SQL statements to be identical, there is a good chance that those statements will be in the shared SQL area already parsed.
For an SQL statement to take advantage of SQL or PL/SQL statements that may have already been parsed, the following criteria must be met:
You may think that these conditions make it difficult to take advantage of the shared SQL areas. In fact, users sharing the same application code meet these criteria quite easily. It is to the advantage of the application developer to use the same SQL statements to access the same data, ensuring that SQL statements within the application can also take advantage of the shared SQL areas.
If the already parsed SQL statement is not in the shared pool, the following steps are executed to parse the SQL statement:
Tip:
Using stored procedures whenever possible guarantees that the same shared PL/SQL area is used. Another advantage is that stored procedures are stored in a parsed form, eliminating runtime parsing altogether.Standardizing naming conventions for bind variables and spacing conventions for SQL and PL/SQL statements also increases the likelihood of reusing shared SQL statements.
The V$LIBRARYCACHE table contains statistics on how well you are using the library cache. The important columns to view in this table are PINS and RELOADS. The PINS column contains the number of times the item in the library cache was executed. The RELOADS column contains the number of times the library cache missed and the library object was reloaded. A few number of reloads relative to the number of executions indicates a high cache-hit rate for shared SQL statements.
As you can see from the number of steps that must be executed, it is important to try to keep the SQL statements in the shared pool to avoid the parsing phase of the execution process.
Queries are handled differently than other SQL statements because queries return data as the result of the statement. Other SQL statements need only return a return code that indicated success or failure. In addition to the other steps that must be executed, queries may require the following additional functions:
The following functions also may be executed outside of the RDBMS:
The preceding functions are necessary only for queries, in addition to the other SQL statement processing.
Variables, when used, must be defined before the statement can be processed. The application program must specify to Oracle the address of the variable before Oracle can bind that variable. Because the binding is done by reference, you do not have to rebind a variable before re-executing the statement; simply changing its value is sufficient.
You must supply the datatype and length of each variable you bind to Oracle unless these datatypes or lengths are implied or defaulted.
Once the statement has been parsed and the variables have been defined, the statement is executed. In array processing, the execution step may happen many times. Any necessary locks are applied before the execution of the statement.
Previous | Table of Contents | Next |