三十一、インデックスの弊害の読み書き分離の導入

14315 ワード

インデックスの弊害の読み書き分離の導入
インデックス=カラム値+rowidインデックスの弊害:インデックスはソートする必要があり、データが挿入されると再ソートされ、遅くなります.インデックスのメリット:クエリーの速度が速い
1、マルチインデックスのテーブル挿入データが遅い
実験SQL:
drop table test1 purge;
drop table test2 purge;
drop table test3 purge;
drop table t purge;
create table t as select * from dba_objects;
create table test1 as select * from t;
create table test2 as select * from t;
create table test3 as select * from t;
create index idx_owner on test1(owner);
create index idx_object_name on test1(object_name);
create index idx_data_obj_id on test1(data_object_id);
create index idx_created on test1(created);
create index idx_last_ddl_time on test1(last_ddl_time);
create index idx_status on test1(status);
create index idx_t2_sta on test2(status);
create index idx_t2_objid on test2(object_id);
set timing on 
--  1(test1  6   )
insert into test1 select * from t;
commit;
--  2(test2  2   )
insert into test2 select * from t;
commit;
--  3(test3     )
insert into test3 select * from t;
commit;

実験結果:

SQL> --  1(test1  6   )
SQL> insert into test1 select * from t;

   72690 。

    :  00: 00: 05.72
SQL> commit;

    。

    :  00: 00: 00.01
SQL> --  2(test2  2   )
SQL> insert into test2 select * from t;

   72690 。

    :  00: 00: 02.93
SQL> commit;

    。

    :  00: 00: 00.00
SQL> --  3(test3     )
SQL> insert into test3 select * from t;

   72690 。

    :  00: 00: 00.85
SQL> commit;

    。

    :  00: 00: 00.01
test1     ,  :5.72
test2     ,  :2.93
test3    ,  :0.85

2、先行インデックス再挿入データと先行データ再構築インデックスの時間比較
drop table t purge;
create table t as select * from dba_objects;
insert into t select * from t;
insert into t select * from t;
commit;
--             (           )
set timing on 
create index idx_t_owner on t(owner);
create index idx_t_obj_name on t(object_name);
create index idx_t_data_obj_id on t(data_object_id);
create index idx_t_created on t(created);
create index idx_t_last_ddl on t(last_ddl_time);

--  1(t  6   )
insert into t select * from t;
commit;
 

--      2
drop table t purge;
create table t as select * from dba_objects;
insert into t select * from t;
insert into t select * from t;
commit;

---                 (             )

set timing on 

--  1(t  6   ,     )
insert into t select * from t;
create index idx_t_owner on t(owner);
create index idx_t_obj_name on t(object_name);
create index idx_t_data_obj_id on t(data_object_id);
create index idx_t_created on t(created);
create index idx_t_last_ddl on t(last_ddl_time);