我从这个过程中得到缓慢的表现
CREATE PROCEDURE MyProcedure01
@date datetime2(7)
AS
BEGIN
SELECT
[Limit1].[C2] AS [C1],
[Limit1].[mc_object] AS [mc_object],
[Limit1].[C1] AS [C2]
FROM ( SELECT TOP (50)
[GroupBy1].[A1] AS [C1],
[GroupBy1].[K1] AS [mc_object],
1 AS [C2]
FROM ( SELECT
[Extent1].[mc_object] AS [K1],
COUNT(1) AS [A1]
FROM [dbo].[BEM_EVT_FULL] AS [Extent1]
WHERE [Extent1].[date_reception] > @date
GROUP BY [Extent1].[mc_object]
) AS [GroupBy1]
) AS [Limit1]
END
在做了一些搜索之后,我发现如果以这种方式声明变量,我们将解决参数嗅探问题。
CREATE PROCEDURE MyProcedure02
@date datetime2(7)
AS
BEGIN
DECLARE @myDate datetime2(7)
SET @myDate = @date
SELECT
[Limit1].[C2] AS [C1],
[Limit1].[mc_object] AS [mc_object],
[Limit1].[C1] AS [C2]
FROM ( SELECT TOP (50)
[GroupBy1].[A1] AS [C1],
[GroupBy1].[K1] AS [mc_object],
1 AS [C2]
FROM ( SELECT
[Extent1].[mc_object] AS [K1],
COUNT(1) AS [A1]
FROM [dbo].[BEM_EVT_FULL] AS [Extent1]
WHERE [Extent1].[date_reception] > @myDate
GROUP BY [Extent1].[mc_object]
) AS [GroupBy1]
) AS [Limit1]
END
但不幸的是结果仍然很慢我能知道我是否遗漏了什么吗