關於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/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SQL INSERT批次插入方式SQL
- insert批量插入優化方案優化
- Oracle中的insert/insert all/insert firstOracle
- [LeetCode] 57. Insert Interval 插入區間LeetCode
- Oracle批量插入資料insert all into用法Oracle
- oracle-資料庫- insert 插入語句Oracle資料庫
- 【廖雪峰python入門筆記】list新增元素_append()和insert()Python筆記APP
- MySQL 關於 INSERT INTO...ON DUPLICATE KEY UPDATE 的使用MySql
- MySQL防止重複插入相同記錄 insert if not existsMySql
- 通過append hint來插入資料,演示它和普通插入資料的效能比較。APP
- 【MyBatis】幾種批量插入效率的比較MyBatis
- insert into select
- 二分搜尋樹系列之[ 插入操作 (insert) ]
- 二分搜尋樹系列之「 插入操作 (insert) 」
- Oracle insert all一次插入多個表中Oracle
- insert all和insert first語句的用法
- insert images to a plot
- E - Insert or Erase
- SQL__INSERTSQL
- PostgreSQL 原始碼解讀(4)- 插入資料#3(heap_insert)SQL原始碼
- SQL INSERT INTO 語句詳解:插入新記錄、多行插入和自增欄位SQL
- ArrayList宣告,Add(), Insert();
- SQLite Insert 語句SQLite
- leetcode–57–Insert IntervalLeetCode
- MySQL:關於RR模式下insert..selcet sending data狀態說明MySql模式
- mysql insert的特殊用法MySql
- lightdb -- merge into insert 相容 OracleOracle
- 1089 Insert or Merge (25分)
- mysql insert導致死鎖MySql
- insert()與substr()函式函式
- LeetCode之Insert Interval(Kotlin)LeetCodeKotlin
- Leetcode 35 Search Insert PositionLeetCode
- SQLite 之 INSERT OR REPLACE使用SQLite
- [20180907]insert+with+select.txt
- insert和insertSelective區別
- Oracle-insert into加日期Oracle
- JS嵌入html的方式及各種方式的比較JSHTML
- 各種富文字/ HTML編輯器和框架比較HTML框架
- 鍵盤insert操作怎麼取消?電腦鍵盤insert操作取消教程