这是一个非常简单的功能,它反映了确定性.如果我编译它本机,它不再是确定性的.我如何使其原生编译和确定性?
CREATE FUNCTION [hash].[HashDelimiter2]() RETURNS NCHAR(1) WITH SCHEMABINDING AS BEGIN RETURN N';' END GO /* This does indeed result in YES */ SELECT IS_DETERMINISTIC FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME = 'HashDelimiter2' /* But then compile it native and it's no longer deterministic */ CREATE FUNCTION [hash].[HashDelimiter3]() RETURNS NCHAR(1) WITH NATIVE_COMPILATION,SCHEMABINDING AS BEGIN ATOMIC WITH ( TRANSACTION ISOLATION LEVEL = SNAPSHOT,LANGUAGE = N'English' ) RETURN N';' END GO /* This results in NO */ SELECT IS_DETERMINISTIC FROM INFORMATION_SCHEMA.ROUTINES WHERE ROUTINE_NAME = 'HashDelimiter3'
解决方法
只有一个猜测,我没有2016年测试,
但我会尝试改变:
但我会尝试改变:
RETURN N';'
至
DECLARE @R AS NCHAR(1) = N';' RETURN @R
我认为问题是N’;’被创建为NVARCHAR(1),然后隐式转换为NCHAR(1),所以也许转换使它不确定.