在SQL Server中删除240行11秒

[英]11 seconds to delete 240 rows in SQL Server


i am running a delete statement:

我正在运行删除声明:

DELETE FROM TransactionEntries
WHERE SessionGUID = @SessionGUID

The actual execution plan of the delete is:

删除的实际执行计划是:

Execution Tree
--------------
Clustered Index Delete(
   OBJECT:([GrobManagementSystemLive].[dbo].[TransactionEntries].IX_TransactionEntries_SessionGUIDTransactionGUID]), 
   WHERE:([TransactionEntries].[SessionGUID]=[@SessionGUID])
)

The table is clustered by SessionGUID, so the 240 rows are physically together.

该表由SessionGUID聚类,因此240行在物理上在一起。

The table has no triggers on it.

该表没有触发器。

The operation takes:

该操作需要:

  • Duration: 11821 ms
  • 持续时间:11821毫秒
  • CPU: 297
  • CPU:297
  • Reads: 14340
  • 阅读:14340
  • Writes: 1707
  • 写道:1707

The table contains 11 indexes:

该表包含11个索引:

  • 1 clustered index (SessionGUID)
  • 1个聚簇索引(SessionGUID)
  • 1 unique (primary key) index
  • 1个唯一(主键)索引
  • 9 other non-unique, non-clustered indexes
  • 9个其他非唯一的非聚集索引

How can i figure out why this delete operation is performing 14,340 reads, and takes 11 seconds?

我怎么能弄清楚为什么这个删除操作执行14,340读取,需要11秒?

  • the Avg. Disk Read Queue Length reaches 0.8
  • 平均磁盘读取队列长度达到0.8
  • the Avg. Disk sec/Read never exceeds 4ms
  • 平均磁盘秒/读取不会超过4毫秒
  • the Avg. Disk Write Queue Length reaches 0.04
  • 平均磁盘写入队列长度达到0.04
  • the Avg. Disk sec/Write never exceeds 4ms
  • 平均磁盘秒/写永远不会超过4毫秒

What are the other reads for? The execution plan gives no indication of what it's reading.

其他读物有哪些?执行计划没有说明它正在阅读什么。


Update:

更新:

EXECUTE sp_spaceused TransactionEntries

TransactionEntries  
  Rows      6,696,199
  Data:     1,626,496 KB (249 bytes per row)
  Indexes:  7,303,848 KB (1117 bytes per row)
  Unused:      91,648 KB    
            ============
  Reserved: 9,021,992 KB (1380 bytes per row)

With 1,380 bytes per row, and 240 rows, that's 340 kB to be deleted.

每行1,380字节,240行,即删除340 kB。

Counter intuitive that it can be so difficult for 340 kB.

反直觉,340 kB可能会如此困难。

Update Two: Fragmentation

更新二:碎片

Name                           Scan Density  Logical Fragmentation
=============================  ============  =====================
IX_TransactionEntries_Tran...  12.834        48.392
IX_TransactionEntries_Curr...  15.419        41.239
IX_TransactionEntries_Tran...  12.875        48.372
TransactionEntries17           98.081         0.0049325
TransactionEntries5            12.960        48.180
PK_TransactionEntries          12.869        48.376
TransactionEntries18           12.886        48.480
IX_TranasctionEntries_CDR...   12.799        49.157
IX_TransactionEntries_CDR...   12.969        48.103
IX_TransactionEntries_Tra...   13.181        47.127

i defragmented TransactionEntries17

我对TransactionEntries17进行了碎片整理

DBCC INDEXDEFRAG (0, 'TransactionEntries', 'TransactionEntries17')

since INDEXDEFRAG is an "online operation" (i.e. it only holds IS Intent Shared locks). i was going to then manually defragment the others until the business operations called, saying that the system is dead - and they switched to doing everything on paper.

因为INDEXDEFRAG是一个“在线操作”(即它只持有IS Intent共享锁)。我打算对其他人进行手动碎片整理,直到业务操作调用,说系统已经死了 - 他们转而在纸上做所有事情。

What say you; 50% fragmentation, and only 12% scan density, cause horrible index scan performance?

怎么说你; 50%的碎片,只有12%的扫描密度,导致可怕的索引扫描性能?

3 个解决方案

#1


5  

As @JoeStefanelli points out in comments, it's the extra non-clustered indexes.

正如@JoeStefanelli在评论中指出的那样,它是额外的非聚集索引。

You are deleting 240 rows from the table.

您正在从表中删除240行。

This equates to 2640 index rows, 240 of which include all fields in the table.

这相当于2640个索引行,其中240个包括表中的所有字段。

Depending on how wide they are and how many included fields you have, this could equate to all the extra read activity you are seeing.

根据它们的宽度和所包含的字段数量,这可能等同于您所看到的所有额外读取活动。

The non-clustered index rows will definitely NOT be grouped together on disk, which will increase delays.

非聚集索引行肯定不会在磁盘上组合在一起,这会增加延迟。

#2


1  

I think the indexing might be the likeliest culprit but I wanted to throw out another possibility. You mentioned no triggers, but are there any tables that have a foreign key relationship to this table? They would have to be checked to make sure no records are in them and if you have cascade delete turned on, those records would have to be deleted as well.

我认为索引可能是最有可能的罪魁祸首,但我想抛出另一种可能性。你提到没有触发器,但有没有任何表与这个表有外键关系?必须检查它们以确保其中没有记录,如果启用了级联删除,则还必须删除这些记录。

#3


1  

Having banged my head on many-a-SQL performance issue, my standard operating procedure for something like this is to:

在我的许多SQL性能问题上引起了轰动,我这样的标准操作过程是:

  1. Back up the data
  2. 备份数据
  3. Delete one of the indexes on the table in question
  4. 删除有问题的表上的一个索引
  5. Measure the operation
  6. 测量操作
  7. Restore DB
  8. 恢复数据库
  9. Repeat w/#2 until #3 shows a drastic change. That's likely your culprit.
  10. 重复w /#2直到#3显示出剧烈的变化。那可能是你的罪魁祸首。
智能推荐

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:http://www.silva-art.net/blog/2011/10/05/cdd58d7c4c198500e48f1a20183d9cd2.html



 
© 2014-2019 ITdaan.com 粤ICP备14056181号  

赞助商广告