debugsqlMinor
Passing Memory-Optimized Table Into Inline Function Causes Error When Called From Stored Proc
Viewed 0 times
storederrorcalledpassingintofunctionoptimizedprocmemorywhen
Problem
When I use a memory-optimized table with a stored Procedure that passes the table to an inline table-valued function I get an error:
Msg 596, Level 21, State 1, Line 0
Cannot continue the execution because the session is in the kill state.
Msg 0, Level 20, State 0, Line 0
A severe error occurred on the current command. The results, if any, should be discarded.
I'm using SQL Server 2016 Developer Edition:
Microsoft SQL Server 2016 (SP1-CU3) (KB4019916) - 13.0.4435.0 (X64)
Apr 27 2017 17:36:12
Copyright (c) Microsoft Corporation
Developer Edition (64-bit) on Windows 10 Pro 6.3 (Build 14393: ) (Hypervisor)
I can recreate the error like this:
Sometimes this happens and sometimes it doesn't. I have other procedures that work similarly and usually they work fine.
I get this dump in my
2017-07-17 13:14:36.14 spid56 ***Stack Dump being sent to
C:\Program Files\Microsoft SQL
Server\MSSQL13.MSSQLSERVER\MSSQL\LOG\SQLDump0058.txt 2017-07-17
13:14:36.14 spid56 SqlDumpExceptionHandler: Process 56 generated
fatal exception c0000005 EXCEPTION_ACCESS_VIOLATION. SQL Server is
terminating this process. 2017-07-17 13:14:36.14 spid56 *
Msg 596, Level 21, State 1, Line 0
Cannot continue the execution because the session is in the kill state.
Msg 0, Level 20, State 0, Line 0
A severe error occurred on the current command. The results, if any, should be discarded.
I'm using SQL Server 2016 Developer Edition:
Microsoft SQL Server 2016 (SP1-CU3) (KB4019916) - 13.0.4435.0 (X64)
Apr 27 2017 17:36:12
Copyright (c) Microsoft Corporation
Developer Edition (64-bit) on Windows 10 Pro 6.3 (Build 14393: ) (Hypervisor)
I can recreate the error like this:
CREATE TYPE [dbo].[Name] AS TABLE
( [Name] VARCHAR(500) NOT NULL PRIMARY KEY NONCLUSTERED )
WITH (MEMORY_OPTIMIZED = ON)
GO
CREATE TABLE Table1
( ID INT IDENTITY(1,1) PRIMARY KEY NOT NULL
, [Data] nvarchar(max) not null
)
INSERT INTO Table1 ([Data])
VALUES (N'blah1'), (N'blah2'), (N'blah3'), (N'blah4')
GO
CREATE OR ALTER FUNCTION dbo.Test
( @table dbo.[Name] READONLY
) RETURNS TABLE AS RETURN
SELECT *
FROM Table1 t
JOIN @table t2
ON t2.[Name] = t.[Data]
GO
CREATE OR ALTER PROCEDURE dbo.Test2
@table dbo.[Name] READONLY
AS
SELECT *
FROM dbo.Test(@table)
GO
DECLARE @memTable dbo.[Name]
INSERT INTO @memTable ([Name])
VALUES ('blah1'), ('blah3')
EXEC dbo.Test2 @memTableSometimes this happens and sometimes it doesn't. I have other procedures that work similarly and usually they work fine.
I get this dump in my
ERRORLOG (Cut short for brevity):2017-07-17 13:14:36.14 spid56 ***Stack Dump being sent to
C:\Program Files\Microsoft SQL
Server\MSSQL13.MSSQLSERVER\MSSQL\LOG\SQLDump0058.txt 2017-07-17
13:14:36.14 spid56 SqlDumpExceptionHandler: Process 56 generated
fatal exception c0000005 EXCEPTION_ACCESS_VIOLATION. SQL Server is
terminating this process. 2017-07-17 13:14:36.14 spid56 *
Solution
This is a bug: Connect Bug Submission
A workaround is to not pass the memory-optimized table into the stored procedure. You can use it after that though.
Fixed in SQL Server 2017 CU1:
Fix: Error when a stored procedure passes a memory-optimized table to an inline table-valued function in SQL Server 2017
A workaround is to not pass the memory-optimized table into the stored procedure. You can use it after that though.
Fixed in SQL Server 2017 CU1:
Fix: Error when a stored procedure passes a memory-optimized table to an inline table-valued function in SQL Server 2017
Context
StackExchange Database Administrators Q#180061, answer score: 4
Revisions (0)
No revisions yet.