색인 성능 실험 분석

6559 단어
1. 분석 대상: 테이블 구분 없음, 인덱스 구분 없음 & 테이블 구분 없음, 인덱스local 구분
1. 차트 작성:
temp1 테이블: 테이블이 구분되지 않음, 인덱스가 구분되지 않음
create table temp1 nologging  tablespace P17ETLTBS as 
select /*+ parallel(t,8) */  * from t_cc_l1_cpic_policy t where 1=1 and policy_id < 2500000 ;  

alter table temp1 parallel 1 ;

create index i_temp1_policyno on temp1(ext_policy_no) parallel 4 tablespace P17IDXTBS02 ; 

alter index i_temp1_policyno parallel 1 ;

temp2표: 표는 보증서 번호에 따라hash구역, 인덱스local구역
create table TEMP2
(
  POLICY_ID                  NUMBER(10) not null,
  EXT_POLICY_NO              VARCHAR2(45),
  EXT_SUBCOMP_NO             VARCHAR2(30),
  SUB_COMPANY_ID             NUMBER(10),
  SUBCOMP_NAME               VARCHAR2(180),
  BEGIN_OPERATION_DATE       DATE,
  END_OPERATION_DATE         DATE,
  POLICY_ISSUE_DATE          DATE,
  POLICY_STATUS_CD           NUMBER(10),
  POLICY_STATUS              VARCHAR2(180),
  EXT_POLICY_APP_NO          VARCHAR2(45),
  EXT_SUB_CENTRAL_COMPANY_NO VARCHAR2(30),
  SUB_CENTRAL_COMPANY_ID     NUMBER(10),
  SUB_CENTRAL_COMPANY        VARCHAR2(180),
  POL_CD                     VARCHAR2(20),
  POL_PRODUCT_NAME           VARCHAR2(180),
  EXT_AGENT_CD               VARCHAR2(60),
  AGENT_NAME                 VARCHAR2(180),
  SOURCE_SYSTEM              VARCHAR2(10),
  CRT_USER_ID                NUMBER(10),
  CRT_DTTM                   DATE,
  LASTUPT_USER_ID            NUMBER(10),
  LASTUPT_DTTM               DATE,
  DATA_HIERARCHY_TYPE        VARCHAR2(10),
  ENABLE_FLG                 VARCHAR2(1),
  PRODUCT_ASS_CODE           VARCHAR2(8),
  POLICY_ASS_CODE            VARCHAR2(15),
  SALE_CHANNEL               VARCHAR2(2)
)
partition by hash (EXT_POLICY_NO)
(
  partition SYS_P1
    tablespace P17ETLTBS,
  partition SYS_P2
    tablespace P17DATATBS02,
  partition SYS_P3
    tablespace P17ETLTBS,
  partition SYS_P
    tablespace P17DATATBS02,
  partition SYS_P4
    tablespace P17ETLTBS,
  partition SYS_P5
    tablespace P17DATATBS02,
  partition SYS_P6
    tablespace P17ETLTBS,
  partition SYS_P7
    tablespace P17DATATBS02,
  partition SYS_P8
    tablespace P17ETLTBS
);

insert into temp2
select /*+ parallel(t,8) */  * from t_cc_l1_cpic_policy t where 1=1 and policy_id < 2500000 ; 
commit; 

create index i_temp2_policyno on temp2(EXT_POLICY_NO) local parallel 4 ;
alter index i_temp2_policyno parallel  1 ;

통계표 작성
create table TEMP_STAT
(
  TYPE       CHAR(1),
  SID        NUMBER,
  STATISTIC# NUMBER,
  VALUE      NUMBER
)

이로써temp1,temp2표는 모두 200백만 위안 정도의 데이터를 가지고 있다.
2, SQL 분석 수행;
declare
  v_policyno varchar2(45);
  v_polcd     varchar2(20);
  v_POL_PRODUCT_NAME VARCHAR2(100);
  v_sysdate  timestamp;
  v_random   number;
  type ty_policyno is table of t_cc_l1_cpic_policy.ext_policy_no%type;
  type ty_pol_cd is table of t_cc_l1_cpic_policy.pol_cd%type;
  v_list_policyno ty_policyno;
  v_list_pol_cd ty_pol_cd;
  v_table t_cc_l1_cpic_policy%rowtype;
begin

  v_random := trunc(2500000 * dbms_random.value);

  v_sysdate := sysdate;

  execute immediate 'truncate table temp_stat ';

  select t.ext_policy_no,t.pol_cd bulk collect
    into v_list_policyno,v_list_pol_cd
    from t_cc_l1_cpic_policy t
   where 1 = 1
     and policy_id < 2500000
     and policy_id >= v_random
     and policy_id <= v_random + 10000;

  dbms_output.put_line(sysdate - v_sysdate);

  for i in 1 .. v_list_policyno.count loop
    v_policyno := v_list_policyno(i);
    v_polcd  := v_list_pol_cd(i); 
  end loop;

  insert into temp_stat
    select '1', t.* from v$mystat t;
  commit;

  v_sysdate := sysdate;

  for i in 1 .. v_list_policyno.count loop
    select t.*
      into v_table
      from temp1 t
     where 1 = 1
       and t.ext_policy_no = v_list_policyno(i)
       and t.pol_cd = v_list_pol_cd(i)
       and t.enable_flg = '1';
    if i = v_list_policyno.count then
      dbms_output.put_line(i);
    end if;
  end loop;

  dbms_output.put_line(sysdate - v_sysdate);

  insert into temp_stat
    select '2', t.* from v$mystat t;
  commit;

  v_sysdate := sysdate;

  for i in 1 .. v_list_policyno.count loop
    select t.*
      into v_table
      from temp2 t
     where 1 = 1
       and t.ext_policy_no = v_list_policyno(i)
       and t.pol_cd = v_list_pol_cd(i)
       and t.enable_flg = '1';
    if i = v_list_policyno.count then
      dbms_output.put_line(i);
    end if;
  end loop;

  dbms_output.put_line(sysdate - v_sysdate);

  insert into temp_stat
    select '3', t.* from v$mystat t;
  commit;

end;


3, 결과 분석:
a, 런타임 분석:
다음과 같은 SQL 문이 반환됩니다.
+000000000 00:00:49.000000000
7934
+000000000 00:00:01.000000000
7934
+000000000 00:00:01.000000000

b, v$mystat 분석:
select a.statistic# ,c.NAME , a.dif "first", b.dif "sec" , b.dif - a.dif from ( 
select t2.value - t1.value dif,t1.statistic# from temp_stat t1 , temp_stat t2
where 1=1 and t1.statistic# = t2.statistic# 
and t1.type = '1'
and t2.type = '2'
and  t2.value <> t1.value ) a,  (
select t2.value - t1.value dif,t1.statistic# from temp_stat t1 , temp_stat t2
where 1=1 and t1.statistic# = t2.statistic# 
and t1.type = '2'
and t2.type = '3'
and  t2.value <> t1.value 
) b , v$statname c where a. statistic# = b.statistic# 
and a.statistic# = c.STATISTIC# 
order by  (  b.dif - a.dif  ) desc 

결과는 다음과 같습니다.
 
STATISTIC#
NAME
DIF
DIF
B.DIF-A.DIF
1
58
physical read bytes
12910592
18481152
5570560
2
39
physical read total bytes
12910592
18481152
5570560
3
243
IMU Redo allocation size
6296
7352
1056
4
242
IMU undo allocation size
72
1000
928
5
97
free buffer inspected
1536
2304
768
6
37
physical read total IO requests
1576
2256
680
7
57
physical read IO requests
1576
2256
680
8
55
physical reads cache
1576
2256
680
9
54
physical reads
1576
2256
680
10
93
free buffer requested
1582
2256
674
11
176
undo change vector size
952
1016
64
에서 알 수 있듯이 테이블은 구분되지 않고 IO 12.9MB를 읽고 구분되며 로컬 인덱스를 18.4MB로 사용합니다.

좋은 웹페이지 즐겨찾기