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

insert /*+ APPEND*/ 笔记

1. append方式添加记录对insert into ... values语句不起作用。
2. append方式批量插入的记录,其存储位置在hwm 之上,即使hwm之下存在空闲块也不能使用。

HWM(高水位线)(High Water Mark):是数据库段管理中的一个重要概念,简单来说HWM就是在段中已经使用和没有使用的块的分界线。在oracle请求空间的时候,如果现有的Freelist中没有足够的空间时,HWM指向的块将被标记为已使用并且HWM将移动到下一个未使用的块。

3. append方式插入记录后,要执行commit,才能对表进行查询。否则会出现错误:
ORA-12838:无法在并行模式下修改之后读/修改对象
4. 在归档模式下,要把表设置为nologging,然后以append方式批量添加记录,才会显著减少redo数量。在非归档模式下,不必设置表的 nologging属性,即可减少redo数量。如果表上有索引,则append方式批量添加记录,不会减少索引上产生的redo数量,索引上的redo 数量可能比表的redo数量还要大。
5. nologging 配合会更快的使用新的BLOCK而不使用FREELIST中的块增加插入速度使用这个hint可以将数据使用直接路径插入到表的高水线之后,由于是连续的没有使用的空间,所以插入速度快。就是说直接插入减少了搜索块的时间。


会在一定程度上造成空间浪费
请看oracle文挡中的描述:
APPEND
The APPEND hint lets you enable direct-path INSERT if your database is runningin serial mode. Your database is in serial mode if you are not using EnterpriseEdition. Conventional INSERT is the default in serial mode, and direct-pathINSERT is the default in parallel mode.
In direct-path INSERT, data is appended tothe end of the table, rather than using existing space currently allocated tothe table. As a result, direct-path INSERT can be considerably faster than conventionalINSERT.

SQL语句中的优化提示
APPEND : Only valid for INSERT .. SELECT. Allows INSERT to work like directload or to perform parallel insert.