简体   繁体   English

参数嗅探故障排除

[英]Parameter sniffing troubleshooting

need a bit of help in accomplishing something in tsql. 需要一些帮助才能完成tsql中的操作。 I am collecting sql profiler trace data to get a particular stored procedure execution and basically I am trying to strip out the parameter values from the textdata column Example for the below set of data, i need to stripe out parameter value out 我正在收集sql profiler跟踪数据以获取特定的存储过程执行,并且基本上我正试图从textdata列中剥离参数值对于以下数据集的示例,我需要剥离出参数值

exec test
exec test @aa=10
exec test @aa=10,@bb=10
exec test @aa=10,@bb=10,@cc=100
exec test @aa=10,@bb=1000,@cc=1

so the output table might look like 所以输出表可能看起来像

aa   bb     cc
10   Null  NUll
10    10   NULL
10    10   100
10   1000   1

I am just trying to find out what are the common parameters that are being passed to the sp, so if there is other easy ways of doing it please let me know. 我只是想找出传递给sp的通用参数是什么,因此,如果有其他简便的方法,请告诉我。

Few Ways i could think off.. 我想不出什么办法..

1.using plan cache 1.使用计划缓存

select query_plan from sys.dm_exec_cached_plans cp
cross apply
sys.dm_exec_text_query_plan(cp.plan_handle,default,default)
where objtype='proc' and object_name(objectid)='usp_test'

Now the above query plan is an xml which will contain all the values used at compile time .This procedure is very cuber some and you will get only compiled values.But with time due to plan cache invalidation which can occur due to many reasons ,you will get new values over time 现在,上面的查询计划是一个xml,其中将包含编译时使用的所有 。此过程有些复杂,您将只获得编译后的值。但是由于计划缓存无效,随着时间的流逝,由于许多原因 ,缓存可能会失效,因此,随着时间的推移将获得新的价值

2.Modify your stored proc to insert into some other table all the param values some thing like below 2.修改存储的过程以将所有参数值插入到其他表中,如下所示

create proc usp_test
(
@a int=1,
@b int =2
)

as
begin
insert into sometable 
select @a,@b,getdate()
end

Other than the above said ways,there is no way i could think off by which you can obtain passed parameter values(Excluding trace you are running) 除了上述方式外,没有其他办法可以让我获得传递的参数值(不包括正在运行的跟踪)

If you are looking to troubleshoot parameter sniffing,by gathering all parameter values,this might not be the accurate way 如果要通过收集所有参数值来解决参数嗅探问题,这可能不是正确的方法

what i understand is that you want to overcome parameter sniffing problem . 我了解的是您想克服参数嗅探问题。

you can make your proc like this, 你可以像这样使你的过程,

create proc usp_test
(
@aa int,
@bb int ,
@cc int
)

as
begin

    DECLARE @aa1 INT
    SET @aa1 = @aa
    DECLARE @bb1 INT
    SET @bb1 = @bb
    DECLARE @cc1 INT
    SET @cc1 = @cc


select col1,col2 from testtable
    where col1=@aa1 and col2=@bb1

end

https://www.simple-talk.com/sql/t-sql-programming/parameter-sniffing/ https://www.simple-talk.com/sql/t-sql-programming/parameter-sniffing/

https://blogs.technet.microsoft.com/mdegre/2011/11/06/what-is-parameter-sniffing/ https://blogs.technet.microsoft.com/mdegre/2011/11/06/what-is-parameter-sniffing/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM