首页 > 数据库 > Oracle > /*+append*/
A>insert /*+append*/ into t1 select * from dba_users;
15 rows created.
A>insert into t1 select * from dba_users;
15 rows created.
A>select sid,type,id1,id2,lmode,request,block from v$lock where sid=1;
SID TY ID1 ID2 LMODE REQUEST BLOCK
---------- -- ---------- ---------- ---------- ---------- ----------
1 AE 100 0 4 0 0
1 TM 59051 0 3 0 0 //常规插入时加的是3号锁
1 TX 262175 501 6 0 0
A>insert /*+append*/ into t1 select * from dba_users;
15 rows created.
A>select sid,type,id1,id2,lmode,request,block from v$lock where sid=1;
SID TY ID1 ID2 LMODE REQUEST BLOCK
---------- -- ---------- ---------- ---------- ---------- ----------
1 AE 100 0 4 0 0
1 TM 59051 0 6 0 0 //改成APPEND插入后变成了6号锁
1 TX 262175 501 6 0 0
此后无论是常规插入,APPEND插入,还是更新删除操作,一律失败,原因都是6号排它锁
A>insert /*+append*/ into t1 select * from dba_users;
insert /*+append*/ into t1 select * from dba_users
*
ERROR at line 1:
ORA-12838: cannot read/modify an object after modifying it in parallel
A>insert into t1 select * from dba_users;
insert into t1 select * from dba_users
*
ERROR at line 1:
ORA-12838: cannot read/modify an object after modifying it in parallel
A>update t1 set user_id=1;
update t1 set user_id=1
*
ERROR at line 1:
ORA-12838: cannot read/modify an object after modifying it in parallel
A>delete from t1;
delete from t1
*
ERROR at line 1:
ORA-12838: cannot read/modify an object after modifying it in parallel
最后要注意的就是hint的写法,其中多一个空格也不行,尤其是在+前面
A>insert into t1 select * from dba_users;
15 rows created.
A>insert /* +append */ into t1 select * from dba_users; //+append前后都有空格,没问题
15 rows created.
A>insert /* +append*/ into t1 select * from dba_users; //+append前面有空格,后边没空格,没问题
15 rows created.
A>insert /*+append */ into t1 select * from dba_users; //+append前面没空格,后面有,不行了,锁变成6号了,换句话说,这种写法可能才是正确
15 rows created.
A>insert /*+append*/ into t1 select * from dba_users; //当然了,+append前后都没有,也是加的6号锁
insert /*+append*/ into t1 select * from dba_users
*
ERROR at line 1:
ORA-12838: cannot read/modify an object after modifying it in parallel
总结
关于APPEND有两点要注意:1.使用/*+APPEND*/后会在表上加6号排它锁
2.注意/*+APPEND*/中,/*和+号之间不能有空格,否则就不是APPEND方式了
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29646619/viewspace-1163324/ ,如需转载,请注明出处,否则将追究法律责任。