all groups > sql server programming > october 2005 >
You're in the

sql server programming

group:

deadlock on tempdb..sysindexes


deadlock on tempdb..sysindexes Saxon
10/16/2005 11:50:03 PM
sql server programming:
Greetings,

I have stored procedure dumping resultset into created temporary table.
Every 15-30 minutes we have deadlock and always on sysindexes in tempdb.

Problem is I that can not change stored procedure and not sure how to stop
locking sysindexes since stored proc will take between 5-15 seconds to run
depending on date range supplied.

I would appreciate any suggestions how to resolve this issue

PS: Code goes like this

create table #temp(....)
insert into #temp
execute sp_StoredProc
--
Re: deadlock on tempdb..sysindexes Brian Selzer
10/17/2005 7:12:57 AM
The problem appears to be that the stored procedure is executing within a
transaction. This is unavoidable, since the INSERT...EXEC statement starts
a transaction prior to executing the procedure. To avoid the deadlocks, you
MUST alter the stored procedure. If you can't alter it, then make a copy
and alter that. Change the procedure so that it executes an INSERT
statement into the temp table. (If a temp table is created before executing
the stored procedure, it is available within the body of the stored
procedure.) This will eliminate the transaction

You should avoid creating, altering or deleting temporary objects within a
transaction. This includes both tables, indexes and constraints. You
should avoid executing procedures within a transaction. For this reason, I
generally avoid INSERT...EXEC.


[quoted text, click to view]

Re: deadlock on tempdb..sysindexes Saxon
10/17/2005 4:35:05 PM
Thanks Brian,

so basically if I create temp table and call stored proc to insert into
table instead of using INSERT... EXEC it would not cause deadlock since no
transactions would be started.

PS: Why inserting into temp table would hold lock on sysindexes anyway? I
tried to find some info on that but no luck.

Regards

--
Saxon


[quoted text, click to view]
Re: deadlock on tempdb..sysindexes Saxon
10/17/2005 6:13:02 PM
Thank you kindly Brian.

Much appreciated.

Regards

Saxon


[quoted text, click to view]
Re: deadlock on tempdb..sysindexes Brian Selzer
10/17/2005 9:01:38 PM
The lock isn't caused by inserting, it's caused by creating, altering, or
deleting a temporary object within the procedure! The problem is that
normally, when a procedure runs, any transactions must be explicitly started
within the body of the proc. INSERT...EXEC wraps the procedure call in a
transaction. There are several articles on MSDN about lock contention and
blocking--some cite concurrency issues with tempdb. (There are fixes for
that in SP4.)

[quoted text, click to view]

Re: deadlock on tempdb..sysindexes Hugo Kornelis
11/23/2005 12:00:00 AM
[quoted text, click to view]

Hi winther,

Yes. Every modification is automatically part of a transaction. If you
didn't start one explicitly, it will be started implicitly.

If SET IMPLICIT_TRANSACTION is OFF, the implicitly started transaction
will also be implicitly committed after each statement. With this
setting to ON, the server waits for an explicit COMMIT or ROLLBACK to
end the transaction.

Best, Hugo
--

Re: deadlock on tempdb..sysindexes winther
11/23/2005 3:36:11 AM
Thanks for this useful description of the problem.

If we creates at temporary table in the procedure and fill data into it with
a function, will that cause a transaction too?

create table #temp(....)
insert into #temp SELECT x, y FROM (udf_MyTableFunction1)



[quoted text, click to view]
Re: deadlock on tempdb..sysindexes Brian Selzer
11/23/2005 3:37:31 PM
There will be a transaction, but it won't put a lock on sysindexes because
the create table occurs apart from the transaction started for the insert.

[quoted text, click to view]

AddThis Social Bookmark Button