Skip Headers

Oracle9i Database Performance Tuning Guide and Reference
Release 2 (9.2)

Part Number A96533-02
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Feedback

Go to previous page Go to next page
View PDF

7
Using Plan Stability

This chapter describes how to use plan stability to preserve performance characteristics.

This chapter contains the following sections:

Using Plan Stability to Preserve Execution Plans

Plan stability prevents certain database environment changes from affecting the performance characteristics of applications. Such changes include changes in optimizer statistics, changes to the optimizer mode settings, and changes to parameters affecting the sizes of memory structures, such as SORT_AREA_SIZE and BITMAP_MERGE_AREA_SIZE. Plan stability is most useful when you cannot risk any performance changes in an application.

Plan stability preserves execution plans in stored outlines. Oracle can create a public or private stored outline for one or all SQL statements. The optimizer then generates equivalent execution plans from the outlines when you enable the use of stored outlines. You can group outlines into categories and control which category of outlines Oracle uses to simplify outline administration and deployment.

The plans Oracle maintains in stored outlines remain consistent despite changes to a system's configuration or statistics. Using stored outlines also stabilizes the generated execution plan if the optimizer changes in subsequent Oracle releases. Plan stability also facilitates migration from the rule-based optimizer to the cost-based optimizer when you upgrade to a new Oracle release.


Note:

If you develop applications for mass distribution, then you can use stored outlines to ensure that all customers access the same execution plans.


Using Hints with Plan Stability

The degree to which plan stability controls execution plans is dictated by how much Oracle's hint mechanism controls execution plans, because Oracle uses hints to record stored plans.

There is a one-to-one correspondence between SQL text and its stored outline. If you specify a different literal in a predicate, then a different outline applies. To avoid this, replace literals in applications with bind variables.

See Also:

Oracle can force similar statements to share SQL by replacing literals with system-generated bind variables. This works with plan stability if the outline was generated using the CREATE_STORED_OUTLINES parameter, not the CREATE OUTLINE statement. Also, the outline must have been created with the CURSOR_SHARING parameter set to SIMILAR or FORCE, and the parameter must also set to SIMILAR or FORCE when attempting to use the outline. See Chapter 14, "Memory Configuration and Use" for more information.

Plan stability relies on preserving execution plans at a point in time when performance is satisfactory. In many environments, however, attributes for datatypes such as dates or order numbers can change rapidly. In these cases, permanent use of an execution plan can result in performance degradation over time as the data characteristics change.

This implies that techniques that rely on preserving plans in dynamic environments are somewhat contrary to the purpose of using cost-based optimization. Cost-based optimization attempts to produce execution plans based on statistics that accurately reflect the state of the data. Thus, you must balance the need to control plan stability with the benefit obtained from the optimizer's ability to adjust to changes in data characteristics.

How Outlines Use Hints

An outline consists primarily of a set of hints that is equivalent to the optimizer's results for the execution plan generation of a particular SQL statement. When Oracle creates an outline, plan stability examines the optimization results using the same data used to generate the execution plan. That is, Oracle uses the input to the execution plan to generate an outline, and not the execution plan itself.


Note:

Oracle creates the USER_OUTLINES and USER_OUTLINE_HINTS views in the SYS tablespace based on data in the OL$ and OL$HINTS tables, respectively. Direct manipulation of the OL$, OL$HINTS, and OL$NODES tables is prohibited.

You can embed hints in SQL statements, but this has no effect on how Oracle uses outlines. Oracle considers a SQL statement that you revised with hints to be different from the original SQL statement stored in the outline.


Storing Outlines

Oracle stores outline data in the OL$, OL$HINTS, and OL$NODES tables. Unless you remove them, Oracle retains outlines indefinitely.

The only effect outlines have on caching execution plans is that the outline's category name is used in addition to the SQL text to identify whether the plan is in cache. This ensures that Oracle does not use an execution plan compiled under one category to execute a SQL statement that Oracle should compile under a different category.

Enabling Plan Stability

Settings for several parameters, especially those ending with the suffix _ENABLED, must be consistent across execution environments for outlines to function properly. These parameters are:

Using Supplied Packages to Manage Stored Outlines

The DBMS_OUTLN and DBMS_OUTLN_EDIT package provides procedures used for managing stored outlines and their outline categories.

Users need the EXECUTE_CATALOG_ROLE role to execute DBMS_OUTLN, but public has execute privileges on DBMS_OUTLN_EDIT. The DBMS_OUTLN_EDIT package is an invoker's rights package.

See Also:

Oracle9i Supplied PL/SQL Packages and Types Reference for detailed information on using DBMS_OUTLN and DBMS_OUTLN_EDIT procedures

Creating Outlines

Oracle can automatically create outlines for all SQL statements, or you can create them for specific SQL statements. In either case, the outlines derive their input from the optimizer.

Oracle creates stored outlines automatically when you set the parameter CREATE_STORED_OUTLINES to true. When activated, Oracle creates outlines for all compiled SQL statements. You can create stored outlines for specific statements using the CREATE OUTLINE statement.


Note:

You must ensure that schemas in which outlines are to be created have the CREATE ANY OUTLINE privilege. Otherwise, despite having turned on the CREATE_STORED_OUTLINE parameter, you will not find outlines in the database after you run the application.

Also, the default system tablespace can become exhausted if the CREATE_STORED_OUTLINES parameter is enabled and the running application has an abundance of literal SQL statements. If this happens, use the DBMS_OUTLN.DROP_UNUSED procedure to remove those literal SQL outlines.


The CREATE_EDIT_TABLES procedure in the DBMS_OUTLN_EDIT package creates tables in the invoker's schema. This is necessary for editing private outlines. This is callable by anyone with EXECUTE privilege on DBMS_OUTLN_EDIT.

See Also:

Using Category Names for Stored Outlines

Outlines can be categorized to simplify the management task. The CREATE OUTLINE statement allows for specification of a category. The DEFAULT category is chosen if unspecified. Likewise, the CREATE_STORED_OUTLINES parameter lets you specify a category name, where specifying true produces outlines in the DEFAULT category.

If you specify a category name using the CREATE_STORED_OUTLINES parameter, then Oracle assigns all subsequently created outlines to that category until you reset the category name. Set the parameter to false to suspend outline generation.

If you set CREATE_STORED_OUTLINES to true, or if you use the CREATE OUTLINE statement without a category name, then Oracle assigns outlines to the category name of DEFAULT.


Note:

The CREATE_STORED_OUTLINES, USE_STORED_OUTLINES, and USE_PRIVATE_OUTLINES parameters are system or session specific. They are not initialization parameters. For more information on these parameters, see the Oracle9i SQL Reference.


Using and Editing Stored Outlines

When you activate the use of stored outlines, Oracle always uses the cost-based optimizer. This is because outlines rely on hints, and to be effective, most hints require the cost-based optimizer.

To use stored outlines when Oracle compiles a SQL statement, set the system parameter USE_STORED_OUTLINES to true or to a category name. If you set USE_STORED_OUTLINES to true, then Oracle uses outlines in the default category. If you specify a category with the USE_STORED_OUTLINES parameter, then Oracle uses outlines in that category until you reset the parameter to another category name or until you suspend outline use by setting USE_STORED_OUTLINES to false. If you specify a category name and Oracle does not find an outline in that category that matches the SQL statement, then Oracle searches for an outline in the default category.

The designated outlines only control the compilation of SQL statements that have outlines. If you set USE_STORED_OUTLINES to false, then Oracle does not use outlines. When you set USE_STORED_OUTLINES to false and you set CREATE_STORED_OUTLINES to true, Oracle creates outlines but does not use them.

The USE_PRIVATE_OUTLINES parameter lets you control the use of private outlines. A private outline is an outline seen only in the current session and whose data resides in the current parsing schema. Any changes made to such an outline are not seen by any other session on the system, and applying a private outline to the compilation of a statement can only be done in the current session with the USE_PRIVATE_OUTLINES parameter. Only when you explicitly choose to save your edits back to the public area are they seen by the rest of the users.

While the optimizer usually chooses optimal plans for queries, there are times when users know things about the execution environment that are inconsistent with the heuristics that the optimizer follows. By editing outlines directly, you can tune the SQL query without having to alter the application.

When a private outline is created, an error is returned if the prerequisite outline tables to hold the outline data do not exist in the local schema. These tables can be created using the DBMS_OUTLN_EDIT.CREATE_EDIT_TABLES procedure. You can also use the UTLEDITOL.SQL script.

When the USE_PRIVATE_OUTLINES parameter is enabled and an outlined SQL statement is issued, the optimizer retrieves the outline from the session private area rather than the public area used when USE_STORED_OUTLINES is enabled. If no outline exists in the session private area, then the optimizer will not use an outline to compile the statement.

Any CREATE OUTLINE statement requires the CREATE ANY OUTLINE privilege. Specification of the FROM clause also requires the SELECT privilege. This privilege should be granted only to those users who would have the authority to view SQL text and hint text associated with the outlined statements. This role is required for the CREATE OUTLINE FROM command unless the issuer of the command is also the owner of the outline.

When you begin an editing session, USE_PRIVATE_OUTLINES should be set to the category to which the outline being edited belongs. When you are finished editing, this parameter should be set to false to restore the session to normal outline lookup according to the USE_STORED_OUTLINES parameter.

You can use the GUI Outline Editor of the Oracle Enterprise Manager Tuning Pack to update outlines. Figure 7-1 is an illustration of the Outline Editor.

Figure 7-1 Outline Editor

Text description of outlineed1.gif follows.

Text description of the illustration outlineed1.gif

See Also:

Database Tuning with the Oracle Tuning Pack for more information on the GUI tool for editing outlines

Example of Editing Outlines

Assume that you want to edit the outline ol1. The steps are as follows:

  1. Connect to a schema from which the outlined statement can be executed, and ensure that the CREATE ANY OUTLINE and SELECT privileges have been granted.
  2. Create outline editing tables locally with the DBMS_OUTLN_EDIT.CREATE_EDIT_TABLES procedure.
  3. Clone the outline being edited to the private area using the following:
    CREATE PRIVATE OUTLINE p_ol1 FROM ol1;
    
    
  4. Edit the outline, either with the Outline Editor in Enterprise Manager or manually by querying the local OL$HINTS tables and performing DML against the appropriate hint tuples. DBMS_OUTLN_EDIT.CHANGE_JOIN_POS is available for changing join order.
  5. If manually editing the outline, then resynchronize the stored outline definition using the following so-called identity statement:
    CREATE PRIVATE OUTLINE p_ol1 FROM PRIVATE p_ol1;
    
    

    You can also use DBMS_OUTLN_EDIT.REFRESH_PRIVATE_OUTLINE or ALTER SYSTEM FLUSH SHARED_POOL to accomplish this.

  6. Test the edits. Set USE_PRIVATE_OUTLINES=TRUE, and issue the outline statement or run EXPLAIN PLAN on the statement.
  7. If you want to preserve these edits for public use, then publicize the edits with the following statement.
    CREATE OR REPLACE OUTLINE ol1 FROM PRIVATE p_ol1;
    
    
  8. Disable private outline usage by setting the following:
    USE_PRIVATE_OUTLINES=FALSE
    
    
    See Also:

How to Tell If an Outline Is Being Used

You can test if an outline is being used with the V$SQL view. Query the OUTLINE_CATEGORY column in conjunction with the SQL statement. If an outline was applied, then this column contains the category to which the outline belongs. Otherwise, it is NULL. The OUTLINE_SID column tells you if this particular cursor is using a public outline (value is 0) or a private outline (session's SID of the corresponding session using it).

For example:

SELECT OUTLINE_CATEGORY, OUTLINE_SID
FROM V$SQL 
WHERE SQL_TEXT LIKE 'SELECT COUNT(*) FROM emp%';

Viewing Outline Data

You can access information about outlines and related hint data that Oracle stores in the data dictionary from the following views:

Use the following syntax to obtain outline information from the USER_OUTLINES view, where the outline category is mycat:

SELECT NAME, SQL_TEXT 
FROM USER_OUTLINES 
WHERE CATEGORY='mycat';

Oracle responds by displaying the names and text of all outlines in category mycat.

To see all generated hints for the outline name1, use the following syntax:

SELECT HINT 
FROM USER_OUTLINE_HINTS 
WHERE NAME='name1';

Note:

If necessary, you can use the procedure to move outline tables from one tablespace to another as described in "Moving Outline Tables".


Moving Outline Tables

Oracle creates the USER_OUTLINES and USER_OUTLINE_HINTS views based on data in the OL$ and OL$HINTS tables, respectively. Oracle creates these tables, and also the OL$NODES table, in the SYS tablespace using a schema called OUTLN. If outlines use too much space in the SYS tablespace, then you can move them. To do this, create a separate tablespace and move the outline tables into it using the following process.

  1. The default system tablespace could become exhausted if the CREATE_STORED_OUTLINES parameter is on and if the running application has many literal SQL statements. If this happens, then use the DBMS_OUTLN.DROP_UNUSED procedure to remove those literal SQL outlines.

    See Also:

    Oracle9i Supplied PL/SQL Packages and Types Reference for detailed information on using the DBMS_OUTLN package

  1. Export the OL$, OL$HINTS, and OL$NODES tables:
    EXP OUTLN/OUTLN FILE = exp_file TABLES = 'OL$' 'OL$HINTS' 'OL$NODES'
    
    
    
  2. Remove the previous OL$, OL$HINTS, and OL$NODES tables:
    CONNECT OUTLN/outln_password;
    DROP TABLE OL$; 
    CONNECT OUTLN/outln_password;
    DROP TABLE OL$HINTS; 
    CONNECT OUTLN/outln_password;
    DROP TABLE OL$NODES; 
    
    
    
  3. Create a new tablespace for the tables:
    CREATE TABLESPACE outln_ts 
    DATAFILE 'tspace.dat' SIZE 2MB 
    DEFAULT STORAGE (INITIAL 10KB NEXT 20KB 
    MINEXTENTS 1 MAXEXTENTS 999 PCTINCREASE 10) ONLINE; 
    
    
  4. Enter the following statement:
    ALTER USER OUTLN DEFALUT TABLESPACE outln_ts;
    
    
    
  5. Import the OL$, OL$HINTS, and OL$NODES tables:
    IMP OUTLN/outln_password 
    FILE=exp_file TABLES = 'OL$' 'OL$HINTS' 'OL$NODES'
    
    
    

The IMPORT statement re-creates the OL$, OL$HINTS, and OL$NODES tables in the schema named OUTLN, but the schema now resides in a new tablespace called OUTLN_TS.


Note:

If Oracle8i outlines are imported into an Oracle9i database, then the DBMS_OUTLN.UPDATE_SIGNATURES procedure must be run. This updates the signatures of all outlines on the system so that they are compatible with Oracle9i semantics. If this step is not done, then no outlines from the Oracle8i database are used.


Using Plan Stability with the Cost-Based Optimizer

This section describes procedures you can use to significantly improve performance by taking advantage of cost-based optimizer functionality. Plan stability provides a way to preserve a system's targeted execution plans with satisfactory performance while also taking advantage of new cost-based optimizer features for the rest of the SQL statements.

Topics covered in this section are:

Using Outlines to Move to the Cost-Based Optimizer

If an application was developed using the rule-based optimizer, then a considerable amount of effort might have gone into manually tuning the SQL statements to optimize performance. You can use plan stability to leverage the effort that has already gone into performance tuning by preserving the behavior of the application when upgrading from rule-based to cost-based optimization.

By creating outlines for an application before switching to cost-based optimization, the plans generated by the rule-based optimizer can be used, while statements generated by newly written applications developed after the switch use cost-based plans. To create and use outlines for an application, use the following process.


Note:

Carefully read this procedure and consider its implications before executing it!


  1. Ensure that schemas in which outlines are to be created have the CREATE ANY OUTLINE privilege. For example, from SYS:
    GRANT CREATE ANY OUTLINE TO user-name
    
    
    
    
  2. Execute syntax similar to the following to designate; for example, the RBOCAT outline category.
    ALTER SESSION SET CREATE_STORED_OUTLINES = rbocat;
    
    
  3. Run the application long enough to capture stored outlines for all important SQL statements.
  4. Suspend outline generation:
    ALTER SESSION SET CREATE_STORED_OUTLINES = FALSE;
    
    
  5. Gather statistics with the DBMS_STATS package.
  6. Alter the parameter OPTIMIZER_MODE to CHOOSE.
  7. Enter the following syntax to make Oracle use the outlines in category RBOCAT:
    ALTER SESSION SET USE_STORED_OUTLINES = rbocat;
    
    
  8. Run the application.

    Subject to the limitations of plan stability, access paths for this application's SQL statements should be unchanged.


    Note:

    If a query was not executed in step 2, then you can capture the old behavior of the query even after switching to cost-based optimization. To do this, change the optimizer mode to RULE, create an outline for the query, and then change the optimizer mode back to CHOOSE.


Upgrading and the Cost-Based Optimizer

When upgrading to a new Oracle release under cost-based optimization, there is always a possibility that some SQL statements will have their execution plans changed due to changes in the optimizer. While such changes benefit performance, you might have applications that perform so well that you would consider any changes in their behavior to be an unnecessary risk. For such applications, you can create outlines before the upgrade using the following procedure.


Note:

Carefully read this procedure and consider its implications before running it!


  1. Enter the following syntax to enable outline creation:
    ALTER SESSION SET CREATE_STORED_OUTLINES = ALL_QUERIES;
    
    
  2. Run the application long enough to capture stored outlines for all critical SQL statements.
  3. Enter this syntax to suspend outline generation:
    ALTER SESSION SET CREATE_STORED_OUTLINES = FALSE;
    
    
  4. Upgrade the production system to the new version of the RDBMS.
  5. Run the application.

After the upgrade, you can enable the use of stored outlines, or alternatively, you can use the outlines that were stored as a backup if you find that some statements exhibit performance degradation after the upgrade.

With the latter approach, you can selectively use the stored outlines for such problematic statements as follows:

  1. For each problematic SQL statement, change the CATEGORY of the associated stored outline to a category name similar to this:
    ALTER OUTLINE outline_name CHANGE CATEGORY TO problemcat;
    
    
  2. Enter this syntax to make Oracle use outlines from the category problemcat.
    ALTER SESSION SET USE_STORED_OUTLINES = problemcat;
    

Upgrading with a Test System

A test system, separate from the production system, can be useful for conducting experiments with optimizer behavior in conjunction with an upgrade. You can migrate statistics from the production system to the test system using import/export. This can alleviate the need to fill the tables in the test system with data.

You can move outlines between the systems by category. For example, after you create outlines in the problemcat category, export them by category using the query-based export option. This is a convenient and efficient way to export only selected outlines from one database to another without exporting all outlines in the source database. To do this, issue these statements:

EXP OUTLN/outln_password FILE=exp-file TABLES= 'OL$' 'OL$HINTS' 'OL$NODES'
QUERY='WHERE CATEGORY="problemcat"'