如何比较本机编译存储过程中的 varchar 参数?
How to compare varchar parameters in a natively compiled stored procedure?
我正在将一些表和存储过程迁移到内存优化表和本机编译的存储过程。我卡在了字符串比较上。
Comparison, sorting, and manipulation of character strings that do not
use a *_BIN2 collation is not supported with natively compiled stored
procedures.
CREATE TABLE [User].[FingerPrints]
(
Id int NOT NULL PRIMARY KEY NONCLUSTERED HASH WITH (BUCKET_COUNT = 10000),
FingerPrint VARCHAR(4000) NOT NULL,
SecretKey VARCHAR(512) NOT NULL,
BranchId int NOT NULL,
SteadySign bit NOT NULL,
CreatedOn datetime NOT NULL,
ModifiedOn datetime NOT NULL
) WITH (MEMORY_OPTIMIZED = ON, DURABILITY = SCHEMA_AND_DATA)
GO
CREATE PROCEDURE [User].[GetFingerPrint]
@Id int,
@SecretKey VARCHAR(512)
WITH NATIVE_COMPILATION, SCHEMABINDING, EXECUTE AS OWNER
AS BEGIN ATOMIC WITH
(
TRANSACTION ISOLATION LEVEL = SNAPSHOT, LANGUAGE = N'us_english'
)
SELECT [Id]
,[FingerPrint]
,[SecretKey]
,[BranchId]
,[SteadySign]
,[CreatedOn]
,[ModifiedOn]
FROM [User].[FingerPrints]
WHERE [Id] = @Id AND [SecretKey] = @SecretKey
END
GO
更改 @SecretKey
参数的排序规则似乎对我有用,在 AdventureWorks2014 的副本中:
CREATE PROCEDURE [User].[GetFingerPrint]
@Id int,
@SecretKey VARCHAR(512)
WITH NATIVE_COMPILATION, SCHEMABINDING, EXECUTE AS OWNER
AS BEGIN ATOMIC WITH
(
TRANSACTION ISOLATION LEVEL = SNAPSHOT, LANGUAGE = N'us_english'
)
SELECT [Id]
,[FingerPrint]
,[SecretKey]
,[BranchId]
,[SteadySign]
,[CreatedOn]
,[ModifiedOn]
FROM [User].[FingerPrints]
WHERE [Id] = @Id AND [SecretKey] = @SecretKey COLLATE LATIN1_GENERAL_BIN2
END
GO
我正在将一些表和存储过程迁移到内存优化表和本机编译的存储过程。我卡在了字符串比较上。
Comparison, sorting, and manipulation of character strings that do not use a *_BIN2 collation is not supported with natively compiled stored procedures.
CREATE TABLE [User].[FingerPrints]
(
Id int NOT NULL PRIMARY KEY NONCLUSTERED HASH WITH (BUCKET_COUNT = 10000),
FingerPrint VARCHAR(4000) NOT NULL,
SecretKey VARCHAR(512) NOT NULL,
BranchId int NOT NULL,
SteadySign bit NOT NULL,
CreatedOn datetime NOT NULL,
ModifiedOn datetime NOT NULL
) WITH (MEMORY_OPTIMIZED = ON, DURABILITY = SCHEMA_AND_DATA)
GO
CREATE PROCEDURE [User].[GetFingerPrint]
@Id int,
@SecretKey VARCHAR(512)
WITH NATIVE_COMPILATION, SCHEMABINDING, EXECUTE AS OWNER
AS BEGIN ATOMIC WITH
(
TRANSACTION ISOLATION LEVEL = SNAPSHOT, LANGUAGE = N'us_english'
)
SELECT [Id]
,[FingerPrint]
,[SecretKey]
,[BranchId]
,[SteadySign]
,[CreatedOn]
,[ModifiedOn]
FROM [User].[FingerPrints]
WHERE [Id] = @Id AND [SecretKey] = @SecretKey
END
GO
更改 @SecretKey
参数的排序规则似乎对我有用,在 AdventureWorks2014 的副本中:
CREATE PROCEDURE [User].[GetFingerPrint]
@Id int,
@SecretKey VARCHAR(512)
WITH NATIVE_COMPILATION, SCHEMABINDING, EXECUTE AS OWNER
AS BEGIN ATOMIC WITH
(
TRANSACTION ISOLATION LEVEL = SNAPSHOT, LANGUAGE = N'us_english'
)
SELECT [Id]
,[FingerPrint]
,[SecretKey]
,[BranchId]
,[SteadySign]
,[CreatedOn]
,[ModifiedOn]
FROM [User].[FingerPrints]
WHERE [Id] = @Id AND [SecretKey] = @SecretKey COLLATE LATIN1_GENERAL_BIN2
END
GO