關於insert /*+ append*/ 各種insert插入速度比較
http://hi.baidu.com/dba_james/blog/item/6909ec2b7e0a742ad52af128.html[@more@]
SQL> select count(*) from t;
COUNT(*)
----------
5442048
****************************
SQL> alter table t1 nologging;
SQL> insert /*+append*/ into t1
2 select * from t;
5442048 rows created.
Elapsed: 00:00:55.73
****************************
SQL> create table t1 nologging parallel(degree 2) as select * from t;
Table created.
Elapsed: 00:00:56.79
********************************
SQL> insert /*+APPEND */ into t1
2 select /*+ parallel(t,4) */ * from t;
5442048 rows created.
Elapsed: 00:01:38.39
***********************************
alter table t1 nologging;
SQL> insert into t1
2 select * from t;
5442048 rows created.
Elapsed: 00:01:46.18
***********************************
SQL> alter table t1 logging;
Table altered.
SQL> insert into t1
2 select * from t;
5442048 rows created.
Elapsed: 00:02:03.51
*********************************
SQL> create table t1
2 as
3 select * from t;
Table created.
Elapsed: 00:03:03.34
insert 和 insert /*+append*/對hwm的影響
(1) insert
[email=sys@ORCL%3Ecreate]sys@ORCL>create[/email] table t_hwmtablespace hwm as select * from all_objects;
表已建立。
[email=sys@ORCL%3Eselect]sys@ORCL>select[/email]count(*) from t_hwm;
COUNT(*)
----------
50176
已選擇 1 行。
[email=sys@ORCL]sys@ORCL[/email]>
[email=sys@ORCL%3Edelete]sys@ORCL>delete[/email] from t_hwm;
已刪除50176行。
[email=sys@ORCL%3Eexec]sys@ORCL>exec[/email]show_space('t_hwm','auto')
Total Blocks............................5120
Total Bytes.............................41943040
Unused Blocks...........................4429
Unused Bytes............................36282368
Last Used Ext FileId....................10
Last Used Ext BlockId...................5129
Last Used Block.........................691
PL/SQL 過程已成功完成。
[email=sys@ORCL%3Einsert]sys@ORCL>insert[/email]into t_hwm select * from all_objects where rownum < 2000;
已建立1999行。
[email=sys@ORCL%3Eexec]sys@ORCL>exec[/email]show_space('t_hwm','auto')
Total Blocks............................5120
Total Bytes.............................41943040
Unused Blocks...........................4429
Unused Bytes............................36282368
Last Used Ext FileId....................10
Last Used Ext BlockId...................5129
Last Used Block.........................691
--在插入HWM下資料量時,不會修還HWM
PL/SQL 過程已成功完成。
[email=sys@ORCL%3Einsert]sys@ORCL>insert[/email]into t_hwm select * from all_objects ;
已建立50176行。
[email=sys@ORCL%3Eexec]sys@ORCL>exec[/email]show_space('t_hwm','auto')
Total Blocks............................5120
Total Bytes.............................41943040
Unused Blocks...........................4374
Unused Bytes............................35831808
Last Used Ext FileId....................10
Last Used Ext BlockId...................5129
Last Used Block.........................746
PL/SQL 過程已成功完成。
--在插入大量資料量時,超過HWM時增加HWM
(2) insert /*+ append */ into
[email=sys@ORCL%3Edelete]sys@ORCL>delete[/email]from t_hwm;
已刪除52175行。
[email=sys@ORCL%3Eexec]sys@ORCL>exec[/email]show_space('t_hwm','auto')
Total Blocks............................5120
Total Bytes.............................41943040
Unused Blocks...........................4374
Unused Bytes............................35831808
Last Used Ext FileId....................10
Last Used Ext BlockId...................5129
Last Used Block.........................746
PL/SQL 過程已成功完成。
[email=sys@ORCL%3Einsert]sys@ORCL>insert[/email]/*+ append */ into t_hwm select * from all_objects where rownum
< 2000;
已建立1999行。
[email=sys@ORCL%3Eexec]sys@ORCL>exec[/email]show_space('t_hwm','auto')
Total Blocks............................5120
Total Bytes.............................41943040
Unused Blocks...........................4374
Unused Bytes............................35831808
Last Used Ext FileId....................10
Last Used Ext BlockId...................5129
Last Used Block.........................746
PL/SQL 過程已成功完成。
[email=sys@ORCL%3Einsert]sys@ORCL>insert[/email]/*+ append */ into t_hwm select * from all_objects where rownum
< 20000;
[email=sys@ORCL%3Ecommit]sys@ORCL>commit[/email];
提交完成。
[email=sys@ORCL%3Einsert]sys@ORCL>insert[/email]/*+ append */ into t_hwm select * from all_objects where rownum
< 20000;
已建立19999行。
[email=sys@ORCL%3Eexec]sys@ORCL>exec[/email]show_space('t_hwm','auto')
Total Blocks............................5120
Total Bytes.............................41943040
Unused Blocks...........................4349
Unused Bytes............................35627008
Last Used Ext FileId....................10
Last Used Ext BlockId...................5129
Last Used Block.........................771
PL/SQL 過程已成功完成。
1. append方式新增記錄對insert into ... values語句不起作用。
2. 以append方式批次插入的記錄,其儲存位置在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.
COUNT(*)
----------
5442048
****************************
SQL> alter table t1 nologging;
SQL> insert /*+append*/ into t1
2 select * from t;
5442048 rows created.
Elapsed: 00:00:55.73
****************************
SQL> create table t1 nologging parallel(degree 2) as select * from t;
Table created.
Elapsed: 00:00:56.79
********************************
SQL> insert /*+APPEND */ into t1
2 select /*+ parallel(t,4) */ * from t;
5442048 rows created.
Elapsed: 00:01:38.39
***********************************
alter table t1 nologging;
SQL> insert into t1
2 select * from t;
5442048 rows created.
Elapsed: 00:01:46.18
***********************************
SQL> alter table t1 logging;
Table altered.
SQL> insert into t1
2 select * from t;
5442048 rows created.
Elapsed: 00:02:03.51
*********************************
SQL> create table t1
2 as
3 select * from t;
Table created.
Elapsed: 00:03:03.34
insert 和 insert /*+append*/對hwm的影響
(1) insert
[email=sys@ORCL%3Ecreate]sys@ORCL>create[/email] table t_hwmtablespace hwm as select * from all_objects;
表已建立。
[email=sys@ORCL%3Eselect]sys@ORCL>select[/email]count(*) from t_hwm;
COUNT(*)
----------
50176
已選擇 1 行。
[email=sys@ORCL]sys@ORCL[/email]>
[email=sys@ORCL%3Edelete]sys@ORCL>delete[/email] from t_hwm;
已刪除50176行。
[email=sys@ORCL%3Eexec]sys@ORCL>exec[/email]show_space('t_hwm','auto')
Total Blocks............................5120
Total Bytes.............................41943040
Unused Blocks...........................4429
Unused Bytes............................36282368
Last Used Ext FileId....................10
Last Used Ext BlockId...................5129
Last Used Block.........................691
PL/SQL 過程已成功完成。
[email=sys@ORCL%3Einsert]sys@ORCL>insert[/email]into t_hwm select * from all_objects where rownum < 2000;
已建立1999行。
[email=sys@ORCL%3Eexec]sys@ORCL>exec[/email]show_space('t_hwm','auto')
Total Blocks............................5120
Total Bytes.............................41943040
Unused Blocks...........................4429
Unused Bytes............................36282368
Last Used Ext FileId....................10
Last Used Ext BlockId...................5129
Last Used Block.........................691
--在插入HWM下資料量時,不會修還HWM
PL/SQL 過程已成功完成。
[email=sys@ORCL%3Einsert]sys@ORCL>insert[/email]into t_hwm select * from all_objects ;
已建立50176行。
[email=sys@ORCL%3Eexec]sys@ORCL>exec[/email]show_space('t_hwm','auto')
Total Blocks............................5120
Total Bytes.............................41943040
Unused Blocks...........................4374
Unused Bytes............................35831808
Last Used Ext FileId....................10
Last Used Ext BlockId...................5129
Last Used Block.........................746
PL/SQL 過程已成功完成。
--在插入大量資料量時,超過HWM時增加HWM
(2) insert /*+ append */ into
[email=sys@ORCL%3Edelete]sys@ORCL>delete[/email]from t_hwm;
已刪除52175行。
[email=sys@ORCL%3Eexec]sys@ORCL>exec[/email]show_space('t_hwm','auto')
Total Blocks............................5120
Total Bytes.............................41943040
Unused Blocks...........................4374
Unused Bytes............................35831808
Last Used Ext FileId....................10
Last Used Ext BlockId...................5129
Last Used Block.........................746
PL/SQL 過程已成功完成。
[email=sys@ORCL%3Einsert]sys@ORCL>insert[/email]/*+ append */ into t_hwm select * from all_objects where rownum
< 2000;
已建立1999行。
[email=sys@ORCL%3Eexec]sys@ORCL>exec[/email]show_space('t_hwm','auto')
Total Blocks............................5120
Total Bytes.............................41943040
Unused Blocks...........................4374
Unused Bytes............................35831808
Last Used Ext FileId....................10
Last Used Ext BlockId...................5129
Last Used Block.........................746
PL/SQL 過程已成功完成。
[email=sys@ORCL%3Einsert]sys@ORCL>insert[/email]/*+ append */ into t_hwm select * from all_objects where rownum
< 20000;
[email=sys@ORCL%3Ecommit]sys@ORCL>commit[/email];
提交完成。
[email=sys@ORCL%3Einsert]sys@ORCL>insert[/email]/*+ append */ into t_hwm select * from all_objects where rownum
< 20000;
已建立19999行。
[email=sys@ORCL%3Eexec]sys@ORCL>exec[/email]show_space('t_hwm','auto')
Total Blocks............................5120
Total Bytes.............................41943040
Unused Blocks...........................4349
Unused Bytes............................35627008
Last Used Ext FileId....................10
Last Used Ext BlockId...................5129
Last Used Block.........................771
PL/SQL 過程已成功完成。
1. append方式新增記錄對insert into ... values語句不起作用。
2. 以append方式批次插入的記錄,其儲存位置在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.
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/82387/viewspace-1024172/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- insert /*+ append */直接路徑插入APP
- 直接路徑插入 -- insert /*+append*/ into [zt]APP
- 關於insert /* append */的幾點註記APP
- insert /*+ append */ into 與insert into 的區別APP
- APPEND,bulk collect,正常插入比較APP
- 關於加快INSERT語句執行速度和 HINT /*+ append*/及nologging的使用APP
- C#中各種Lock的速度比較C#
- insert /*+ append */於report unrecoverable命令實驗。APP
- insert的不同場景效能比較
- 關於加快INSERT語句執行速度的測試
- insert 中append 用法詳解APP
- nologging和insert /*+append*/APP
- Append與Direct-Path Insert(一)APP
- Append與Direct-Path Insert(二)APP
- MySQL大量資料插入各種方法效能分析與比較MySql
- insert批量插入優化方案優化
- [CareerCup] 5.1 Insert Bits 插入位
- insert append需要注意的問題APP
- 如何讓insert /*+ append */ 採用並行。APP並行
- ORACLE的Copy命令和create table,insert into的比較Oracle
- oracle bulk Insert 比insert 快不是一點啊.Oracle
- 【INSERT】在INSERT插入語句中引入條件限制選項實現資料插入控制
- 【SQL】 Multi table insert 多表插入操作SQL
- oracle insert all多表插入的示例Oracle
- [Oracle] Append hint(insert sql) will lead a TM LOCKOracleAPPSQL
- CTAS和insert append的一個測試APP
- Selenium各種工具比較
- Oracle批量插入資料insert all into用法Oracle
- c++ insert iterators 插入型迭代器C++
- MySQL:使用INSERT 插入多條記錄MySql
- Oracle中的insert/insert all/insert firstOracle
- MySQL批量insert效率對比SQL
- 【MyBatis】幾種批量插入效率的比較MyBatis
- Direct Path Insert與APPEND, PARALLEL的梳理與小結APPParallel
- insert語句中append提示對欄位的檢查APP
- oracle-資料庫- insert 插入語句Oracle資料庫
- MyBatis insert操作插入,返回主鍵from官方MyBatis
- 通過append hint來插入資料,演示它和普通插入資料的效能比較。APP