SQL Server 2022 Tells You Why A Query Can’t Go Parallel.


Until 2022, when a query couldn’t go parallel, all we got was a really cryptic note in the execution plan properties saying NonParallelPlanReason = CouldNotGenerateValidParallelPlan.

But starting with SQL Server 2022, even when I’m running under older compatibility levels:

ALTER DATABASE CURRENT SET COMPATIBILITY_LEVEL = 140; /* 2017 */ GO DECLARE @TableVariable TABLE(Total BIGINT); INSERT INTO @TableVariable (Total) SELECT COUNT(*) FROM dbo.Votes;

The execution plan gives me way more details:

Awww yeah! Here’s another example using a scalar user-defined function:

CREATE OR ALTER FUNCTION dbo.RightHereRightNow ( @Meaningless INT ) RETURNS DATETIME2 WITH RETURNS NULL ON NULL INPUT, SCHEMABINDING AS BEGIN