SQL 服务器存储过程不在计划缓存中,也不在 Profiler 中

SQL Server stored procedure not in plan cache nor Profiler

我无法确定为什么某个存储过程没有出现在计划缓存中,也没有出现在 SQL Server Profiler 中。我是 运行 SQL Server 2014 SP2。

存储过程和类型如下所示。我发现的唯一可能有用的参考资料谈到了 SS 2008 中的错误修复,其中在字符串函数中使用了 blob。我在类型定义中确实有一个 blob (ntext)。这可能是原因或以某种方式相关吗?如果不是,还有什么可能导致这种行为?有什么方法可以让存储过程缓存 and/or 显示在探查器中?

CREATE TYPE [dbo].[OruMessages] AS TABLE
(
    [msg_status] [nchar](10) NOT NULL,
    [msg_no] [char](20) NOT NULL,
    [HL7_text_long] [ntext] NULL,
    [HL7_text_short] [nvarchar](255) NULL,
    [patient_id] [nvarchar](60) NULL,
    [msh_system] [nvarchar](50) NOT NULL,
    [msh_organization] [nvarchar](50) NOT NULL,
    [msh_event_cd] [nchar](10) NOT NULL,
    [msh_msg_type] [nchar](10) NOT NULL,
    [sent_dt] [datetime] NULL,
    [queued_dt] [datetime] NOT NULL
)
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[usp_HL7_SaveOruMessages]
    (@messageList [dbo].[OruMessages] READONLY)
AS
BEGIN
    INSERT  INTO [dbo].[HL7_out_queue]
    SELECT
        [msg_status],
        [msg_no],
        [HL7_text_long],
        [HL7_text_short],
        [patient_id],
        [msh_system],
        [msh_organization],
        [msh_event_cd],
        [msh_msg_type],
        [sent_dt],
        [queued_dt]
    FROM
        @messageList;
END;
GO


CREATE EVENT SESSION [Capture [usp_HL7_SaveOruMessages]] executions] ON SERVER 
ADD EVENT sqlserver.module_end(
    ACTION(sqlserver.database_name,sqlserver.sql_text)
    WHERE ([sqlserver].[database_name]=N'db' AND [sqlserver].[like_i_sql_unicode_string]([sqlserver].[sql_text],N'%usp_HL7_SaveOruMessages%'))),
ADD EVENT sqlserver.module_start(
    ACTION(sqlserver.database_name,sqlserver.sql_text)
    WHERE ([sqlserver].[database_name]=N'db' AND [sqlserver].[like_i_sql_unicode_string]([sqlserver].[sql_text],N'%usp_HL7_SaveOruMessages%'))),
ADD EVENT sqlserver.sql_batch_completed(
    ACTION(sqlserver.database_name,sqlserver.sql_text)
    WHERE ([sqlserver].[equal_i_sql_unicode_string]([sqlserver].[database_name],N'db') AND [sqlserver].[like_i_sql_unicode_string]([sqlserver].[sql_text],N'%usp_HL7_SaveOruMessages%') )),
ADD EVENT sqlserver.sql_statement_completed(
    ACTION(sqlserver.database_name,sqlserver.sql_text)
    WHERE ([sqlserver].[equal_i_sql_unicode_string]([sqlserver].[database_name],N'db') AND [sqlserver].[like_i_sql_unicode_string]([sqlserver].[sql_text],N'%usp_HL7_SaveOruMessages%') ))
ADD TARGET package0.event_file(SET filename=N'C:\db\Capture [usp_HL7_SaveOruMessages] executions')
WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=30 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=OFF,STARTUP_STATE=OFF)
GO

这是最后更改的扩展事件会话,它为我提供了来自主机的所有 RPC、批处理和模块调用,然后我能够找到有问题的存储过程。

CREATE EVENT SESSION [<MachineName>] ON SERVER 
ADD EVENT sqlserver.rpc_completed(
    ACTION(sqlserver.client_app_name,sqlserver.client_hostname,sqlserver.database_name,sqlserver.sql_text)
    WHERE ([sqlserver].[client_hostname]=N'<MachineName>')),
ADD EVENT sqlserver.sql_batch_completed(
    ACTION(sqlserver.client_app_name,sqlserver.client_hostname,sqlserver.database_name,sqlserver.sql_text)
    WHERE ([sqlserver].[client_hostname]=N'<MachineName>')),
ADD EVENT sqlserver.sql_statement_completed(
    ACTION(sqlserver.client_app_name,sqlserver.client_hostname,sqlserver.database_name,sqlserver.sql_text)
    WHERE ([sqlserver].[client_hostname]=N'<MachineName>'))
ADD TARGET package0.event_file(SET filename=N'C:\ExtEvents\<MachineName>.xel',max_file_size=(5120))
WITH (MAX_MEMORY=4096 KB,EVENT_RETENTION_MODE=ALLOW_SINGLE_EVENT_LOSS,MAX_DISPATCH_LATENCY=30 SECONDS,MAX_EVENT_SIZE=0 KB,MEMORY_PARTITION_MODE=NONE,TRACK_CAUSALITY=OFF,STARTUP_STATE=OFF)