首页  >  文章  >  数据库  >  Conventional-pathinsert(传统路径插入)

Conventional-pathinsert(传统路径插入)

WBOY
WBOY原创
2016-06-07 16:06:341311浏览

前面我们已经说过了Direct-path INSERT,现在来说一下ConventionalINSERT。文章来源Oracle? Database Administrator's Guide11 g Release 2 (11.2)” Conventional and Direct-Path INSERT You can use the INSERT statement to insert data into a table, p

前面我们已经说过了Direct-path INSERT,现在来说一下Conventional INSERT。文章来源"Oracle? Database Administrator's Guide11g Release 2 (11.2)”

Conventional and Direct-Path INSERT

You can use the INSERT statement to insert data into a table, partition, or view in two ways: conventional INSERT and direct-path INSERT. When you issue a conventional INSERT statement, Oracle Database reuses free space in the table into which you are inserting and maintains referential integrity constraints. With direct-pathINSERT, the database appends the inserted data after existing data in the table. Data is written directly into data files, bypassing the buffer cache. Free space in the existing data is not reused. This alternative enhances performance during insert operations and is similar to the functionality of the Oracle direct-path loader utility, SQL*Loader. When you insert into a table that has been created in parallel mode, direct-pathINSERT is the default.

##向表,分区或者视图中插入数据,我们可以使用传统路径插入和直接路径插入两种方式。

当使用传统路径插入方式时,数据库会利用目标表中空闲空间(插入时会扫描高水位线以下,如果有空闲空间就利用,如果没有空闲空间就扩展),并且在插入过程中会维护引用的完整性约束。

当使用直接路径插入时,使用高水位线之上的块。数据绕过buffer cache被直接写入数据文件。目标表中空间空间不被使用。direct-pathINSERT的功能同direct-path loader单元SQL*Loader相似,可以提高insert操作的性能。

当你向一个并行表中插入数据时,默认使用direct-pathINSERT方式。

The manner in which the database generates redo and undo data depends in part on whether you are using conventional or direct-pathINSERT:

##数据库日志产生的方式一定程度上取决于你是使用传统路径还是直接路径查收

Conventional INSERT always generates maximal redo and undo for changes to both data and metadata, regardless of the logging setting of the table and the archivelog and force logging settings of the database.##不论表是否设置了logging模式,数据库是否启用了force logging,数据库是否启用了归档,传统路径插入方式总是会为数据好元数据的变化产生大量的redo和undo

Direct-path INSERT generates both redo and undo for metadata changes, because these are needed for operation recovery. For data changes, undo and redo are generated as follows:##直接路径插入会为元数据的改变而产生redo和undo,因为这些是进行恢复所需要的信息。对于数据的变化,其所产生的redo和undo根据下面的条件来决定:

Direct-path INSERT always bypasses undo generation for data changes.##直接路径插入不会产生undo(因为不需要靠undo来回滚)

If the database is not in ARCHIVELOG or FORCE LOGGING mode, then no redo is generated for data changes, regardless of the logging setting of the table. ##如果数据库没有被设置成归档模式,也没有被设置成force logging模式,那么不会为数据的变化产生日志,除非目标表设置了logging模式

If the database is in ARCHIVELOG mode (but not in FORCE LOGGING mode), then direct-path INSERT generates data redo for LOGGING tables but not for NOLOGGING tables.##如果被设置为归档模式,但是没有被设置我force logging,那么直接路径插入会为指定了logging的表的数据变化产生日志,如果表没有指定logging那么就不产生日志

If the database is in ARCHIVELOG and FORCE LOGGING mode, then direct-path SQL generate data redo for both LOGGING and NOLOGGING tables.##如果数据库处于归档模式,并且设置了force logging,那么不论表是否指定了logging属性,直接路径插入都会为数据变化产生日志

Direct-path INSERT is subject to a number of restrictions. If any of these restrictions is violated, then Oracle Database executes conventional INSERT serially without returning any message, unless otherwise noted:

##Direct-path INSERT有如下一些限制。如果符合下面任何一条,那么数据库会在不给任何反馈信息的情况下自动的采用串行传统路径插入

您可以在单个事务中使用多个直接路径 INSERT 语句,无论是否带有其他 DML 语句。但是,在一条 DML 语句更改特定的表、分区或索引后,事务中的其他 DML 语句就不能再进行更改。 访问该表、分区或索引。##

在 direct-pathINSERT 语句之前允许访问相同表、分区或索引的查询,但在其之后则不允许。

如果任何串行或并行语句尝试访问已在同一事务中通过直接路径INSERT 修改的表,则数据库将返回错误并拒绝该语句。

目标表不能是集群。

目标表不能包含对象类型列。

如果索引组织表 (IOT) 未分区、具有映射表或者被物化视图引用,则不支持直接路径 INSERT。

直接路径 INSERT 到索引组织表 (IOT) 的单个分区或只有一个分区的分区 IOT 中,将串行完成,即使 IOT 是在并行模式下创建的或者您指定了 APPEND 或 APPEND_VALUES 提示。然而,只要不使用分区扩展名称并且 IOT 具有多个分区,对分区 IOT 的直接路径 INSERT 操作将遵循并行模式。

目标表上不能定义任何触发器或引用完整性约束。

目标表无法复制。

包含直接路径 INSERT 语句的事务不能分布式。

直接路径插入数据插入完成后无法立即查询或修改。如果您尝试这样做,则会生成 ORA-12838 错误。您必须首先发出 在尝试读取或修改新插入的数据之前执行 COMMIT 语句。

另请参阅:

Oracle 数据库管理员指南,了解 direct-pathINSERT 的更完整描述

Oracle Database Utilities 有关 SQL*Loader 的信息

Oracle 数据库性能调优指南,了解如何调优并行的信息 直接路径INSERT

使用传统插入来加载表格

在传统的 INSERT 操作期间,数据库会重用表中的可用空间,将新插入的数据与现有数据交错。在此类操作期间,数据库还维护引用完整性约束。不像 直接路径INSERT操作,常规INSERT操作不需要表上的排它锁。

其他一些限制适用于直接路径 INSERT 操作,但不适用于传统 INSERT 操作。看 Oracle 数据库 SQL 语言参考,了解有关这些限制的信息。

您可以使用NOAPPEND提示以串行模式或并行模式执行传统的INSERT操作。

以下是使用NOAPPEND提示以串行模式执行常规INSERT的示例:

INSERT /*+ NOAPPEND */ INTO sales_hist SELECT * FROM sales WHERE cust_id=8890;

以下是使用 NOAPPEND 提示以并行模式执行常规 INSERT 的示例:

INSERT /*+ NOAPPEND PARALLEL */ INTO sales_hist
   SELECT * FROM sales;

要以并行 DML 模式运行,必须满足以下要求:

您必须安装 Oracle 企业版。

您必须在会话中启用并行 DML。为此,请提交以下声明:

ALTER SESSION { ENABLE | FORCE } PARALLEL DML;

您必须至少满足以下要求之一:

在创建时或随后指定目标表的并行属性

为每个插入操作指定 PARALLEL 提示

将数据库初始化参数PARALLEL_DEGREE_POLICY设置为AUTO

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn