日期:2014-05-16  浏览次数:20513 次

有关nologging和append提高插入效率的研究

? ? ?那天接到一个事情,我们的数据库表空间已经快用完了,我们需要将一个3GB的表里的数据转储到历史表里去,3天干完。但是我们因为是给运营商服务的,所以白天是绝对不能做这个事情的,只能晚上干,这就要求我们必须尽可能的提高效率。有同事提议使用nologging和append提高效率,但是nologging和append是不是能够提高效率呢。我查询了官方文档,有这么一个描述:

?

? ?Conventional INSERT is the default in serial mode. In serial mode, direct path can be used only if you include the APPEND hint.

? ?Direct-path INSERT is the default in parallel mode. In parallel mode, conventional insert can be used only if you specify the NOAPPEND hint.

? ?In direct-path INSERT, data is appended to the end of the table, rather than using existing space currently allocated to the table. As a result, direct-path INSERT can be considerably faster than conventional INSERT.

?

?

? ? ?原来append模式的原理就是将数据直接插到表的最后,而不是插入到表的空闲空间中,这样从算法上讲,是一个很简单的算法,所以效率会提高不少。但是还是做个试验,验证一下吧。

? ? ?实验环境:windows7 x64,oracle11gR2,归档模式。

? ? ?实验一:append和nologging对insert的影响。

? ? ?1 建立试验用表。

? ? ? create table test1 as select * from dba_objects;

? ? ????2 记录现在系统中的redo size:

? ? ?select name, value from v$sysstat where name = 'redo size';

? ? ?现在系统的redo size为:915021984。

? ? ?3 普通模式插表,记录之后的redo size以及时间:

? ? ?insert into test1 (select * from dba_objects);

? ? ?commit;

? ? ?现在的redo size为:936621172

? ? ?耗用时间为:1.264秒

? ? ?这个操作产生的redo为:21599188

? ? ?4 drop掉试验表,重建该表,使用nologging hint,记录前后的redo size:

? ?? insert /*+ nologging*/ into test1 (select * from dba_objects);

? ? ?commit;

? ? ?? ? 插入之前的redo size:953810184

? ? 插入之后的redo size:962152616