Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12963

SPID Blocking itself with Sch-S on a table variable.

$
0
0

OK,

 

Here is the problem. I have a SPID that was blocking itself. When you try and kill this SPID it returns the message;

 

"SPID 120: transaction rollback in progress. Estimated rollback completion: 0%. Estimated time remaining: 0 seconds"

 

When looking at this SPID in sys.sysprocesses I can see that the blocking SPID is itself.  The last wait type is LCK_M_SCH_M with a wait type of 0x0002.

 

When looking at the locks by process i can see that in tempdb Owner ID 2063795945 has taken out a Sch-S lock on Object ID 958657192. In the same process there is Owner ID 2063803448 which is waiting to obtain a Sch-M lock on the same object (958657192). This lock request has a Request Status of WAIT.

 

This SPID executed a stored procedure which calls a user defined table value function that splits a comma delimited string into a table variable and returns a table with an integer Column type. The code for this can be seen at the foot of this post.

 

BOL states that Schema stability (Sch-S) locks are used when compiling queries. This lock does not block any transactional locks, but when the Schema stability (Sch-S) lock is used, the DDL operations cannot be performed on the table. Because the table variable definition cannot be changed after the initial DECLARE statement and you cannot drop a table variable WHY is it trying to obtain a Sch-M on that object?!

 

It is the table variable within this function that the process is trying to obtain the Sch-M lock.

 

With this in mind, I have a few of questions.

 

1. Is there any other way of removing this SPID without restarting the service, obviously the KILL statement is not going to work.

 

2. What does the Owner ID in Activity Monitor "Lock By Process" refer to? Is there any way i can trace this back further to establish what has happened

 

3. How can more than one Owner ID exist within the same process when in BOL it states that the owner id is “The owner ID associated with the process”

 

4. How can a process block itself on a table variable in tempdb?

 

Thanks in advance for any help you might be able to offer.

 

Phil Harbour

 

 

FYI

 

dbcc inputbuffer (120,2)

RPC Event 0 dbo.<MyProcName>;1

 

Table Function

 

 
 declare @separator char(1) 
 select @separator = ',' 

 declare @separator_position int  
 declare @array_value varchar(1000)  

 set @array = @array + ',' 

 while patindex('%,%' , @array) <> 0  
 begin 
  select @separator_position =  patindex('%,%' , @array) 
  select @array_value = left(@array, @separator_position - 1) 

  insert @IntTable 
  select (cast(@array_value as int)) 

  select @array = stuff(@array, 1, @separator_position, '') 
 end 


Viewing all articles
Browse latest Browse all 12963

Trending Articles