sql server存储proc超时,查询不超时,为什么?

时间:2021-05-22 23:36:01

I have a stored proc on sql server 2008 that excepts a int parameter. It does call other stored procs and have nested quires.

我在sql server 2008上有一个存储的proc,除了一个int参数。它确实调用了其他存储的proc,并具有嵌套的quires。

the problem i am facing is when i run the procedure from SQL server management studio it does not execute and times out.

我所面临的问题是,当我从SQL server management studio中运行过程时,它不会执行和超时。

If i run the queries in side the stored proc separately in another SQL server management studio it just executes all fine.

如果我在另一个SQL server管理studio中单独运行存储的proc,那么它就会执行所有的操作。

I am not able to debug the issue. will appreciate any help/pointers to dig this deep.

我不能调试这个问题。将感激任何帮助/指示来深入挖掘。

( i am useing the same credential when executing the proc or the query )

(执行proc或查询时使用相同的凭据)

Thanks in advance.

提前谢谢。

1 个解决方案

#1


7  

Could be a case of parameter sniffing.

可能是参数嗅探的情况。

Try assigning the sproc parameters to local variables and using those in the queries within the sproc instead.

尝试将sproc参数分配给本地变量,并在sproc中使用这些参数。

e.g.

如。

CREATE PROCEDURE [TestSproc]
    @Param1 INTEGER
AS
BEGIN
DECLARE @Param1_LOCAL INTEGER
SET @Param1_LOCAL = @Param1

SELECT Something
FROM Somewhere
WHERE SomeField = @Param1_LOCAL 
END

#1


7  

Could be a case of parameter sniffing.

可能是参数嗅探的情况。

Try assigning the sproc parameters to local variables and using those in the queries within the sproc instead.

尝试将sproc参数分配给本地变量,并在sproc中使用这些参数。

e.g.

如。

CREATE PROCEDURE [TestSproc]
    @Param1 INTEGER
AS
BEGIN
DECLARE @Param1_LOCAL INTEGER
SET @Param1_LOCAL = @Param1

SELECT Something
FROM Somewhere
WHERE SomeField = @Param1_LOCAL 
END