Skip to Main Content
  • Questions
  • Deadlock issue came while using set based sql

Breadcrumb

Question and Answer

Chris Saxon

Thanks for the question, kuruba.

Asked: October 17, 2018 - 11:39 am UTC

Last updated: October 17, 2018 - 2:20 pm UTC

Version: oracle 11g

Viewed 1000+ times

You Asked

Hi Tom,
We are using set based sql in my process, In that we are creating so many GTT tables in a package. And we are executing this package concurrently in more than ten sessions, these sessions will create temporary tables with different name and we're encountering with this following error once in a while
ORA-00060: deadlock detected while waiting for resource
Please refer the following dead graph and it would be very grateful if you could give us a solution for this issue.

Deadlock graph:
---------Blocker(s)-------- ---------Waiter(s)---------
Resource Name process session holds waits process session holds waits
TX-00500004-00772129 254 3699 X 896 4258 S
TX-00550006-006a22b4 896 4258 X 254 3699 S

session 3699: DID 0001-00FE-0006362E session 4258: DID 0001-0380-000284EB
session 4258: DID 0001-0380-000284EB session 3699: DID 0001-00FE-0006362E

Rows waited on:
Session 3699: obj - rowid = 00000000 - D/////An8AADLQbAAA
(dictionary objn - 0, file - 2556, block - 832539, slot - 0)
Session 4258: obj - rowid = 001B1566 - AAGxVmA8DAABV8qAAA
(dictionary objn - 1774950, file - 3843, block - 352042, slot - 0)

----- Information for the OTHER waiting sessions -----
Session 4258:
sid: 4258 ser: 28139 audsid: 77875022 user: 402/MFPR
flags: (0x310041) USR/- flags_idl: (0x1) BSY/-/-/-/-/-
flags2: (0x48009) -/DDLT2/INC
pid: 896 O/S info: user: oracle, term: UNKNOWN, ospid: 72144
image: oracle@KURINJI (J006)
client details:
O/S info: user: oracle, term: UNKNOWN, ospid: 72144
machine: KURINJI program: oracle@KURINJI (J006)
application name: MFPRTRAILER_FEE, hash value=1360404787
action name: TRL-SISep1998, hash value=3252358592
current SQL:
insert into col$(obj#,name,intcol#,segcol#,type#,length,precision#,scale,null$,offset,fixedstorage,segcollength,deflength,default$,col#,property,charsetid,charsetform,spare1,spare2,spare3)values(:1,:2,:3,:4,:5,:6,decode(:5,182/*DTYIYM*/,:7,183/*DTYIDS*/,:7,decode(:7,0,null,:7)),decode(:5,2,decode(:8,-127/*MAXSB1MINAL*/,null,:8),178,:8,179,:8,180,:8,181,:8,182,:8,183,:8,231,:8,null),:9,0,:10,:11,decode(:12,0,null,:12),:13,:14,:15,:16,:17,:18,:19,:20)

----- End of information for the OTHER waiting sessions -----

Information for THIS session:

----- Current SQL Statement for this session (sql_id=60uw2vh6q9vn2) -----
insert into col$(obj#,name,intcol#,segcol#,type#,length,precision#,scale,null$,offset,fixedstorage,segcollength,deflength,default$,col#,property,charsetid,charsetform,spare1,spare2,spare3)values(:1,:2,:3,:4,:5,:6,decode(:5,182/*DTYIYM*/,:7,183/*DTYIDS*/,:7,decode(:7,0,null,:7)),decode(:5,2,decode(:8,-127/*MAXSB1MINAL*/,null,:8),178,:8,179,:8,180,:8,181,:8,182,:8,183,:8,231,:8,null),:9,0,:10,:11,decode(:12,0,null,:12),:13,:14,:15,:16,:17,:18,:19,:20)
----- PL/SQL Stack -----
----- PL/SQL Call Stack -----
object line object
handle number name
0x798307ef30 15148 package body MFPR.PKG_TRAIL_FEE_COMPUTATION_GTT
0x798307ef30 23947 package body MFPR.PKG_TRAIL_FEE_COMPUTATION_GTT
0x790d4a7270 1 anonymous block
===================================================


and Chris said...

we are creating so many GTT tables in a package

This is the source of your problem. It's creating GTTs that's causing the deadlock. The SQL that's causing the deadlock is generated when do this. On 11.2:

create global temporary table gtt (
  c1 int
);

select substr ( sql_text, 1, 50 ) 
from   v$sql
where  sql_id = '60uw2vh6q9vn2';

SUBSTR(SQL_TEXT,1,50)                                
insert into col$(obj#,name,intcol#,segcol#,type#,l  


Regularly creating and dropping tables in Oracle Database is a Bad Idea.*

You create a GTT ONCE. Period.

So strip all the DDL out of your code and your problem should go away!

* 18c introduced private temporary tables. These you can create in every session. In fact, you need to. But you need to be on 18 to use these!

Is this answer out of date? If it is, please let us know via a Comment

More to Explore

Design

New to good database design? Check out Chris Saxon's full fundamentals class.