|
原帖由 CaptainKobe 于 2010-4-11 13:16 发表 ![]()
呵呵,继续问一下
1. insert之前drop index,完成以后再create index;
2. insert之前把index置为unusable,完成后再rebuild index;
1和2哪个会更快一点?原因是什么?
感觉应该没什么差别,我猜测是索引UNSABLE的时候插入要比没索引慢,但是重建UNSABLE比新CREATE要快,所以差不多,证实果然大致如此,笔记本环境有限,否则我做上亿的记录的测试可能更清楚点,上班的时候实验一下去UNIX服务器构造大数据量比较一下啊,300万记录是否太小了。(如果没啥差别,建议用失效再生效方式,不容易出错:))
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
Connected as yxl
SQL> create table test as select * from dba_objects;
Table created
SQL> insert into test select * from test;
52596 rows inserted
SQL> insert into test select * from test;
105192 rows inserted
SQL> insert into test select * from test;
210384 rows inserted
SQL> insert into test select * from test;
420768 rows inserted
SQL> insert into test select * from test;
841536 rows inserted
SQL> insert into test select * from test;
1683072 rows inserted
SQL> commit;
Commit complete
SQL> create index idx_object_id on test(object_id);
Index created
SQL> create table test2 as select * from test;
Table created
SQL> commit;
SQL> create index idx2_object_id on test2(object_id);
Index created
SQL> purge recyclebin;
Done
SQL> select count(*) from test;
COUNT(*)
----------
3366144
SQL> select count(*) from test2;
COUNT(*)
----------
3366144
Connected to Oracle Database 10g Enterprise Edition Release 10.2.0.1.0
Connected as yxl
SQL> set timing on
SQL> drop index idx_object_id ;
Index dropped
Executed in 0.25 seconds
SQL> insert into test select * from test;
3366144 rows inserted
Executed in 69.828 seconds
SQL> create index idx_object_id on test(object_id);
Index created
Executed in 124.375 seconds
0.25 + 69.828 +124.375 =194.453
SQL> alter index idx2_object_id unusable;
Index altered
Executed in 0.063 seconds
SQL> insert into test2 select * from test2;
3366144 rows inserted
Executed in 83.938 seconds
SQL> alter index idx2_object_id rebuild;
Index altered
Executed in 102.719 seconds
0.063 +83.938 + 102.719 =192.72
[ 本帖最后由 wabjtam123 于 2010-4-11 14:39 编辑 ] |
|