오라클

[책] Optimizing Oracle Optimizer

끄적끄적 2009. 3. 5. 11:56

http://wiki.oracleclub.com/pages/viewpage.action?pageId=4325453

*  DBMS_XPLAN

1) dbms_xplan.display
 - explain plan for    select * from t1;

 -  select * from table(dbms_xplan.display('plan_table', null, 'typical', null ));   
          -- 디폴트(dbms_xplan.display) 와 동일한 결과
 -  select * from table(dbms_xplan.display('plan_table', null, 'all'));  
          -- Query Block 정보, 추출하는 컬럼정보, /*+ qb_name(x) */ 힌트로 query block 명 조작가능
 -  select * from table(dbms_xplan.display('plan_table', null, 'outline'));   -- 필요한(사용된) 힌트를 나열
 -  select * from table(dbms_xplan.display('plan_table', null, 'advanced'));   -- all, outline 정보 같이 보여줌

2) dbms_xplan.display_cursor

 - 통계정보 생성(t1테이블)
    exec dbms_stats.gather_table_stats(user, 't1', cascade=>true, no_invalidate=>false);

   : 인덱스가 있는 컬럼에 대해 histogram 생성하면서 통계생성
    exec dbms_stats.gather_table_stats(user, 't1', method_opt=>'for all indexed columns size skewonly');

 - gather_plan_statistics 힌트 : 쿼리 수행시 예측 Row수와 실제 Row수를 기록한다.
  select /*+ gather _plan_statistics */ count(*) from t1 where c1 = 'Many2';

  - select * from table(dbms_xplan.display_cursor(null, null, 'allstats last'));   
     -- 현재 세션에 대한 최근 쿼리 결과조회 ( SQL ID, Child number, 옵션)
 
  - 테이블 정보조회
     select     a.table_name, a.num_rows, a.blocks, a.sample_size, a.last_analyzed,
       s.column_name, s.num_distinct, s.num_nulls, s.density, s.low_value, s.high_value, s.histogram
     from user_tab_statistics a, user_tab_cols s
     where a.table_name = 'T1'
     and a.table_name = s.table_name;

     select * from user_histograms
     where table_name = 'T1'
     order by column_name, endpoint_value;


* Index and CBO
 1) Clustering Factor
    - Index Scan의 Cost 계산
      Cost = Blevel + Leaf Blocks * index Selectivity + Clustering Factor * Table Selectivity + Adjusted CPU

   - index 생성시 sequence key 값을 사용하거나, 시간순으로 date형을 사용하면 clustering factor가 좋게(낮게) 나온다. clustering factor를 개선시키려면 테이블을 다시 생성(order by 로 reinsert)해야 함.




반응형