Deleting 1 record is taking 4:30 minutes

  • Hi all,

    I am experiencing an issue when deleting a record.

    use MyDatabase

    go

    delete from dbo.MyTable

    where id = 174

    It is taking a very long time. I can see that it is creating several locks. any ideas?

    Thank you so much!

  • first thing, is it blocked by any other processes?

    ---------------------------------------------------------------------

  • No it is not block by anyother process.

  • then please post more info, such as table schema, size of table, execution plan.

    you say delete A record, are you sure only one record meets that criteria?

    ---------------------------------------------------------------------

  • I attached the execution plan and the table schema. This table is less than 200 records. Yes I am sure there is only one record with that criteria. The database is also in simple recovery model.

    Thank you!

  • Take a look at the other tables referred to in the execution plan.

    I suspect that these have a foreign key reference to the table you trying to delete from, and not all of these tables have an index to support the foreign key. SQL Server is therefore having to resort to clustered index scans (and some of those tables will be large) to make sure there is nothing referencing the row you are trying to delete.

  • Ian Scarlett

    Thank you for the reply.

    I already check all those tables and they do have a foreign key in reference to that table. All the tables have indexes to support the foreing key, however, the indexex are compose index with one being that foreing key plus another field.

  • Run the delete from SSMS with "SET STATISTICS IO ON"

    Look at the statistics, and that should tell you which table(s) are causing excessive IO

  • Ian Scarlett

    these are the two tables with excessive IO:

    Table 'MyValueR'. Scan count 1, logical reads 27179, physical reads 5, read-ahead reads 27173, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

    Table 'MyValue'. Scan count 1, logical reads 818211, physical reads 0, read-ahead reads 698578, lob logical reads 0, lob physical reads 0, lob read-ahead reads 0.

    Both of these tables contains conposite indexes including the reference of the FK.

    Thanks

  • If the FK column isn't the first column of the composite index, then SQL Server will revert to clustered index or table scans, which is what you are getting.

    I wouldn't re-order the existing index(es), as they are probably there to satisfy other queries, so add another index, with just the FK column.

  • That worked! Thank you so much! 😛

  • JohnDBA (6/29/2009)


    That worked! Thank you so much! 😛

    You're welcome:-)

Viewing 12 posts - 1 through 11 (of 11 total)

You must be logged in to reply to this topic. Login to reply