小编O. *_*nes的帖子

SELECT TOP 1 损害查询性能;有没有一种 dba 可访问的方法来克服这个问题?

在生产应用程序(C# 与 SQL Server 2014 Standard 对话)中,有一个如下所示的查询。大多数情况下,它以毫秒为单位运行。但偶尔(对于 的某些值@Id),它会发疯并需要一分钟左右的时间。这比应用超时时间长,因此用户的应用失败。

在“疯了”的情况下,返回的结果集是正确的,因为它在许多但不是所有其他情况下都是空的。

幸运的是,这在生产和开发环境中都是可重现的。

开发人员说从查询中删除“TOP 1”,然后确保应用程序使用结果集的额外行,清除性能问题。

查询规划器在TOP 1存在时建议没有索引。(在开发中)。

正在更改查询并修复应用程序。推出需要一段时间。

我的问题:是否有任何 DBA 可访问的方法来调整或调整生产 SQL Server 实例以在新查询推出应用程序更改之前解决此问题?

SELECT TOP 1
       subscription_id 
  FROM subscription AS sub
  JOIN billing_info AS bi ON bi.billing_info_id = sub.billing_info_id   
  JOIN person_group AS apg ON apg.person_id = bi.person_id
  JOIN pplan ON pplan.plan_id = sub.plan_id
  JOIN product ON product.product_id = [plan].product_id 
  JOIN product_attribute ON product_attribute.product_id = product.product_id 
 WHERE apg.group_id = @Id
   AND apg.start_date < GETDATE()
   AND (apg.end_date IS NULL …
Run Code Online (Sandbox Code Playgroud)

performance sql-server database-tuning query-performance

13
推荐指数
1
解决办法
1650
查看次数