SQL Server中删除查询的性能变慢

时间:2022-10-25 00:06:49

I have an application which is using Entity framework for DB operations. In an one table when performing the delete operation it takes more than 3 minutes. But other similar tables doesn't take much time. I have debugged the code and find out there is no issue with the code.But executing the query in the sql server took much time.

我有一个使用Entity框架进行数据库操作的应用程序。在执行删除操作的一个表中,它需要超过3分钟。但其他类似的表格并不需要太多时间。我调试了代码并发现代码没有问题。但是在sql server中执行查询需要花费很多时间。

Any troubleshooting steps/root cause for this issue ?

此问题的任何故障排除步骤/根本原因?

My table is as below,

我的桌子如下,

Id (PK,uniqueidentifier,not null)
FirstValue(real,not null)
SecondValue(real,not null)
ThirdValue(real,not null)
LastValue(int,not null)
Config_Id(FK,uniqueidentifier,not null)

Query Execution Plan SQL Server中删除查询的性能变慢

查询执行计划

1 个解决方案

#1


0  

Something isn't adding up here, we're not seeing the full picture...

有些东西没有在这里加起来,我们没有看到全貌......

There are a multitude of things which can slow down deletes (usually):

有很多东西可以减缓删除(通常):

  • deleting a lot of records (which we know isn't the case here)
  • 删除大量记录(我们知道这不是这里的情况)
  • many indexes (which I suspect IS the case here)
  • 很多索引(我怀疑这是这里的情况)
  • deadlocks and blocking (is this a development or production database?)
  • 死锁和阻塞(这是一个开发或生产数据库?)
  • triggers
  • 触发器
  • cascade delete
  • 级联删除
  • transaction log needing to grow
  • 需要增长的事务日志
  • many foreign keys to check (I suspect this might also be happening)
  • 许多外键要检查(我怀疑这可能也会发生)

Can you please give us a screenshot of the "View Dependencies" feature in SSMS? To get this, right click on the table in the object explorer and select View Dependencies.

你能否给我们一个关于SSMS中“查看依赖关系”功能的截图?要获得此功能,请右键单击对象资源管理器中的表,然后选择“查看依赖项”。

Also, can you open up a query on the master database, run the following queries and post the results:

此外,您是否可以在master数据库上打开查询,运行以下查询并发布结果:

SELECT name, value, value_in_use, minimum, maximum, [description], is_dynamic, is_advanced
FROM sys.configurations WITH (NOLOCK)
where name in (
    'backup compression default',
    'clr enabled',
    'cost threshold for parallelism',
    'lightweight pooling',
    'max degree of parallelism',
    'max server memory',
    'optimize for ad hoc workloads',
    'priority boost',
    'remote admin connections'
)
ORDER BY name OPTION (RECOMPILE);

SELECT DB_NAME([database_id]) AS [Database Name], 
       [file_id], [name], physical_name, [type_desc], state_desc,
       is_percent_growth, growth,
       CONVERT(bigint, growth/128.0) AS [Growth in MB], 
       CONVERT(bigint, size/128.0) AS [Total Size in MB]
FROM sys.master_files WITH (NOLOCK)
ORDER BY DB_NAME([database_id]), [file_id] OPTION (RECOMPILE);

#1


0  

Something isn't adding up here, we're not seeing the full picture...

有些东西没有在这里加起来,我们没有看到全貌......

There are a multitude of things which can slow down deletes (usually):

有很多东西可以减缓删除(通常):

  • deleting a lot of records (which we know isn't the case here)
  • 删除大量记录(我们知道这不是这里的情况)
  • many indexes (which I suspect IS the case here)
  • 很多索引(我怀疑这是这里的情况)
  • deadlocks and blocking (is this a development or production database?)
  • 死锁和阻塞(这是一个开发或生产数据库?)
  • triggers
  • 触发器
  • cascade delete
  • 级联删除
  • transaction log needing to grow
  • 需要增长的事务日志
  • many foreign keys to check (I suspect this might also be happening)
  • 许多外键要检查(我怀疑这可能也会发生)

Can you please give us a screenshot of the "View Dependencies" feature in SSMS? To get this, right click on the table in the object explorer and select View Dependencies.

你能否给我们一个关于SSMS中“查看依赖关系”功能的截图?要获得此功能,请右键单击对象资源管理器中的表,然后选择“查看依赖项”。

Also, can you open up a query on the master database, run the following queries and post the results:

此外,您是否可以在master数据库上打开查询,运行以下查询并发布结果:

SELECT name, value, value_in_use, minimum, maximum, [description], is_dynamic, is_advanced
FROM sys.configurations WITH (NOLOCK)
where name in (
    'backup compression default',
    'clr enabled',
    'cost threshold for parallelism',
    'lightweight pooling',
    'max degree of parallelism',
    'max server memory',
    'optimize for ad hoc workloads',
    'priority boost',
    'remote admin connections'
)
ORDER BY name OPTION (RECOMPILE);

SELECT DB_NAME([database_id]) AS [Database Name], 
       [file_id], [name], physical_name, [type_desc], state_desc,
       is_percent_growth, growth,
       CONVERT(bigint, growth/128.0) AS [Growth in MB], 
       CONVERT(bigint, size/128.0) AS [Total Size in MB]
FROM sys.master_files WITH (NOLOCK)
ORDER BY DB_NAME([database_id]), [file_id] OPTION (RECOMPILE);