0

我有两个相同的模式,在通过数据库链接连接的不同数据库上。

Schema_1: Source Schema. **Rows being inserted at rapid rate.**
Schema_2: Target Schema. 

快速插入到 Schema_1(源模式)中的行。

我在源模式中运行 SQL,如下所示:

Insert into Table_1@DB_LINK select * from Table_1

此语句需要几分钟时间。

现在我将语句更改如下(使用闪回查询)

Insert into Table_1@DB_LINK select * Table_1 as of timestamp to_timestamp ( to_timestamp ( date ));

此查询在几秒钟内完成。

为什么会有如此巨大的差异?

4

1 回答 1

1

在您的闪回查询中,您正在选择恰好插入的行05/01/2017 10:00:00。但是在您的非闪回查询中,您选择的是插入到表中的所有行。

简单演示:

SQL> create table t1(id number, name varchar2(20));

Table created.

SQL> insert into t1 values(1, 'joe');

1 row created.

SQL>  insert into t1 values(2, 'jay');

1 row created.

SQL> commit;

Commit complete.

SQL>  insert into t1 values(3, 'john');

1 row created.

SQL> commit;

Commit complete.

SQL> select * from t1;

        ID NAME
---------- --------------------
         1 joe
         2 jay
         3 john

SQL> select * from t1 as of timestamp to_timestamp('02-MAY-17 11:00','DD-MON-RR HH24:MI');

        ID NAME
---------- --------------------
         1 joe

我的第一个查询select * from t1;与您的非闪回查询相同​​,后者从表中选择所有行。

我的第二个查询select * from t1 as of timestamp to_timestamp('02-MAY-17 11:00','DD-MON-RR HH24:MI');类似于您的闪回查询,它只选择一行。

当然插入一行比插入三行要快。

于 2017-05-02T05:22:10.637 回答