Severe performance degradation in SQL Server 2022 when SMO enumerates databases with ActiveConnections due to sys.sysprocesses query
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 38/100
調査の方向性
ActiveConnections と Databases の列挙に Server.SetDefaultInitFields を使用する PowerShell での再現から始め、生成された ActiveConnections クエリがどこで組み立てられているかを追跡します。現在の sys.sysprocesses クエリと SQL Server 2022 で提案されている代替案を比較し、データベースの列挙で報告された遅延が発生しなくなったことを確認して完了を検証します。
索引モデルが issue の本文から書いたものです。
説明
Hello,
We've had to add a workaround for an issue that was introduced in 2022.
Please fix and we will update our codebase.
https://github.com/dataplat/dbatools/pull/9908
Description
SQL Server 2022 has severe performance degradation when SMO enumerates databases with ActiveConnections in the default init fields. The same query that takes ~1 second on SQL Server 2016 takes 20+ seconds on SQL Server 2022.
Root Cause
The generated query includes:
(select count(*) from master.dbo.sysprocesses p where dtb.database_id=p.dbid) AS [ActiveConnections]
This subquery for ActiveConnections uses the deprecated sys.sysprocesses compatibility view, which has severe performance issues on SQL Server 2022, particularly when querying hundreds of databases.
Workaround Found
Setting the legacy cardinality estimator on the master database reduces query time from 20s to 1s, suggesting this is a query optimizer regression in SQL Server 2022.
Environment
- SQL Server Version: SQL Server 2022 (VersionMajor 16)
- SMO Version: Multiple versions tested (including 17.100.23.0)
- Number of Databases: 190+ databases significantly amplifies the issue
- Query Execution: Each database enumeration includes this subquery, causing exponential slowdown
Proposed Solutions
- Short-term: Update SMO to use
sys.dm_exec_sessionsinstead ofsys.sysprocesses - Medium-term: Fix the cardinality estimation issue for
sys.sysprocessesqueries in SQL Server 2022 - Long-term: Remove
sys.sysprocessesentirely as it's been deprecated since SQL Server 2008
Reproduction
$server = New-Object Microsoft.SqlServer.Management.Smo.Server "SQL2022Instance"
$initFields = New-Object System.Collections.Specialized.StringCollection
[void]$initFields.AddRange(@('ActiveConnections'))
$server.SetDefaultInitFields([Microsoft.SqlServer.Management.Smo.Database], $initFields)
# This will be very slow on SQL 2022 with 100+ databases
Measure-Command { $server.Databases | Out-Null }
Impact
- Affects all SMO-based tooling (SSMS, Azure Data Studio, dbatools, custom scripts)
- Only manifests when user has
VIEW SERVER STATEpermission - Severely impacts automation and monitoring tools
- Issue affects SQL Server 2022 RTM and remains after applying latest CUs
References
- Original issue: dataplat/dbatools#9282
- Deprecated view documentation: https://learn.microsoft.com/en-us/sql/relational-databases/system-compatibility-views/sys-sysprocesses-transact-sql
- 主要言語
- C#
- スター
- 143
- フォーク
- 28
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/sqlmanagementobjects のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 72/100
-
難易度 4/5 3〜5日 初心者へのやさしさ 74/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 78/100
-
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
microsoft/sqlmanagementobjects の issue をすべて見る
似ている issue
-
:watch: Not Triaged dotnet-fsharp/svc
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
-
Client customer-reported needs-team-attention question Service Attention WebPubSub
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
Azure/azure-sdk-for-net#63292 · コメント 3 件 · リアクション 1 件 ·
-
Issue-Enhancement Needs-Triage
難易度 1/5 1時間未満 初心者へのやさしさ 86/100
PowerShell/PowerShell#28061 · リアクション 2 件 ·
-
dependencies needs-team-triage server-Azure.Mcp
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
aspnet-core/svc aspnetcore-signalr/subsvc doc-enhancement Pri2 SignalR
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
dotnet/AspNetCore.Docs#37729 ·