Ask Tom - Using Stored Outlines.pdf

download Ask Tom - Using Stored Outlines.pdf

of 21

Transcript of Ask Tom - Using Stored Outlines.pdf

  • 8/14/2019 Ask Tom - Using Stored Outlines.pdf

    1/21

    Submitted on 28-Sep-2007 23:08 Central time zone Tom's latest followup | Bookmark | Bottom

    Questions Resources Archives Links Popular Hot Files

    Home > Question Details

    Sreenivas -- Thanks for the question regarding "Using Stored Outlines", version 9.2.0.3

    Last updated 9-Aug-2010 14:02

    You Asked

    Dear Tom,I need some help in implementing/understanding stored outlines..As per the articles provided from oracle,i understand that outlines will help instablizing the exectuion plan across environments(test and production).Here are the steps that i have done and i need some clarification.Pl help me.

    Here are the details of our database

    Version 9.2.0.3Optimizer mode=all_rows

    select /*+ INDEX(t1 pk_tbl_data_collections)*/

    t1.DATA_COLLECTION_ID,t2.object_id,t1.collection_idfrom tbl_data_collections t1,tbl_object_data t2,tbl_service_data t3where t1.DATA_COLLECTION_ID = t2.data_collection_idand t1.OLD_COLLECTION_ID = t3.data_collection_idand t1.collection_id = :1and t1.active = :2and t1.service_id = :3

    for example , we have sql from the code where the binded varibales are the parameters been passed to SQL.I have observed that the cost ofexplain plan for the above SQL is high and the reason is becuase of the hint applied on the query.And the same SQL without the hint give me a much faster response time than earlier and the cost is very low.I have the statistics upto date on the tables but the only differnece is the hint.

    Now the problem is i have no control on the source code and so i thought the only way we can implement is through stored outlines.

    I have followed these steps in creating the stored outlines.

    alter session set create_stored_outlines=true;create or replace outlineonselect t1.DATA_COLLECTION_ID,t2.object_id,t1.collection_idfrom tbl_data_collections t1,tbl_object_data t2,tbl_service_data t3where t1.DATA_COLLECTION_ID = t2.data_collection_idand t1.OLD_COLLECTION_ID = t3.data_collection_idand t1.collection_id = :1and t1.active = :2and t1.service_id = :3;alter session set use_stored_outlines=true;

    When i queried view user_outlines i notice that the outline is created but not used.Why is that?Is there any wrong in the way i was creating the outline.

    I know that the SQL comming from code is not similar to the SQL that the outline is created on.Is that a problem? because i needed the querynot to use the hint.I cannot modify the source code?

    Please and Please help me out Tom.

    Sorry for any typos

    ThanksSreenivas

    and we said...

    because the query you saved the outline for differs from the query you are actually executing.

    You would need to

  • 8/14/2019 Ask Tom - Using Stored Outlines.pdf

    2/21

    a) capture the query exactly as it is executed by the application, hints and allb) get it to have the plan you want in some session by some method (eg: setting session parameters, invalidating the index referenced)c) capturing that plan and using it.

    Or, you could just rename the index, making the hint reference something that doesn't exist, so it would be ignored. Beware however that itwould be sort of "global", my experience is if the developers hinted once - they hinted a thousand times (because they didn't really understandwhat they were doing...) and renaming the index would cause thousands of hints to stop being meaningful.

    Reviews

  • 8/14/2019 Ask Tom - Using Stored Outlines.pdf

    3/21

    Am I missing something ? April 14, 2010 - 11am Central time zone Bookmark | Bottom | Top

    Reviewer: Nicosafrom Paris, France

    Hi Tom,

    I'm trying to implement outlines on a 10gR2 (10.2.0.4) on Linux, using what you provided in previous followup :

    a) capture the query exactly as it is executed by the application, hints and all

    b) get it to have the plan you want in some session by some method (eg: setting session parameters, inval idating the index referenced)

    c) capturing that plan and using it.

    This is how I do it :

    create table T(c1 integer,c2 integer,c3 integer,c4 integer,c5 integer,c6 integer,c7 integer,c8 date,val1 varchar2(30));

    alter table T add constraint T_pk primary key (c1, c2, c3, c4, c5, c6, c7, c8);

    create index T_idx on T(c6, c7);

    insert into Tselectmod(n,97),mod(n,89),mod(n,83),mod(n,79),mod(n,73),mod(n,67),mod(n,61),sysdate+(n/(24*3600)),rpad('a',30,'a'),rpad('a',30,'a'),rpad('a',30,'a'),rpad('a',30,'a'),rpad('a',30,'a'),rpad('a',30,'a')from (select level n from dual connect by level user,tabname => 'T',method_opt => 'for all columns size 1',estimate_percent => null,cascade => true);end;/

    The query I want to outline is :

    selectc1, c2, c3, c4, c5, c6, c7, c8, val1from Twhere c1=19and c2=54and c3=28and c4=41and c5=16and c6=51and c7=18and c8=(sysdate + 1.2345)for update nowait;

    I put it in a file called q.sql so I'm sure it's always the same (syntax wise)

    I want it (for test purpose only) to range_scan T_idx instead of unique scan t_pk.

    So I tried to make the index unusable before generating outline, then rebuild it and check weither outline is used or not :

    SQL> alter index t_pk unusable;

    Index altered.

    SQL> create outline myol

  • 8/14/2019 Ask Tom - Using Stored Outlines.pdf

    4/21

    2 for category myol 3 on 4 @q

    Outline created.

    SQL> alter index t_pk rebuild;

    Index altered.

    SQL> set autotrace traceonly explainSQL> alter session set use_stored_outlines=myol;

    Session altered.

    SQL> @q

    Execution Plan----------------------------------------------------------Plan hash value: 2503694904

    -------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |-------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 1 | 214 | 3 (0)| 00:00:01 || 1 | FOR UPDATE | | | | | || 2 | TABLE ACCESS BY INDEX ROWID| T | 1 | 214 | 3 (0)| 00:00:01 ||* 3 | INDEX UNIQUE SCAN | T_PK | 1 | | 2 (0)| 00:00:01 |-------------------------------------------------------------------------------------

    Predicate Information (identified by operation id):---------------------------------------------------

    3 - access("C1"=19 AND "C2"=54 AND "C3"=28 AND "C4"=41 AND "C5"=16 AND "C6"=51 AND "C7"=18 AND "C8"=SYSDATE@!+1.234502314814814814814814814814814814 81)

    Note----- - outline "MYOL" used for this statement

    I'm quite lost.... autotrace says the outline myol is used, but I see the t_pk index being used.One of those must be lying to me, or I missed something.

    Here is the content of user_outline_hints for myol outline :SQL> select * from user_outline_hints where name='MYOL';

    NAME NODE STAGE JOIN_POS HINT----- ----- ------ --------- -------------------------------------------------------MYOL 1 1 1 INDEX_RS_ASC(@"SEL$1" "T"@"SEL$1" ("T"."C6" "T"."C7"))MYOL 1 1 0 OUTLINE_LEAF(@"SEL$1")MYOL 1 1 0 ALL_ROWSMYOL 1 1 0 OPTIMIZER_FEATURES_ENABLE('10.2.0.4')MYOL 1 1 0 IGNORE_OPTIM_EMBEDDED_HINTS

    5 rows selected.

    Can you help ?

    Followup April 14, 2010 - 4pm Central time zone:

    your example does not work, I cannot reproduce as it will not use t_pk for me.

    Your insert fails

    ops$tkyte%ORA10GR2> insert into T 2 select 3 mod(n,97), 4 mod(n,89), 5 mod(n,83), 6 mod(n,79), 7 mod(n,73), 8 mod(n,67),

    9 mod(n,61),10 sysdate+(n/(24*3600)),11 rpad('a',30,'a'),12 rpad('a',30,'a'),13 rpad('a',30,'a'),14 rpad('a',30,'a'),15 rpad('a',30,'a'),

  • 8/14/2019 Ask Tom - Using Stored Outlines.pdf

    5/21

    I feel stupid... April 15, 2010 - 4am Central time zone Bookmark | Bottom | Top

    16 rpad('a',30,'a')17 from (18 select level n from dual connect by level createTable.sql :

    create table T(c1 integer,

    c2 integer,c3 integer,c4 integer,c5 integer,c6 integer,c7 integer,c8 date,val1 varchar2(30),val2 varchar2(30),val3 varchar2(30),val4 varchar2(30),val5 varchar2(30),val6 varchar2(30));

    alter table T add constraint T_pk primary key (c1, c2, c3, c4, c5, c6, c7, c8);

    create index T_idx on T(c6, c7);

    insert into Tselectmod(n,97),mod(n,89),mod(n,83),mod(n,79),mod(n,73),mod(n,67),mod(n,61),sysdate+(n/(24*3600)),rpad('a',30,'a'),rpad('a',30,'a'),rpad('a',30,'a'),rpad('a',30,'a'),rpad('a',30,'a'),rpad('a',30,'a')

    from (select level n from dual connect by level user,tabname => 'T',method_opt => 'for all columns size 1',estimate_percent => null,cascade => true);end;/

    -> q.sql (the query) :

    selectc1, c2, c3, c4, c5, c6, c7, c8, val1, val2, val3, val4, val5, val6from Twhere c1=19and c2=54and c3=28

  • 8/14/2019 Ask Tom - Using Stored Outlines.pdf

    6/21

    and c4=41and c5=16and c6=51and c7=18and c8=(sysdate + 1.2345)for update nowait;

    -> the "main" example file :

    set lines 100set tab offset echo on

    set feed onset long 30000

    @createTable.sql

    alter index t_pk unusable;

    create outline myol for category myol [email protected]

    alter index t_pk rebuild;

    alter session set use_stored_outlines=myol;

    set autotrace traceonly explain

    @q.sql

    set autotrace off

    col name for A4col hint for A55col node for 99999col stage for 99999select * from user_outline_hints where name='MYOL';

    Now the run :

    The output of sqlplus scott/tiger @fullExample.sqlis as follow :

    SQL*Plus: Release 10.2.0.4.0 - Production on Thu Apr 15 10:57:00 2010

    Copyright (c) 1982, 2007, Oracle. All Rights Reserved.

    Connected to:Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options

    Session altered.

    SQL> set feed onSQL> set long 30000SQL>SQL> @createTable.sqlSQL> create table T 2 ( 3 c1 integer, 4 c2 integer, 5 c3 integer,

    6 c4 integer, 7 c5 integer, 8 c6 integer, 9 c7 integer,10 c8 date,11 val1 varchar2(30),12 val2 varchar2(30),13 val3 varchar2(30),14 val4 varchar2(30),15 val5 varchar2(30),16 val6 varchar2(30)17 );

    Table created.

    SQL>SQL> alter table T add constraint T_pk primary key (c1, c2, c3, c4, c5, c6, c7, c8);

    Table altered.

    SQL>SQL> create index T_idx on T(c6, c7);

    Index created.

  • 8/14/2019 Ask Tom - Using Stored Outlines.pdf

    7/21

    SQL>SQL> insert into T 2 select 3 mod(n,97), 4 mod(n,89), 5 mod(n,83), 6 mod(n,79), 7 mod(n,73), 8 mod(n,67), 9 mod(n,61),10 sysdate+(n/(24*3600)),

    11 rpad('a',30,'a'),12 rpad('a',30,'a'),13 rpad('a',30,'a'),14 rpad('a',30,'a'),15 rpad('a',30,'a'),16 rpad('a',30,'a')17 from (18 select level n from dual connect by level commit;

    Commit complete.

    SQL>SQL> begin 2 dbms_stats.gather_table_stats( 3 ownname => user, 4 tabname => 'T', 5 method_opt => 'for all columns size 1', 6 estimate_percent => null, 7 cascade => true); 8 end; 9 /

    PL/SQL procedure successfully completed.

    SQL>SQL>SQL> alter index t_pk unusable;

    Index altered.

    SQL>SQL> create outline myol for category myol on 2 @q.sql 2 select 3 c1, c2, c3, c4, c5, c6, c7, c8 4 , val1, val2, val3, val4, val5, val6 5 from T 6 where c1=19 7 and c2=54 8 and c3=28 9 and c4=4110 and c5=1611 and c6=5112 and c7=1813 and c8=(sysdate + 1.2345)14 for update nowait;

    Outline created.

    SQL>SQL> alter index t_pk rebuild;

    Index altered.

    SQL>SQL> alter session set use_stored_outlines=myol;

    Session altered.

    SQL>SQL> set autotrace traceonly explainSQL>SQL> @q.sqlSQL> select

    2 c1, c2, c3, c4, c5, c6, c7, c8 3 , val1, val2, val3, val4, val5, val6 4 from T 5 where c1=19 6 and c2=54 7 and c3=28 8 and c4=41

  • 8/14/2019 Ask Tom - Using Stored Outlines.pdf

    8/21

    9 and c5=1610 and c6=5111 and c7=1812 and c8=(sysdate + 1.2345)13 for update nowait;

    Execution Plan----------------------------------------------------------Plan hash value: 2503694904

    -------------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |

    -------------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 1 | 214 | 2 (0)| 00:00:01 || 1 | FOR UPDATE | | | | | || 2 | TABLE ACCESS BY INDEX ROWID| T | 1 | 214 | 2 (0)| 00:00:01 ||* 3 | INDEX UNIQUE SCAN | T_PK | 1 | | 1 (0)| 00:00:01 |-------------------------------------------------------------------------------------

    Predicate Information (identified by operation id):---------------------------------------------------

    3 - access("C1"=19 AND "C2"=54 AND "C3"=28 AND "C4"=41 AND "C5"=16 AND "C6"=51 AND "C7"=18 AND "C8"=SYSDATE@!+1.234502314814814814814814814814814814 81)

    Note----- - outline "MYOL" used for this statement

    SQL>SQL> set autotrace offSQL>SQL> col name for A4SQL> col hint for A55SQL> col node for 99999SQL> col stage for 99999SQL> select * from user_outline_hints where name='MYOL';

    NAME NODE STAGE JOIN_POS HINT---- ------ ------ ---------- -------------------------------------------------------MYOL 1 1 1 INDEX_RS_ASC(@"SEL$1" "T"@"SEL$1" ("T"."C6" "T"."C7"))MYOL 1 1 0 OUTLINE_LEAF(@"SEL$1")MYOL 1 1 0 ALL_ROWSMYOL 1 1 0 OPTIMIZER_FEATURES_ENABLE('10.2.0.4')MYOL 1 1 0 IGNORE_OPTIM_EMBEDDED_HINTS

    5 rows selected.

    Still the same problem :- Autotrace says myol outline is used- but I see it using T_PK where I wanted it to use T_IDX

    I must be missing something...

    Followup April 15, 2010 - 8am Central time zone:

    I'm having troubles reproducing.

    anything 'different' about you? non-standard init.ora settings?

    ops$tkyte%ORA10GR2> set echo onops$tkyte%ORA10GR2> set linesize 10000ops$tkyte%ORA10GR2> drop table t purge;

    Table dropped.

    ops$tkyte%ORA10GR2> drop outline myol;

    Outline dropped.

    ops$tkyte%ORA10GR2>ops$tkyte%ORA10GR2> column PLAN_TABLE_OUTPUT format a80 truncateops$tkyte%ORA10GR2>ops$tkyte%ORA10GR2> create table T

    2 ( 3 c1 integer, 4 c2 integer, 5 c3 integer, 6 c4 integer, 7 c5 integer, 8 c6 integer,

  • 8/14/2019 Ask Tom - Using Stored Outlines.pdf

    9/21

    9 c7 integer,10 c8 date,11 val1 varchar2(30),12 val2 varchar2(30),13 val3 varchar2(30),14 val4 varchar2(30),15 val5 varchar2(30),16 val6 varchar2(30)17 );

    Table created.

    ops$tkyte%ORA10GR2>ops$tkyte%ORA10GR2> alter table T add constraint T_pk primary key (c1, c2, c3, c4, c5, c6, c7, c8);

    Table altered.

    ops$tkyte%ORA10GR2>ops$tkyte%ORA10GR2> create index T_idx on T(c6, c7);

    Index created.

    ops$tkyte%ORA10GR2>ops$tkyte%ORA10GR2> insert into T 2 select 3 mod(n,97), 4 mod(n,89), 5 mod(n,83), 6 mod(n,79), 7 mod(n,73), 8 mod(n,67), 9 mod(n,61),10 sysdate+(n/(24*3600)),11 rpad('a',30,'a'),12 rpad('a',30,'a'),13 rpad('a',30,'a'),14 rpad('a',30,'a'),15 rpad('a',30,'a'),16 rpad('a',30,'a')17 from (18 select level n from dual connect by level commit;

    Commit complete.

    ops$tkyte%ORA10GR2>ops$tkyte%ORA10GR2> begin 2 dbms_stats.gather_table_stats( 3 ownname => user, 4 tabname => 'T', 5 method_opt => 'for all columns size 1', 6 estimate_percent => null, 7 cascade => true); 8 end; 9 /

    PL/SQL procedure successfully completed.

    ops$tkyte%ORA10GR2>ops$tkyte%ORA10GR2> @q.sql

    ops$tkyte%ORA10GR2> select 2 c1, c2, c3, c4, c5, c6, c7, c8 3 , val1, val2, val3, val4, val5, val6 4 from T 5 where c1=19 6 and c2=54 7 and c3=28 8 and c4=41 9 and c5=1610 and c6=5111 and c7=1812 and c8=(sysdate + 1.2345)13 for update nowait;

    no rows selected

    ops$tkyte%ORA10GR2> select * from table(dbms_xplan.display_cursor);

    PLAN_TABLE_OUTPUT--------------------------------------------------------------------------------SQL_ID 0hp10pkdk56ky, child number 0-------------------------------------select c1, c2, c3, c4, c5, c6, c7, c8 , val1, val2, val3, val4, val5, val6from T where c1=19 and c2=54 and c3=28 and c4=41 and c5=16 and c6=51 and

  • 8/14/2019 Ask Tom - Using Stored Outlines.pdf

    10/21

    c7=18 and c8=(sysdate + 1.2345) for update nowait

    Plan hash value: 2503694904

    --------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time--------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | | | 2 (100)|| 1 | FOR UPDATE | | | | || 2 | TABLE ACCESS BY INDEX ROWID| T | 1 | 214 | 2 (0)| 00:00|* 3 | INDEX UNIQUE SCAN | T_PK | 1 | | 1 (0)| 00:00--------------------------------------------------------------------------------

    Predicate Information (identified by operation id):---------------------------------------------------

    3 - access("C1"=19 AND "C2"=54 AND "C3"=28 AND "C4"=41 AND "C5"=16 AND "C6"=51 AND "C7"=18 AND "C8"=SYSDATE@!+1.2345023148148148148148148 81)

    24 rows selected.

    ops$tkyte%ORA10GR2> alter index t_pk unusable;

    Index altered.

    ops$tkyte%ORA10GR2> @q.sqlops$tkyte%ORA10GR2> select 2 c1, c2, c3, c4, c5, c6, c7, c8 3 , val1, val2, val3, val4, val5, val6 4 from T 5 where c1=19 6 and c2=54 7 and c3=28 8 and c4=41 9 and c5=1610 and c6=5111 and c7=1812 and c8=(sysdate + 1.2345)13 for update nowait;

    no rows selected

    ops$tkyte%ORA10GR2> select * from table(dbms_xplan.display_cursor);

    PLAN_TABLE_OUTPUT

    --------------------------------------------------------------------------------SQL_ID 0hp10pkdk56ky, child number 0-------------------------------------select c1, c2, c3, c4, c5, c6, c7, c8 , val1, val2, val3, val4, val5, val6from T where c1=19 and c2=54 and c3=28 and c4=41 and c5=16 and c6=51 andc7=18 and c8=(sysdate + 1.2345) for update nowait

    Plan hash value: 882521605

    --------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time--------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | | | 2 (100)|| 1 | FOR UPDATE | | | | ||* 2 | TABLE ACCESS BY INDEX ROWID| T | 1 | 214 | 2 (0)| 00:0|* 3 | INDEX RANGE SCAN | T_IDX | 1 | | 1 (0)| 00:0--------------------------------------------------------------------------------

    Predicate Information (identified by operation id):---------------------------------------------------

    2 - filter(("C1"=19 AND "C2"=54 AND "C3"=28 AND "C4"=41 AND "C5"=16 AND "C8"=SYSDATE@!+1.23450231481481481481481481481481481481)) 3 - access("C6"=51 AND "C7"=18)

    24 rows selected.

    ops$tkyte%ORA10GR2>ops$tkyte%ORA10GR2> create outline myol for category myol on 2 @q.sql 2 select 3 c1, c2, c3, c4, c5, c6, c7, c8 4 , val1, val2, val3, val4, val5, val6

    5 from T 6 where c1=19 7 and c2=54 8 and c3=28 9 and c4=4110 and c5=1611 and c6=51

  • 8/14/2019 Ask Tom - Using Stored Outlines.pdf

    11/21

    12 and c7=1813 and c8=(sysdate + 1.2345)14 for update nowait;

    Outline created.

    ops$tkyte%ORA10GR2>ops$tkyte%ORA10GR2> alter index t_pk rebuild;

    Index altered.

    ops$tkyte%ORA10GR2>

    ops$tkyte%ORA10GR2> alter session set use_stored_outlines=myol;

    Session altered.

    ops$tkyte%ORA10GR2> set serveroutput offops$tkyte%ORA10GR2> @q.sqlops$tkyte%ORA10GR2> select 2 c1, c2, c3, c4, c5, c6, c7, c8 3 , val1, val2, val3, val4, val5, val6 4 from T 5 where c1=19 6 and c2=54 7 and c3=28 8 and c4=41 9 and c5=1610 and c6=5111 and c7=1812 and c8=(sysdate + 1.2345)13 for update nowait;

    no rows selected

    ops$tkyte%ORA10GR2> select * from table(dbms_xplan.display_cursor);

    PLAN_TABLE_OUTPUT--------------------------------------------------------------------------------SQL_ID 0hp10pkdk56ky, child number 0-------------------------------------select c1, c2, c3, c4, c5, c6, c7, c8 , val1, val2, val3, val4, val5, val6from T where c1=19 and c2=54 and c3=28 and c4=41 and c5=16 and c6=51 andc7=18 and c8=(sysdate + 1.2345) for update nowait

    Plan hash value: 882521605

    --------------------------------------------------------------------------------

    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time--------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | | | 2 (100)|| 1 | FOR UPDATE | | | | ||* 2 | TABLE ACCESS BY INDEX ROWID| T | 1 | 214 | 2 (0)| 00:0|* 3 | INDEX RANGE SCAN | T_IDX | 1 | | 1 (0)| 00:0--------------------------------------------------------------------------------

    Predicate Information (identified by operation id):---------------------------------------------------

    2 - filter(("C1"=19 AND "C2"=54 AND "C3"=28 AND "C4"=41 AND "C5"=16 AND "C8"=SYSDATE@!+1.23450231481481481481481481481481481481)) 3 - access("C6"=51 AND "C7"=18)

    Note-----

    - outline "MYOL" used for this statement

    28 rows selected.

    ops$tkyte%ORA10GR2> set autotrace traceonly explainops$tkyte%ORA10GR2> @q.sqlops$tkyte%ORA10GR2> select 2 c1, c2, c3, c4, c5, c6, c7, c8 3 , val1, val2, val3, val4, val5, val6 4 from T 5 where c1=19 6 and c2=54 7 and c3=28 8 and c4=41 9 and c5=1610 and c6=51

    11 and c7=1812 and c8=(sysdate + 1.2345)13 for update nowait;

    Execution Plan----------------------------------------------------------Plan hash value: 882521605

  • 8/14/2019 Ask Tom - Using Stored Outlines.pdf

    12/21

    This my sandbox db... April 15, 2010 - 9am Central time zone Bookmark | Bottom | Top

    --------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time--------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 1 | 214 | 2 (0)| 00:0| 1 | FOR UPDATE | | | | ||* 2 | TABLE ACCESS BY INDEX ROWID| T | 1 | 214 | 2 (0)| 00:0|* 3 | INDEX RANGE SCAN | T_IDX | 1 | | 1 (0)| 00:0--------------------------------------------------------------------------------

    Predicate Information (identified by operation id):---------------------------------------------------

    2 - filter("C1"=19 AND "C2"=54 AND "C3"=28 AND "C4"=41 AND "C5"=16 AND "C8"=SYSDATE@!+1.23450231481481481481481481481481481481) 3 - access("C6"=51 AND "C7"=18)

    Note----- - outline "MYOL" used for this statement

    ops$tkyte%ORA10GR2> set autotrace offops$tkyte%ORA10GR2> select * from v$version;

    BANNER----------------------------------------------------------------Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - ProdPL/SQL Release 10.2.0.4.0 - ProductionCORE 10.2.0.4.0 ProductionTNS for Linux: Version 10.2.0.4.0 - ProductionNLSRTL Version 10.2.0.4.0 - Production

    Reviewer: Nicosafrom Paris, France

    Tom,

    the test is done on my "sandbox" db (I use to test lots of things on it, so init parameters might be anything... but I don't remember doingsomething spcially strange).

    Would the following query show it ?

    SQL> select name, value from v$parameter where isdefault!='TRUE';

    NAME VALUE------------------------------ ------------------------------------------------------------processes 50sessions 60nls_language FRENCHnls_territory FRANCEnls_date_format yyyy/mm/dd hh24:mi:sssga_target 209715200control_files /oracleDatas/MY10G/controlfile/o1_mf_58tpcw32_.ctl, /oracleD atas/MY10G/controlfile/o1_mf_58tpcwc5_.ctl

    db_block_size 8192compatible 10.2.0.3.0log_archive_dest /oracleDatas/MY10G/archivelog/db_file_multiblock_read_count 16db_create_file_dest /oracleDatas

    db_recovery_file_dest_size 1073741824undo_management AUTOundo_tablespace UNDOTBS1remote_login_passwordfile EXCLUSIVEdb_domaindispatchers (PROTOCOL=TCP) (SERVICE=my10gXDB)job_queue_processes 10background_dump_dest /oracleSofts/product/10g/admin/my10g/bdumpuser_dump_dest /oracleSofts/product/10g/admin/my10g/udumpmax_dump_file_size 1024000core_dump_dest /oracleSofts/product/10g/admin/my10g/cdumpaudit_file_dest /oracleSofts/product/10g/admin/my10g/adumpdb_name my10gopen_cursors 300pga_aggregate_target 52428800

    27 rows selected.

    I also tried to change star_transformation_enabled to true (but didn't bounce the DB since as it is supposed to besys_modifiable=immediate) but with no effect.

  • 8/14/2019 Ask Tom - Using Stored Outlines.pdf

    13/21

    Followup April 15, 2010 - 10am Central time zone:

    nothing strange there

    suggestion: trying flushing shared pool and or reconnecting after the outline is created, before alter session is issued.

    and use this script:

    set echo onset linesize 10000drop table t purge;drop outline myol;

    column PLAN_TABLE_OUTPUT format a80 truncate

    create table T(c1 integer,c2 integer,c3 integer,c4 integer,c5 integer,c6 integer,c7 integer,c8 date,val1 varchar2(30),

    val2 varchar2(30),val3 varchar2(30),val4 varchar2(30),val5 varchar2(30),val6 varchar2(30));

    alter table T add constraint T_pk primary key (c1, c2, c3, c4, c5, c6, c7, c8);

    create index T_idx on T(c6, c7);

    insert into Tselectmod(n,97),mod(n,89),mod(n,83),mod(n,79),

    mod(n,73),mod(n,67),mod(n,61),sysdate+(n/(24*3600)),rpad('a',30,'a'),rpad('a',30,'a'),rpad('a',30,'a'),rpad('a',30,'a'),rpad('a',30,'a'),rpad('a',30,'a')from (select level n from dual connect by level user,tabname => 'T',method_opt => 'for all columns size 1',estimate_percent => null,cascade => true);end;/

    @q.sqlselect * from table(dbms_xplan.display_cursor);alter index t_pk unusable;@q.sqlselect * from table(dbms_xplan.display_cursor);

    create outline myol for category myol [email protected]

    alter index t_pk rebuild;

    connect /alter system flush shared_pool;

  • 8/14/2019 Ask Tom - Using Stored Outlines.pdf

    14/21

    Doesn't compute... (^_^) April 15, 2010 - 12pm Central time zone Bookmark | Bottom | Top

    alter session set use_stored_outlines=myol;set serveroutput [email protected] * from table(dbms_xplan.display_cursor);set autotrace traceonly [email protected] autotrace off

    Reviewer: Nicosafrom Paris, France

    Tom,

    Thanks for your time !This part doesn't compute on my machine :

    SQL> connect /ERROR:ORA-01017: invalid username/password; logon denied

    I allowed myself to modify the end of the script as follows :-added a "set tab off" for nice formatting when pasting on your site-added "as sysdba" and a "conn scott/tiger" after the shared_pool flush.(hope this was what you intended)

    The end of the script now looks like this :

    connect /as sysdbaalter system flush shared_pool;

    conn scott/tiger

    alter session set use_stored_outlines=myol;set serveroutput [email protected] * from table(dbms_xplan.display_cursor);

    set autotrace traceonly [email protected] autotrace off

    I also had to grant 'select any dictionary' to scott to allow dbms_xplan.display_cursor to select from v$session.

    Here's the output :

    SQL*Plus: Release 10.2.0.4.0 - Production on Thu Apr 15 18:55:28 2010

    Copyright (c) 1982, 2007, Oracle. All Rights Reserved.

    Connected to:Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - ProductionWith the Partitioning, OLAP, Data Mining and Real Application Testing options

    SQL> set linesize 10000SQL> drop table t purge;drop table t purge *ERROR at line 1:ORA-00942: table or view does not exist

    SQL> drop outline myol;drop outline myol*ERROR at line 1:ORA-18002: the specified outline does not exist

    SQL>SQL> column PLAN_TABLE_OUTPUT format a80 truncateSQL>SQL> create table T 2 ( 3 c1 integer, 4 c2 integer, 5 c3 integer, 6 c4 integer,

  • 8/14/2019 Ask Tom - Using Stored Outlines.pdf

    15/21

    7 c5 integer, 8 c6 integer, 9 c7 integer,10 c8 date,11 val1 varchar2(30),12 val2 varchar2(30),13 val3 varchar2(30),14 val4 varchar2(30),15 val5 varchar2(30),16 val6 varchar2(30)17 );

    Table created.

    SQL>SQL> alter table T add constraint T_pk primary key (c1, c2, c3, c4, c5, c6, c7, c8);

    Table altered.

    SQL>SQL> create index T_idx on T(c6, c7);

    Index created.

    SQL>SQL> insert into T 2 select 3 mod(n,97), 4 mod(n,89), 5 mod(n,83), 6 mod(n,79), 7 mod(n,73), 8 mod(n,67), 9 mod(n,61),10 sysdate+(n/(24*3600)),11 rpad('a',30,'a'),12 rpad('a',30,'a'),13 rpad('a',30,'a'),14 rpad('a',30,'a'),15 rpad('a',30,'a'),16 rpad('a',30,'a')17 from (18 select level n from dual connect by level commit;

    Commit complete.

    SQL>SQL> begin 2 dbms_stats.gather_table_stats( 3 ownname => user, 4 tabname => 'T', 5 method_opt => 'for all columns size 1', 6 estimate_percent => null, 7 cascade => true); 8 end; 9 /

    PL/SQL procedure successfully completed.

    SQL>SQL> @q.sqlSQL> select 2 c1, c2, c3, c4, c5, c6, c7, c8 3 , val1, val2, val3, val4, val5, val6 4 from T 5 where c1=19 6 and c2=54 7 and c3=28 8 and c4=41 9 and c5=1610 and c6=5111 and c7=1812 and c8=(sysdate + 1.2345)13 for update nowait;

    no rows selected

    SQL> select * from table(dbms_xplan.display_cursor);

    PLAN_TABLE_OUTPUT--------------------------------------------------------------------------------SQL_ID 0hp10pkdk56ky, child number 0-------------------------------------

  • 8/14/2019 Ask Tom - Using Stored Outlines.pdf

    16/21

    select c1, c2, c3, c4, c5, c6, c7, c8 , val1, val2, val3, val4, val5, val6from T where c1=19 and c2=54 and c3=28 and c4=41 and c5=16 and c6=51 andc7=18 and c8=(sysdate + 1.2345) for update nowait

    Plan hash value: 2503694904

    --------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time--------------------------------------------------------------------------------

    PLAN_TABLE_OUTPUT--------------------------------------------------------------------------------

    | 0 | SELECT STATEMENT | | | | 2 (100)|| 1 | FOR UPDATE | | | | || 2 | TABLE ACCESS BY INDEX ROWID| T | 1 | 214 | 2 (0)| 00:00|* 3 | INDEX UNIQUE SCAN | T_PK | 1 | | 1 (0)| 00:00--------------------------------------------------------------------------------

    Predicate Information (identified by operation id):---------------------------------------------------

    3 - access("C1"=19 AND "C2"=54 AND "C3"=28 AND "C4"=41 AND "C5"=16 AND "C6"=51 AND "C7"=18 AND "C8"=SYSDATE@!+1.2345023148148148148148148

    PLAN_TABLE_OUTPUT-------------------------------------------------------------------------------- 81)

    24 rows selected.

    SQL> alter index t_pk unusable;

    Index altered.

    SQL> @q.sqlSQL> select 2 c1, c2, c3, c4, c5, c6, c7, c8 3 , val1, val2, val3, val4, val5, val6 4 from T 5 where c1=19 6 and c2=54 7 and c3=28 8 and c4=41 9 and c5=1610 and c6=5111 and c7=18

    12 and c8=(sysdate + 1.2345)13 for update nowait;

    no rows selected

    SQL> select * from table(dbms_xplan.display_cursor);

    PLAN_TABLE_OUTPUT--------------------------------------------------------------------------------SQL_ID 0hp10pkdk56ky, child number 0-------------------------------------select c1, c2, c3, c4, c5, c6, c7, c8 , val1, val2, val3, val4, val5, val6from T where c1=19 and c2=54 and c3=28 and c4=41 and c5=16 and c6=51 andc7=18 and c8=(sysdate + 1.2345) for update nowait

    Plan hash value: 882521605

    --------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time--------------------------------------------------------------------------------

    PLAN_TABLE_OUTPUT--------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | | | 2 (100)|| 1 | FOR UPDATE | | | | ||* 2 | TABLE ACCESS BY INDEX ROWID| T | 1 | 214 | 2 (0)| 00:0|* 3 | INDEX RANGE SCAN | T_IDX | 1 | | 1 (0)| 00:0--------------------------------------------------------------------------------

    Predicate Information (identified by operation id):---------------------------------------------------

    2 - filter(("C1"=19 AND "C2"=54 AND "C3"=28 AND "C4"=41 AND "C5"=16 AND "C8"=SYSDATE@!+1.23450231481481481481481481481481481481))

    PLAN_TABLE_OUTPUT-------------------------------------------------------------------------------- 3 - access("C6"=51 AND "C7"=18)

    24 rows selected.

  • 8/14/2019 Ask Tom - Using Stored Outlines.pdf

    17/21

    SQL>SQL> create outline myol for category myol on 2 @q.sql 2 select 3 c1, c2, c3, c4, c5, c6, c7, c8 4 , val1, val2, val3, val4, val5, val6 5 from T 6 where c1=19 7 and c2=54 8 and c3=28 9 and c4=41

    10 and c5=1611 and c6=5112 and c7=1813 and c8=(sysdate + 1.2345)14 for update nowait;

    Outline created.

    SQL>SQL> alter index t_pk rebuild;

    Index altered.

    SQL>SQL>SQL>SQL>SQL> connect /as sysdbaConnected.SQL> alter system flush shared_pool;

    System altered.

    SQL>SQL> conn scott/tigerConnected.SQL>SQL>SQL> alter session set use_stored_outlines=myol;

    Session altered.

    SQL> set serveroutput offSQL> @q.sqlSQL> select

    2 c1, c2, c3, c4, c5, c6, c7, c8 3 , val1, val2, val3, val4, val5, val6 4 from T 5 where c1=19 6 and c2=54 7 and c3=28 8 and c4=41 9 and c5=1610 and c6=5111 and c7=1812 and c8=(sysdate + 1.2345)13 for update nowait;

    no rows selected

    SQL> select * from table(dbms_xplan.display_cursor);

    PLAN_TABLE_OUTPUT--------------------------------------------------------------------------------SQL_ID 0hp10pkdk56ky, child number 0-------------------------------------select c1, c2, c3, c4, c5, c6, c7, c8 , val1, val2, val3, val4, val5, val6from T where c1=19 and c2=54 and c3=28 and c4=41 and c5=16 and c6=51 andc7=18 and c8=(sysdate + 1.2345) for update nowait

    Plan hash value: 2503694904

    --------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time--------------------------------------------------------------------------------

    PLAN_TABLE_OUTPUT--------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | | | 2 (100)|

    | 1 | FOR UPDATE | | | | || 2 | TABLE ACCESS BY INDEX ROWID| T | 1 | 214 | 2 (0)| 00:00|* 3 | INDEX UNIQUE SCAN | T_PK | 1 | | 1 (0)| 00:00--------------------------------------------------------------------------------

    Predicate Information (identified by operation id):---------------------------------------------------

  • 8/14/2019 Ask Tom - Using Stored Outlines.pdf

    18/21

    How does OUTLINE work for same query with different HASH_VALUE June 15, 2010 - 2am Central time zoneBookmark | Bottom | Top

    3 - access("C1"=19 AND "C2"=54 AND "C3"=28 AND "C4"=41 AND "C5"=16 AND "C6"=51 AND "C7"=18 AND "C8"=SYSDATE@!+1.2345023148148148148148148

    PLAN_TABLE_OUTPUT-------------------------------------------------------------------------------- 81)

    Note----- - outline "MYOL" used for this statement

    28 rows selected.

    SQL> set autotrace traceonly explainSQL> @q.sqlSQL> select 2 c1, c2, c3, c4, c5, c6, c7, c8 3 , val1, val2, val3, val4, val5, val6 4 from T 5 where c1=19 6 and c2=54 7 and c3=28 8 and c4=41 9 and c5=1610 and c6=5111 and c7=1812 and c8=(sysdate + 1.2345)13 for update nowait;

    Execution Plan----------------------------------------------------------Plan hash value: 2503694904

    --------------------------------------------------------------------------------| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time--------------------------------------------------------------------------------| 0 | SELECT STATEMENT | | 1 | 214 | 2 (0)| 00:00| 1 | FOR UPDATE | | | | || 2 | TABLE ACCESS BY INDEX ROWID| T | 1 | 214 | 2 (0)| 00:00|* 3 | INDEX UNIQUE SCAN | T_PK | 1 | | 1 (0)| 00:00--------------------------------------------------------------------------------

    Predicate Information (identified by operation id):---------------------------------------------------

    3 - access("C1"=19 AND "C2"=54 AND "C3"=28 AND "C4"=41 AND "C5"=16 AND "C6"=51 AND "C7"=18 AND "C8"=SYSDATE@!+1.2345023148148148148148148 81)

    Note----- - outline "MYOL" used for this statement

    SQL> set autotrace offSQL>

    Still the strange behavior...

    By the way, i had the opportunity to test it on another database (Linux OS too, same DB version) and it worked...(of course, the test is not exactly the same as it is a true table with true data, and the query was using bind variables)That would make me think the problem is with my "sandbox" db... I must have done something strange to it.If I have time tomorrow, I'll create a brand new DB on the same system to see if this reproduces.

    Followup April 15, 2010 - 12pm Central time zone:

    connect /

    is in fact

    connect user/password

    you wouldn't have my user/password - and actually mine is just blank and blank.

    Reviewer: Sanju

    Oracle Version: 9.2.0.8

    Hi Tom,My application is executing a query which is of HASH_VALUE=568965. I take this query and run the same from SQLPLUS. TheHASH_VALUE changes to 687956. I can understand why this happens.

  • 8/14/2019 Ask Tom - Using Stored Outlines.pdf

    19/21

    Lots of stored outlines July 1, 2010 - 8am Central time zone Bookmark | Bottom | Top

    CREATE_STORED_OUTLINES - Missing in 9iR2. August 9, 2010 - 12pm Central time zoneBookmark | Bottom | Top

    Now when I create the Stored Outline, it says the HASH_VALUE is 687956(The one I executed from SQLPLUS). If I set the system to usethe STORED_OUTLINE and execute the query from the application, I can see that the executed query is of HASH_VALUE 568965(sinceexecuted from application) but the stored outline is still used. How is this possible? As HASH_VALUE from OUTLN.OL$ says that it is on687956. So should not it be executing only when HASH_VALUE is 687956(sqlplus) and not 568965(application).

    Please can you explain this??

    Thank You,Sanju

    Please can you explain?

    Followup June 22, 2010 - 10am Central time zone:

    ... I can understand why this happens. . .

    did you mean "cannot"?

    probably you added whitespace or changed the query just a tiny bit when you ran it in sqlplus - it has to match EXACTLY the query as itexisted in the application - down to the use of spaces, tabs, newlines and all.

    Reviewer: Lisefrom Norway

    Hi,We are upgrading from 9.2 to 11.1 and find that due to having several GROUP BY queries withoutORDER BY (even though we need them to be ordered), will of course not be ordered in our 'new' dbdue to the introduction of HASH GROUP BY algorithm.There are lots of code changes to be made (approx 200 objects) and the testing of course. We willnot meet our deadline.The options are to use the hidden parameter _gby_hash_aggregation_enabled, or get all the storedoutlines from the 9i database, test each one to ensure that they are being used as we expect themto, or change all the code and miss the deadline. Is there any other way, and if not what would yourecommend please?

    Followup July 6, 2010 - 2pm Central time zone:

    ... will ofcourse not be ordered in our 'new' db due to the introduction of HASH GROUP BYalgorithm....

    No, I disagree with you. They will not be ordered because they NEVER HAD TO BE ORDERED and might have sometimes appeared tobe ordered - but they were not.

    In no version of Oracle - ever - did a group by have to sort data. A simple additional index - data would be returned "non sorted". Introducepartitions - not sorted. Gather statistics - not sorted. Have a client with a character set that doesn't sort binary - NOT sorted in all cases.

    ... There are lots of code changes to be made (approx 200 objects) and the testing

    of course. We will not meet our deadline.

    ...

    I would explain to management that the developed code has a serious bug that must be fixed.

    That is what I would recommend. Anything else will not actually get the problem fixed - ever.

    Reviewer: Rajeshwaran Jeyabal

    test@9iR2> select * from v$version;

    BANNER------------------------------------------------------------Oracle9i Enterprise Edition Release 9.2.0.8.0 - ProductionPL/SQL Release 9.2.0.8.0 - ProductionCORE 9.2.0.8.0 ProductionTNS for 32-bit Windows: Version 9.2.0.8.0 - Production

    NLSRTL Version 9.2.0.8.0 - Production

    test@9iR2> show parameter create_stored;test@9iR2>test@9iR2>test@9iR2> show parameter create;

  • 8/14/2019 Ask Tom - Using Stored Outlines.pdf

    20/21

    NAME TYPE VALUE------------------------------------ ----------- ------------------------------create_bitmap_area_size integer 8388608db_create_file_dest stringdb_create_online_log_dest_1 stringdb_create_online_log_dest_2 stringdb_create_online_log_dest_3 stringdb_create_online_log_dest_4 stringdb_create_online_log_dest_5 stringtest@9iR2>test@9iR2>test@9iR2>

    test@9iR2>test@9iR2> show parameter CREATE_STORED_OUTLINES;test@9iR2>test@9iR2>test@9iR2>test@9iR2>test@9iR2> SELECT * 2 FROM V$PARAMETER 3 WHERE upper(NAME) LIKE '%CREATE_STORED_OUTLINES%' 4 /

    no rows selected

    Elapsed: 00:00:00.00test@9iR2>

    But in Oracle 10gR2

    scott@10GR2> select * from v$version;

    BANNER----------------------------------------------------------------Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - ProdPL/SQL Release 10.2.0.1.0 - ProductionCORE 10.2.0.1.0 ProductionTNS for 32-bit Windows: Version 10.2.0.1.0 - ProductionNLSRTL Version 10.2.0.1.0 - Production

    scott@10GR2> show parameter CREATE_STORED_OUTLINES;

    NAME TYPE VALUE------------------------------------ ----------- ------------------create_stored_outlines stringscott@10GR2>scott@10GR2>scott@10GR2> SELECT name,value 2 FROM V$PARAMETER 3 WHERE upper(NAME) LIKE '%CREATE_STORED_OUTLINES%' 4 /

    NAME VALUE------------------------ ------------------------------------create_stored_outlines

    Elapsed: 00:00:00.03

    Tom:

    Referring from Oracle product documentation, I could not find create_stored_outlines in 9iR2, Is that missing in 9.2.0.8 patch sets?

    http://download.oracle.com/docs/cd/B10501_01/server.920/a96533/outlines.htm#26854

    Followup August 9, 2010 - 2pm Central time zone:

    it just seems missing from v$parameter

    Oracle9i Enterprise Edition Release 9.2.0.8.0 - ProductionWith the Partitioning, OLAP and Oracle Data Mining options

    JServer Release 9.2.0.8.0 - Production

    ops$tkyte%ORA9IR2> alter system set CREATE_STORED_OUTLINES = true;

    System altered.

  • 8/14/2019 Ask Tom - Using Stored Outlines.pdf

    21/21

    http://download.oracle.com/docs/cd/B10501_01/server.920/a96540/statements_23a.htm#2071573

    ... The CREATE_STORED_OUTLINES parameter determines whether Oracle should automatically create and store an outline for eachquery submitted on the system. CREATE_STORED_OUTLINES is not an ini tial ization parameter....

    it wasn't included in v$parameter (initialization parameters)

    Write a Review

    All information and materials provided here are p rovided "as-is"; Oracle disclaims all express and implied warranties, including, the implied warranties of merchantability or fitnessfor a particular use. Oracle shall not be liable for any damages, including, direct, indirect, incidental, special or consequential damages for loss of profits, revenue, data or data

    use, incurred by you or any third party in connection with the use of this information or these materials.

    About Oracle | Legal Notices and Terms of Use | Privacy Statement