Call now: 252-767-6166  
Oracle Training Oracle Support Development Oracle Apps

 
 Home
 E-mail Us
 Oracle Articles
New Oracle Articles


 Oracle Training
 Oracle Tips

 Oracle Forum
 Class Catalog


 Remote DBA
 Oracle Tuning
 Emergency 911
 RAC Support
 Apps Support
 Analysis
 Design
 Implementation
 Oracle Support


 SQL Tuning
 Security

 Oracle UNIX
 Oracle Linux
 Monitoring
 Remote s
upport
 Remote plans
 Remote
services
 Application Server

 Applications
 Oracle Forms
 Oracle Portal
 App Upgrades
 SQL Server
 Oracle Concepts
 Software Support

 Remote S
upport  
 Development  

 Implementation


 Consulting Staff
 Consulting Prices
 Help Wanted!

 


 Oracle Posters
 Oracle Books

 Oracle Scripts
 Ion
 Excel-DB  

Don Burleson Blog 


 

 

 


 

 

 
 
 

Stored Outline tips

Oracle Database Tips by Donald BurlesonJuly 24, 2015


Another 8i feature requiring the cost-based optimizer is stored outlines. To force Oracle to execute SQL statements the same way no matter what occurs at the operating system level, database level, etc., create a stored outline and invoke its category. The system privilege, QUERY REWRITE, must be granted to the schema that plans to use stored outlines and materialized views. The following command is entered from the SYS schema.

 

Also see my notes on displaying SQL plan outlines.

 

SQL> GRANT QUERY REWRITE TO SYSTEM;
Grant succeeded.
SQL> CONNECT SYSTEM/MANAGER

The following command creates a stored outline named EMPLOYEES with a category of SALARY.

 

SQL> CREATE OR REPLACE OUTLINE EMPLOYEES
 
2   FOR CATEGORY SALARY ON
 
3   SELECT  ENAME, SAL, LOC
 
4   FROM    EMP, DEPT
 
5   WHERE   EMP.DEPTNO = DEPT.DEPTNO;
Outline created.

Several data dictionary views get updated when you create stored outlines. The view user_outline_hints is actually looking at outln.ol$_hints. The following query shows that Oracle stores ten hints for the SQL statement joining the EMP and DEPT tables in category SALARY.

 SQL> SELECT  HINT
 
2   FROM    USER_OUTLINE_HINTS
 
3   WHERE   NAME = 'EMPLOYEES'

 4*  ORDER   BY HINT;

HINT
------------------------------
FULL(DEPT)
FULL(EMP)
NOREWRITE
NOREWRITE
NO_EXPAND
NO_FACT(DEPT)
NO_FACT(EMP)
ORDERED
PQ_DISTRIBUTE(EMP NONE NONE)
USE_HASH(EMP)
10 rows selected.

Another data dictionary view, user_outlines, is actually looking at outln.ol$. This view is updated when you create a stored outline. Notice that the outline has not been used.

 

SQL> SELECT NAME,
 
2          CATEGORY,
 
3          USED
 
4*  FROM   USER_OUTLINES;
 

NAME         CATEGORY     USED
------------ ------------ ---------
EMPLOYEES    SALARY       UNUSED

 

One method of insuring that Oracle uses the cost-based optimizer is to analyze one or more tables used in a query. The following two statements analyze the EMP and DEPT tables.

 

SQL> ANALYZE TABLE EMP COMPUTE STATISTICS;

Table analyzed.

 

SQL> ANALYZE TABLE DEPT COMPUTE STATISTICS;

Table analyzed.

 

If query_rewrite_enabledis not set to true, Oracle will not use a stored outline or materialized view.

 

SQL> ALTER SESSION SET QUERY_REWRITE_ENABLED = TRUE;

Session altered.

 

To cause the cost-based optimizer to rewrite your query and use the stored outline for CATEGORY SALARY, enter the following command.

 

SQL> ALTER SESSION SET

     USE_STORED_OUT LINES = SALARY;

Session altered.

 

Now, the moment of truth we have all been waiting for. Write the query stored in the outline EMPLOYEES category SALARY, and query the data dictionary to see if Oracle used your outline to execute the query. Because the used column shows "USED," Oracle did use your stored outline.

 

SQL> SELECT ENAME, SAL, LOC
 2   FROM   EMP,   DEPT
 3*  WHERE  EMP.DEPTNO = DEPT.DEPTNO;
...... Output Omitted Here ...
SQL> SELECT NAME,
 2   CATEGORY,
 3   USED
 4*  FROM USER_OUTLINES;
 
NAME       CATEGORY  USED
---------  --------  -----
EMPLOYEES  SALARY    USED

 

To see the EXPLAIN PLAN output for this query, use AUTOTRACE. Notice that Oracle uses a HASH JOINand a full table scan on each of the two tables, which are hints in user_outline_hints.

SQL> SET AUTOTRACE TRACEONLY EXPLAIN
SQL> SELECT ENAME, SAL, LOC
 
2   FROM   EMP,   DEPT

 
3*  WHERE  EMP.DEPTNO = DEPT.DEPTNO;
Execution Plan
-----------------------------------------
0   SELECT STATEMENT Optimizer=CHOOSE
      
(Cost=3 Card=14 Bytes=266)
1 0 HASH JOIN (Cost=3 Card=14 Bytes=266)
2 1   TABLE ACCESS (FULL) OF 'DEPT'

      
(Cost=1 Card=4 Bytes=36)
3 1 TABLE ACCESS (FULL) OF 'EMP'
      
(Cost=1 Card=14 Bytes=140)

 

Stored Outlines

Stored outlinescan be very useful, especially when the SQL can't be changed (packaged applications).

 

In order to use them, you need to capture the SQL statement, and then create an outline with exactly the same SQL statement that uses an alternative access path (perhaps via a hint).

 

Initially, set up security to create the outlines:

 

connect 'sys/xxx as sysdba'

grant create any outline to scott;

grant execute on dbms_outln to scott;

grant execute on dbms_outln_edit to scott;

grant select on dba_outlines to scott;

 

To begin with, set up the session to allow stored outlines, or to ensure that the init.ora parameter create_stored_outlinesis set accordingly.

 

connect scott/tiger

alter session set create_stored_outlines =  TRUE

 

create or replace outline first_outline

on select a.emp_id, a.name, b.dependent_id, b.name

from emp a,

dependent b

where a.empid_id = b.emp_id

 

Now a public outline has been created, but in order to test it, make a private outline (personal copy).  In order to do this, you need to create the tables to hold the private outline first:

 

execute dbms_outln_edit.create_edit_tables;

create private outline first_private_outline from first_outline;

 

--- check out what is in the outline table by default,

--- just from creating the private outline

select * from ol$hints

where ol_name = 'first_private_outline';

 

--- change which ever access path we are interested in

--- for example, could change a nested_lop join to

--- a hash join

 

update ol$hints set hint_text='USE_HASH(B)'

where hint#=5;

commit;

 

--- check the result, and be sure the update worked

select * from ol$hints

where ol_name = 'first_private_outline';

 

--- resync the outline

 

execute dbms_outline_edit.refresh_private_outline ('first_private_outline')

 

--- test it out

alter session set use_private_outlines=true;

 

set autotrace on explain

select a.emp_id, a.name, b.dependent_id, b.name

from emp a,

dependent b

where a.empid_id = b.emp_id

;

 

--- if new access plan is correct, make the outline public

--- for use by everyone

 

create or replace second_outline from private first_private_outline;

 

Now, whenever the original SQL is executed, it will use the revised access plan instead of the original (assuming the init.ora parameter use_stored_outlinesis set to true).

 

Note that the SQL used to create the stored outline and the SQL that is run after the outline is created, must be IDENTICAL, or it won't use the outline.  Identical means the text must be in the same case, same amount of white space, etc.  Oracle 9i and 10g are more forgiving on this requirement than Oracle 8i.

 

The catalog tables dba_outlinesand dba_outline_hintscontain relevant information about the outlines.  They are based on catalog tables OUTLN.OL$ and OUTLN.OL$HINTS.

 

Stored Outlines have been greatly enhanced with the new Oracle 10g features of SQL Profiles.

 

Swapping stored Outlines

MOSC note 92202 .1 describes a procedure to tune SQL that you cannot touch by performing these steps:

  1. Identify the sub-optimal SQL and create a stored outline

  2. Tune an equivalent query with a faster execution plan and create a stored outline

  3. Swap the bad stored outline for the tuned stored outline

Oracle provides this example for swapping the outlines:

UPDATE
OUTLN.OL$HINTS
SET
OL_NAME=DECODE
(OL_NAME,'HINTSQL','ORIGINALSQL','ORIGINALSQL','HINTSQL')
WHERE
OL_NAME IN ('HINTSQL','ORIGINALSQL');
Commit;

   
Oracle Training from Don Burleson 

The best on site "Oracle training classes" are just a phone call away! You can get personalized Oracle training by Donald Burleson, right at your shop!

Oracle training
 
 

 


 

 

��  
 
 
Oracle Training at Sea
 
 
 
 
oracle dba poster
 

 
Follow us on Twitter 
 
Oracle performance tuning software 
 
Oracle Linux poster
 
 
 

 

Burleson is the American Team

Note: This Oracle documentation was created as a support and Oracle training reference for use by our DBA performance tuning consulting professionals.  Feel free to ask questions on our Oracle forum.

Verify experience! Anyone considering using the services of an Oracle support expert should independently investigate their credentials and experience, and not rely on advertisements and self-proclaimed expertise. All legitimate Oracle experts publish their Oracle qualifications.

Errata?  Oracle technology is changing and we strive to update our BC Oracle support information.  If you find an error or have a suggestion for improving our content, we would appreciate your feedback.  Just  e-mail:  

and include the URL for the page.


                    









Burleson Consulting

The Oracle of Database Support

Oracle Performance Tuning

Remote DBA Services


 

Copyright © 1996 -  2020

All rights reserved by Burleson

Oracle ® is the registered trademark of Oracle Corporation.