Sunteți pe pagina 1din 13

What does it do?

William Tang 2012-10-15

Event 10089 level 1: CBO disable index sorting This event is not set by default. By default CBO use index sorting as a tiebreaker method to choose the first index alphabetically in the event of a choice between two plans using indexes with equal costs. There is brief description in Oracle Doc ID 1485410.1

Use event 10053 to show what optimizer is doing when there are two plans using indexes with the same costs. optimizer_capture_sql_plan_baselines is false. Use treeviewer (Hans-Peter Sloot, Robert van der Ende) for 10053 trace file. http://jonathanlewis.wordpress.com/2010/04/30/ 10053-viewer/

Create table t2 create table t2 ( c1 number , c2 number , c3 number , c4 number , c5 number , c6 number , c7 number , c8 number , c9 number , c10 number);

Generate 100K rows for table t2.


execute dbms_random.seed(0); insert into t2 select c1,c1+1,c1+2,c1+3,c1+4,c1+5,c1+6,c1+7,c1+8,c1+9 from ( select trunc(1+(100000-1)*dbms_random.value) c1 from (select rownum from all_objects where rownum <= 1000) k1, (select rownum from all_objects where rownum <= 100) k2 where rownum <=100000); commit;

Generate create indexes script and run it.


with t2_cols as (select column_name from dba_tab_columns where table_name='T2 order by column_ID) select 'create index t2_idx'||rownum||' on t2('|| case when (tc1.column_name = tc2.column_name) then tc1.column_name else tc1.column_name||','||tc2.column_name end ||');' from t2_cols tc1, t2_cols tc2;

Gather statistics on table t2.


execute DBMS_STATS.gather_table_stats(ownname => 'WILLIAM', tabname => 'T2',estimate_percent => 100, DEGREE => 2);

Manually set T2_IDX2 statistics same as T2_IDX11 If needed.


Note: index t2_idx2 on t2(C1,C2); index t2_idx11 on t2(C2,C1); execute DBMS_STATS.SET_INDEX_STATS ('WILLIAM', 'T2_IDX2', numlblks => 290, clstfct => 99865);

CBO default behavior.


alter system flush shared_pool; alter session set max_dump_file_size=unlimited; alter session set tracefile_identifier='wtang_no10089'; alter session set events '10053 trace name context forever, level 2'; select count(*), c1, c2 from t2 where c1=9 and c2=10 group by c1, c2; exit;

CBO default behavior.

CBO default behavior. Look at the index statistics, they are sorted by index name. Plan used index T2_IDX11.

Event 10089 set.


alter session set events '10089 trace name context forever, level 1' alter system flush shared_pool; alter session set max_dump_file_size=unlimited; alter session set tracefile_identifier='wtang_10089'; alter session set events '10053 trace name context forever, level 2'; select count(*), c1, c2 from t2 where c1=9 and c2=10 group by c1, c2; exit;

Event 10089 set.

Event 10089 set. Look at the index statistics, they are not sorted by index_name. They are in the order I created them. Plan used index T2_IDX2.

10g or 11g with event 10089 set. CBO could choose a different index access path for the same sql. In the test case, it changed because the order of indexes no longer sorted alphabetically. On a side note, this event can be used to reduced number of gets on row cache dc_objects during optimization.
http://williamtang2012.wordpress.com/2013/04/02/wait-event-latch-row-cache-objects-dc_objects-2

S-ar putea să vă placă și