How many times I heard and read that it is absolutely not conceivable to create bitmap indexes into a heavy OnLine Transactional Process (OLTP) application into tables that are subject to concurrent DML operations. The main reason for that is because of the deadlock threat the bitmap indexes can throw into this kind of applications. The purpose of this article, in its first part, is mainly to show how to identify, via the deadlock graph that the deadlock you are experiencing is due to a bitmap index in an OLTP system.
Here below is a deadlock graph automatically generated from a real life OLTP production application I have been asked to have a close look to:
[Transaction Deadlock] The following deadlock is not an ORACLE error. It is a deadlock due to user error in the design of an application or from issuing incorrect ad-hoc SQL. The following information may aid in determining the deadlock: Deadlock graph: ---------Blocker(s)-------- ---------Waiter(s)--------- Resource Name process session holds waits process session holds waits TX-0017000b-0000a507 26 164 X 50 160 S TX-0037000e-000081cc 50 160 X 26 164 S
This is the most fundamental and the first information that should retain your attention: we have two sessions 164 and 160 dead-locking each other. They are both Transaction Enqueues (TX) held on X mode and waited on S mode
Immediately when you see TX held on X mode and waited on S mode you can think of one of the following possibilities which triggered this deadlock
1. Existence of Bitmap indexes into your OLTP application
2. Primary key or unique key constraint overlapping during insert statement
The next bit of information within the deadlock graph will help you identifying the real cause as I did in this application. You need to look to the Sql statements done by the two sessions as shown below:
Information on the OTHER waiting sessions: Session 160: pid=50 serial=9778 audsid=49307085 user: 54/S102 O/S info: user: SYS_XXX-ZZZ, term: wyannhhF103, ospid: 6592:3660, machine: lkti\HJKULOO03 program: xye.exe application name: xye.exe, hash value=2799981571 Current SQL Statement: DELETE xxx_real_life_table WHERE xxx_ID = :B1 End of information on OTHER waiting sessions. Current SQL statement for this session: INSERT INTO yyy_real_life_table (yyy_ID ,DET_ID,xxx_ID) VALUES (yyy__SEQ.NEXTVAL ,0 ,:B23 ) ----- PL/SQL Call Stack -----
As far as session 160 was doing a delete operation while session 164 was doing an insert operation it is impossible that for this deadlock to be caused by primary key or unique key overlapping values. It remains for me only to check the existence of the bitmap indexes into this application.
sql.world> SELECT count(1) 2 FROM all_indexes 3 WHERE index_type = 'BITMAP'; COUNT(1) ---------- 10
I then have dropped those bitmap indexes making the deadlock disappear. I have also asked the local developer to explain me why they’ve created bitmap indexes into tables subject to heavy DML operation; their answer was that all those indexes are on a flag processed which have only two values : Y and N and they told me this is why they opted for this kind of bitmap indexes. My answer for them was this: