Domanda

I'm having issues with timeouts of a table on mine.

Example table:

Id BIGINT, 
Token uniqueidentifier, 
status smallint, 
createdate datetime, 
updatedate datetime

I'm inserting data into this table from 2 different stored procedures that are wrapped with transaction (with specific escalation) and also 1 job that executes once every 30 secs.

I'm getting timeout from only 1 of them, and the weird thing that its from the simple one

BEGIN TRY
BEGIN TRAN
   INSERT INTO [dbo].[TempTable](Id, AppToken, [Status], [CreateDate], [UpdateDate])
   VALUES(@Id, NEWID(), @Status, GETUTCDATE(), GETUTCDATE() )
   COMMIT TRAN
END TRY 
BEGIN CATCH
   IF @@TRANCOUNT > 0 
      ROLLBACK TRAN;
END CATCH

When there is some traffic on this table (TempTable) this procedure keeps getting timeout.

I checked the execution plan and it seems I haven't missed any indexes in both stored procedures.

Also, the only index on TempTable is the clustered PK on Id.

Any ideas?

If more information is needed, do tell.

The 2nd stored procedure using this table isn't causing any big IO or something.

The job, however, uses an atomic UPDATE on this table and in the end of it DELETEs from the table, but as I checked on high IO of this table, the job takes no longer than 3 secs.

Thanks.

È stato utile?

Soluzione

It is most propably because some other process is blocking your insert operation, It could be another insert, delete , update or some trigger or any other sql statement.

To find out who is blocking your operation you can use some esaily avialable stored procedures like

  1. sp_who2
  2. sp_whoIsActive (My Preferred)

While your insert statement is being executed/hung up execute one of these procedures and see who is blocking you.

In sp_who2 you will see a column by the name Blk_by get the SPID from that column and execute the following query

DBCC INPUTBUFFER(71);
GO

This will reutrn the last query executed by that process id. and it is not very well formatted the sql statement, all the query will be in one single line you will need to format it in your SSMS to acutally be able to read it.

On the other hand sp_WhoIsActive will only return the queries that are blocking other process and will have the query formatted just as the user has execute it. Also it will give you the execution plan for that query.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top