block為1,阻塞會(huì)話。 可以看出,對(duì)于表存在主鍵或者 unique index 時(shí),一個(gè)會(huì)話操作主鍵不提交時(shí),其他會(huì)話如果也操作相同的主鍵時(shí),那么必須進(jìn)行等待,而其持有的mode=4;而阻塞blocker的持有mode=6.
2、Bitmap INDEX session 1: SQL> select * from t1_tx;
ID NAME ---------- -------------------- 1 wang 2 wang 3 xxoo 4 xxoo
SQL> SQL> select sid from v$mystat where rownum=1;
SID ---------- 74
SQL> create bitmap index idx_bitmap_name on t1_tx(name);
Index created.
SQL> update t1_tx set name='tx' where id=3;
1 row updated.
未提交。。。。。。。。。。。
session 2: SQL> select sid from v$mystat where rownum=1;
SID ---------- 45
SQL> update t1_tx set name='bitmap' where id=4;
hang。。。。。。。。。。。。。
session 3: SQL> col event for a30 SQL> select inst_id, 2 sid, 3 chr(bitand(p1, -16777216) / 16777215) || 4 chr(bitand(p1, 16711680) / 65535) "Name", 5 (bitand(p1, 65535)) "Mode", 6 event, 7 sql_id, 8 blocking_session, 9 FINAL_BLOCKING_SESSION 10 from gv$session 11 where event like 'enq%';
SQL> SQL> set lines 200 pagesize 200 SQL> select * from table(dbms_xplan.display_cursor('&sql_id', NULL, 'ALL')); Enter value for amp: 7wanaturqndn1 old 1: select * from table(dbms_xplan.display_cursor('&sql_id', NULL, 'ALL')) new 1: select * from table(dbms_xplan.display_cursor('7wanaturqndn1;sql_id', NULL, 'ALL'))
PLAN_TABLE_OUTPUT ---------------------------------------------------------------------------------------------- SQL_ID 7wanaturqndn1, child number 0 ------------------------------------- update t1_tx set name='bitmap' where id=4 Plan hash value: 1842098942 ----------------------------------------------------------------------------------- | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time | ----------------------------------------------------------------------------------- | 0 | UPDATE STATEMENT | | | | 1 (100)| | | 1 | UPDATE | T1_TX | | | | | |* 2 | INDEX UNIQUE SCAN| SYS_C0010951 | 1 | 25 | 1 (0)| 00:00:01 | -----------------------------------------------------------------------------------
session 1: SQL> select sid from v$mystat where rownum=1;
SID ---------- 45
SQL> select * from t1_tx;
ID NAME ---------- -------------------- 1 wang 2 wang 3 tx 4 bitmap
SQL> update t1_tx set name='enmotech' where id=2;
1 row updated.
SQL> commit;
Commit complete.
SQL>
session 2: SQL> select sid from v$mystat where rownum=1;
SID ---------- 74
SQL> update t1_tx set name='xyz'where id=4;
1 row updated.
SQL> commit;
Commit complete.
SQL>
即使我分別開2個(gè)會(huì)話執(zhí)行100w次,也不會(huì)出現(xiàn)tx鎖 session 1: SQL> declare 2 c number; 3 begin 4 for i in 1 .. 1000000 loop 5 update t1_tx set name = 'shit1' where id = 2; 6 end loop; 7 end; 8 /
PL/SQL procedure successfully completed.
SQL>
session 2: SQL> declare c number; 2 begin 3 for i in 1 .. 1000000 loop 4 update t1_tx set name = 't-shit' where id = 3; 5 end loop; 6 end; 7 / PL/SQL procedure successfully completed.
SQL>
session 3: SQL> set lines 200 pages 999 SQL> col event for a60 SQL> select inst_id,event,count(*) from gv$session where status='ACTIVE' and (wait_class<>'Idle' or event not like 'SQL*Net%') group by inst_id,event order by 1,3;