Home » SQL & PL/SQL » SQL & PL/SQL » DeadLock giving trouble!!!!!! Very urgent !!!!
DeadLock giving trouble!!!!!! Very urgent !!!! [message #20542] Mon, 03 June 2002 21:04 Go to next message
K. Prakash babu
Messages: 46
Registered: July 2001
Member
In my databae i hv 200 tables. Table TAB1 is having around 10 child tables. The problem is..........
In my application so many concurrent users are trying to insert records in this table, usually deadlock is happening and it is released whenever the previous user committed. But in this application to complete a DML we need to full fill the order of inserting from Parent to Child. So it is taking some time to execute a DML for a single user...........................
like this
IF LET US SAY 50 USERS ARE CONCURENTLY DOING THE SAME...THE 50th USER HAS TO WAIT TILL THE 49th USER TO BE COMMITTED. THIS IS THE WORST SITUATION WE ARE FACING.
CAN ANYBODY HAVE THE SOLUTION.
Re: DeadLock giving trouble!!!!!! Very urgent !!!! [message #20556 is a reply to message #20542] Tue, 04 June 2002 10:20 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
An insert NEVER locks a table to other DML. Other sessions can't see the records until the session doing the insert has committed.

Run sql_trace on your transaction or examine the SQL statements to check for:
* Update (and delete - although that's not likely to be in your transaction is it?)
* select ... FOR UPDATE; (FOR UPDATE locks the rows returned by the query until you commit/rollback).

You say there are 10 child tables. If these child tables are using referential integrity constraints (which they should) -- then Make extra sure that your foreign keys are indexed! If you don't, then locking a single record in the parent table will lock the entire child table -- not just the corresponding child records. This makes sense as the only way Oracle would be able to determine what the child rows are - is to scan the entire table for them. On a large table this would slow the app to a crawl - so it locks the entire table.

On your parent table, try this:
select * from dept where deptno=10 for update;

Then, from a different session - try to lock a different row on the child table:
select * from emp where deptno=20 for update nowait;

If you can't get the lock - try commit/or rollback from the first session and then try again.

Remember that you need to consider all child tables - not just the first level.

Run this query to find unindexed FK's:
select decode( b.table_name, NULL, '****', 'ok' ) Status,
a.table_name, a.columns, b.columns
from
( select substr(a.table_name,1,30) table_name,
substr(a.constraint_name,1,30) constraint_name,
max(decode(position, 1, substr(column_name,1,30),NULL)) ||
max(decode(position, 2,', '||substr(column_name,1,30),NULL)) ||
max(decode(position, 3,', '||substr(column_name,1,30),NULL)) ||
max(decode(position, 4,', '||substr(column_name,1,30),NULL)) ||
max(decode(position, 5,', '||substr(column_name,1,30),NULL)) ||
max(decode(position, 6,', '||substr(column_name,1,30),NULL)) ||
max(decode(position, 7,', '||substr(column_name,1,30),NULL)) ||
max(decode(position, 8,', '||substr(column_name,1,30),NULL)) ||
max(decode(position, 9,', '||substr(column_name,1,30),NULL)) ||
max(decode(position,10,', '||substr(column_name,1,30),NULL)) ||
max(decode(position,11,', '||substr(column_name,1,30),NULL)) ||
max(decode(position,12,', '||substr(column_name,1,30),NULL)) ||
max(decode(position,13,', '||substr(column_name,1,30),NULL)) ||
max(decode(position,14,', '||substr(column_name,1,30),NULL)) ||
max(decode(position,15,', '||substr(column_name,1,30),NULL)) ||
max(decode(position,16,', '||substr(column_name,1,30),NULL)) columns
from user_cons_columns a, user_constraints b
where a.constraint_name = b.constraint_name
and b.constraint_type = 'R'
group by substr(a.table_name,1,30), substr(a.constraint_name,1,30) ) a,
( select substr(table_name,1,30) table_name, substr(index_name,1,30) index_name,
max(decode(column_position, 1, substr(column_name,1,30),NULL)) ||
max(decode(column_position, 2,', '||substr(column_name,1,30),NULL)) ||
max(decode(column_position, 3,', '||substr(column_name,1,30),NULL)) ||
max(decode(column_position, 4,', '||substr(column_name,1,30),NULL)) ||
max(decode(column_position, 5,', '||substr(column_name,1,30),NULL)) ||
max(decode(column_position, 6,', '||substr(column_name,1,30),NULL)) ||
max(decode(column_position, 7,', '||substr(column_name,1,30),NULL)) ||
max(decode(column_position, 8,', '||substr(column_name,1,30),NULL)) ||
max(decode(column_position, 9,', '||substr(column_name,1,30),NULL)) ||
max(decode(column_position,10,', '||substr(column_name,1,30),NULL)) ||
max(decode(column_position,11,', '||substr(column_name,1,30),NULL)) ||
max(decode(column_position,12,', '||substr(column_name,1,30),NULL)) ||
max(decode(column_position,13,', '||substr(column_name,1,30),NULL)) ||
max(decode(column_position,14,', '||substr(column_name,1,30),NULL)) ||
max(decode(column_position,15,', '||substr(column_name,1,30),NULL)) ||
max(decode(column_position,16,', '||substr(column_name,1,30),NULL)) columns
from user_ind_columns
group by substr(table_name,1,30), substr(index_name,1,30) ) b
where a.table_name = b.table_name (+)
and b.columns (+) like a.columns || '%';
Previous Topic: How to Append text to a data in a column
Next Topic: Compare table from two Instances
Goto Forum:
  


Current Time: Thu Apr 25 02:50:56 CDT 2024