Hi,
I´ve just updated our SQL environment (SQL Server 2019) to latest CU 9.
I run into a problem related to the new Scalar UDF Inlining functionality.
I have some nested scalar UDFs that runs into problem in some scenarios.
The SQL command returns error in SSMS and in the SQL Servers logs I get 0xc0000005 EXCEPTION_ACCESS_VIOLATION.
I don´t think this issue was present before CU9?
To reproduce the issue, please follow the steps below.
On a server running SQL Server 2019 15.0.4102.2 (CU9)
Run the following SQL commands:
CREATE DATABASE [TestDB]
GO
USE [TestDB]
GO
CREATE FUNCTION [dbo].[GetSub1] (@param NVARCHAR(4000))
RETURNS NVARCHAR(4000)
AS
BEGIN
RETURN (@param + ' Test2')
END
GO
CREATE FUNCTION [dbo].[GetSub2] ()
RETURNS NVARCHAR(4000)
AS
BEGIN
RETURN (
SELECT TOP 1 name
FROM [sys].[columns]
)
END
GO
CREATE FUNCTION [dbo].[GetMain1] ()
RETURNS NVARCHAR(4000)
AS
BEGIN
RETURN (dbo.GetSub1(dbo.GetSub2()))
END
GO
This will create a new database and 3 UDFs.
After that run the following SQL command and you will get the error:
SELECT [dbo].[GetMain1] ()
If I rewrite one of the above UDFs like this it will work:
ALTER FUNCTION [dbo].[GetMain1] ()
RETURNS NVARCHAR(4000)
AS
BEGIN
DECLARE @par NVARCHAR(4000)
SET @par = dbo.GetSub2()
RETURN (dbo.GetSub1(@par))
END
GO
It will also work if you disable the inlining functionality like this:
ALTER FUNCTION [dbo].[GetMain1] ()
RETURNS NVARCHAR(4000)
WITH INLINE = OFF
AS
BEGIN
RETURN (dbo.GetSub1(dbo.GetSub2()))
END
GO