Subject trigger transaction deadlock problem
Author martinthrelly
hello

i have recently implemented some calculation logic into our database.
the basic flow is like this:

> INSERT RECORD STORED PROCEDURE ON TABLE 'ENTRY'
> CALLS AFTER INSERT TRIGGER FOR TABLE 'ENTRY'
> CALLS STORED PROCEDURE TO UPDATE TABLE 'CALCS1'
> CALLS AFTER UPDATE TRIGGER FOR TABLE 'CALCS1'
> CALLS STORED PROCEDURE TO UPDATE TABLE 'CALCS2'

i have discovered this is causing a deadlock when several people try
to enter entries for the same types concurrently. i have a few
questions relating to this, and would be grateful for any assistance.

1. I assume that even though the above operations contains both
triggers and stored procedure calls, they are wrapped in the same
transaction. therefore a subsequent rollback will rollback changes
made by both the SP's and the triggers?

2. my conclusion is that i must handle this situation by either
changing the transaction isolation level, or by handling the resulting
deadlock exception and performing a retry. is this correct?

3. we are using the standard .NET ReadCommitted transaction isolation
level so far. this has not caused any deadlocks before we did this
calculation logic because the other transactions are all quick and
simple. yet even on these my thinking is that i should still be
handling potential deadlocks and doing retries? (this is why Q1 is so
important because i dont want duplicated data due to retries with
partial rollbacks).

i have purchased the firebird book and this is my assessment of the
situation. i would be grateful for confirmation. thanks.