Hi Msft team!
I hope this message finds you well. I am writing to report a persistent issue with execution plan parallel deadlocks that still exists in SQL Server 2022. Despite updates and patches, this bug appears to remain unresolved, and I have been able to consistently reproduce it under specific conditions.
Environment:
SELECT @@VERSION
Microsoft SQL Server 2022 (RTM-CU12) (KB5033663) 16.0.4115.5 (X64) Mar 4 2024 08:56:10 Copyright (c) 2022 Microsoft Corporation Enterprise Edition (64-bit) on Windows Server 2016 Datacenter 10.0 (X64) (Build 14393): (Hypervisor)
Issue Description:
The problem arises under certain parallelism conditions when executing queries that are supposed to handle large computations across multiple processors. Here is the SQL script used to reproduce the issue:
-- Creating a table with a primary key and a fill factor CREATE TABLE Numbers ( Number INT NOT NULL, CONSTRAINT PK_Numbers PRIMARY KEY CLUSTERED (Number) WITH FILLFACTOR = 100 );
-- Populating the table with values INSERT INTO Numbers SELECT (a.Number * 256) + b.Number AS Number FROM (SELECT number FROM master..spt_values WHERE type = 'P' AND number <= 255) a, (SELECT number FROM master..spt_values WHERE type = 'P' AND number <= 255) b;
-- Example query that completes quickly with an odd MAXDOP setting SET STATISTICS TIME ON; SELECT maxN = MAX(num.number) FROM dbo.numbers AS num WHERE num.number < 30000 AND CONVERT(INTEGER, CONVERT(VARCHAR(MAX), num.number)) % 2 = 0 OPTION ( MAXDOP 3, QUERYTRACEON 8649 );
-- Example query that leads to a deadlock with an even MAXDOP setting SELECT maxN = MAX(num.number) FROM dbo.numbers AS num WHERE num.number < 30000 AND CONVERT(INTEGER, CONVERT(VARCHAR(MAX), num.number)) % 2 = 0 OPTION ( MAXDOP 4, QUERYTRACEON 8649 );
Issue:
When the MAXDOP is set to an odd number (e.g., 3, 5, 7), the query returns results quickly without any issues. However, changing MAXDOP to an even number (e.g., 2, 4, 6) results in significantly longer execution times, and using the Trace Profiler, we detect a deadlock.
It appears that the deadlock occurs specifically when parallel execution plans are generated with an even number of threads. This issue might be rooted in how SQL Server manages parallel process threads and resources.
Request for Assistance:
Could the SQL Server team look into this matter and provide a fix or workaround? This issue impacts performance significantly and could affect many users working with large data sets and relying on parallel processing for performance optimization.
Thank you for your attention to this matter. I look forward to your prompt response and a resolution to this persistent issue.