Jan 13, 2015

Bitmap index exclusive lock on table (oracle database)

Updating table with bitmap index creates an exclusive lock on table. But only happens in the scope of the same cardinality.

E.g. insert of "Y" and "N" into a bitmap index column can happen independently, but insert "N" and "N" in different session would create a deadlock.

-- create table t
create table t (processed_flag varchar2 (1));

-- create bitmap index on tcreate bitmap index t_idx on t (processed_flag);

set pagesize 5000;
set linesize 200;
col username format a10
col owner format a10
col object_name format a20
col machine format a20

-- view locking sessions
select t2.username, t3.owner, t3.object_name, t2.machine, t2.sid as sid, t2.serial#, t2.last_call_et, t2.program, t1.locked_mode from v$locked_object t1, v$session t2, dba_objects t3 where t1.session_id = t2.sid and t1.object_id = t3.object_id order by t2.logon_time;

-- 202, 75

-- view event of waiting locked session
select sid, event from v$session_wait where sid = 202;
select sid, event from v$session_wait where sid = 75;

-- view statement of current lock session
select /* + NO_MERGE (a) NO_MERGE (b) NO_MERGE (c) */ a.username, a.machine, a.sid, a.serial#, a.last_call_et "Seconds", b.id1, c.sql_text "SQL" from v$session a, v$lock b, v$sqltext c where a.username is not null and a.lockwait = b.kaddr and c.hash_value = a.sql_hash_value;

No comments: