Hi,
I have a stored proc that has one output parameter. When I call
this sp from my client program (an MS Access VBA) it has always worked fine,
but just recently started to give me a message saying that the stored
procedure is expecting a parameter named @.TPRD but did not receive it,
program fails. @.TPRD is the output parameter and is declared as such. I
have not changed the sp recently so there is no code change in the sp. I
do not administrate my SQL Server, but I did request my administrator to
grant me EXEC access to sp_debug so that I could run the stored procedure
debugger. My sp stopped working at about the same time. Do you think
these two events could be related? How to solve? The code for my
stored procedure is below:
ALTER PROCEDURE [ad\jmuseck].[SELECT_TPRD]
@.TPRD VARCHAR(6) OUTPUT
AS
SELECT @.TPRD = TPRD
FROM tblCurrentMonth
RETURN @.TPRD
----
The code in my client MS Access VBA program looks like this:
Function SelectTprd(Optional newval As Variant) As String
Dim cmdCommand As ADODB.Command
Dim prmTPRD As ADODB.Parameter
Set cmdCommand = New ADODB.Command
cmdCommand.ActiveConnection = CurrentProject.AccessConnection
cmdCommand.CommandType = adCmdStoredProc
cmdCommand.CommandText = "SELECT_TPRD"
cmdCommand.Parameters.Refresh
<--STARTED FAILING ON THIS LINE !!
Set prmTPRD = cmdCommand.CreateParameter("@.TPRD", adChar, adParamOutput)
cmdCommand.Execute
'Return the time period to the calling program.'
SelectTprd = cmdCommand.Parameters(1).Value
Set cmdCommand = Nothing 'Free memory
End FunctionHello, Joe
This problem is related to MS Access, more specifically to the OLEDB
provider that Access uses internally. Use one of the following
workarounds:
1. Do not use Parameters.Refresh; instead of this, add each of the
parameters of the stored procedure (even if they have default values)
to the Parameters collection, *in the same order that they are
defined*, using something like this:
cmd.Parameters.Append cmd.CreateParameter("@.ParameterName",...)
2. Use another connection, based on the SQL Server OLEDB provider
(instead of the internal Access OLEDB provider), i.e. instead of the
line:
cmdCommand.ActiveConnection = CurrentProject.AccessConnection
use the following:
cmdCommand.ActiveConnection = CurrentProject.BaseConnectionString
3. If you use at least ADO 2.6, set the NamedParameters property to
True (before setting the ActiveConnection property) and:
a) use Parameters.Refresh (after setting the ActiveConnection) and fill
only the input parameters you need with something like this:
cmd.Parameters("@.ParameterName")=Value
after cmd.Execute, you can get the value of the output parameter by
reffering to it the same way:
Variable=cmd.Parameters("@.ParameterName")
or:
b) do not use Parameters.Refresh, but add the input parameters that you
need (in any order) (it's not necessary to add the input parameters
that have default values) , and also the output parameters (before
setting the ActiveConnection), with something like this:
cmd.Parameters.Append cmd.CreateParameter("@.ParameterName",...)
after cmd.Execute, you can get the value of the output parameter by
reffering to it the same way as above:
Variable=cmd.Parameters("@.ParameterName")
For more informations about the last method, see:
http://msdn.microsoft.com/library/e...dparameters.asp
The easiest method would be the second one (using the
BaseConnectionString to open another connection).
Note: in this message, I wrote about the case when the procedure has
more input parameters, some of them having default values, in addition
to the output parameters. In your case, if you have just one (output)
parameter, some of my remarks do not apply (i.e. adding the parameters
in the same order that they are defined, etc).
Razvan
Showing posts with label proc. Show all posts
Showing posts with label proc. Show all posts
Friday, March 9, 2012
Sunday, February 19, 2012
Execution Plans
I want to review historical SQL execution plans to determine if SQL has used
parallelism in the past. Is it possible to retreive plans from the proc
cache in a remotely human readable format?
Thanks,
NoelI meant to add that if you want to see how your queries are doing you should
run a trace. There are several events that will let you see things about
parallelism.
--
Andrew J. Kelly SQL MVP
"Noel Kennedy" <anonymous@.discussions.microsoft.com> wrote in message
news:OJUnIhoPFHA.1396@.TK2MSFTNGP10.phx.gbl...
>I want to review historical SQL execution plans to determine if SQL has
>used parallelism in the past. Is it possible to retreive plans from the
>proc cache in a remotely human readable format?
> Thanks,
> Noel
>|||You wont be able to tell much in that regard from the cached plans.
Parallel execution plans are not cached after use anyway.
--
Andrew J. Kelly SQL MVP
"Noel Kennedy" <anonymous@.discussions.microsoft.com> wrote in message
news:OJUnIhoPFHA.1396@.TK2MSFTNGP10.phx.gbl...
>I want to review historical SQL execution plans to determine if SQL has
>used parallelism in the past. Is it possible to retreive plans from the
>proc cache in a remotely human readable format?
> Thanks,
> Noel
>
parallelism in the past. Is it possible to retreive plans from the proc
cache in a remotely human readable format?
Thanks,
NoelI meant to add that if you want to see how your queries are doing you should
run a trace. There are several events that will let you see things about
parallelism.
--
Andrew J. Kelly SQL MVP
"Noel Kennedy" <anonymous@.discussions.microsoft.com> wrote in message
news:OJUnIhoPFHA.1396@.TK2MSFTNGP10.phx.gbl...
>I want to review historical SQL execution plans to determine if SQL has
>used parallelism in the past. Is it possible to retreive plans from the
>proc cache in a remotely human readable format?
> Thanks,
> Noel
>|||You wont be able to tell much in that regard from the cached plans.
Parallel execution plans are not cached after use anyway.
--
Andrew J. Kelly SQL MVP
"Noel Kennedy" <anonymous@.discussions.microsoft.com> wrote in message
news:OJUnIhoPFHA.1396@.TK2MSFTNGP10.phx.gbl...
>I want to review historical SQL execution plans to determine if SQL has
>used parallelism in the past. Is it possible to retreive plans from the
>proc cache in a remotely human readable format?
> Thanks,
> Noel
>
Execution plan whackyness
Ok, I have this stored proc that does a lot of things and as of recently
it runs really really slow, like 2 minutes (versus 7-8 seconds before).
In an effort isolate the problem, I cut and pasted the stored proc
source code into Query Analyzer. I then replaced the sproc parameters
with declarations and assigned them values that I pass into the stored
proc. Then I ran it. The source code itself runs fast (7-8 seconds as
the sproc did before). In addition, the query plan is different between
the 2 scenarios.
What could be causing anything like this?You might want to check to ensure the stats are updated and check
fragmentation.
--
Thomas
"Frank Rizzo" wrote:
> Ok, I have this stored proc that does a lot of things and as of recently
> it runs really really slow, like 2 minutes (versus 7-8 seconds before).
> In an effort isolate the problem, I cut and pasted the stored proc
> source code into Query Analyzer. I then replaced the sproc parameters
> with declarations and assigned them values that I pass into the stored
> proc. Then I ran it. The source code itself runs fast (7-8 seconds as
> the sproc did before). In addition, the query plan is different between
> the 2 scenarios.
> What could be causing anything like this?
>|||Hi there,
fragmenatation is not an issue because it would hurt both the SP and the
Ad-hoc query and it doesn't seem like the ad-hoc query has problems. Have
you tried to recompile your SP ?
Try
"EXEC Your_SP With Recompile".
If it generates the same execution plan as the Ad-hoc query then run
"Exec SP_Recompile Your_SP". This will "mark" the SP for a recompilation
at next execute and generate and cache the new executionplan. The problem in
SP's sometimes is that the exeplan is static. It is generated and cached at
first execute and then reused. Eventually check if your SP is recompiling
while executing. You can trace that with your Profiler.
Regards
Bobby Henningsen
"Thomas" <Thomas@.discussions.microsoft.com> wrote in message
news:93A1541E-2C06-4670-BC54-0747A865BBFB@.microsoft.com...[vbcol=seagreen]
> You might want to check to ensure the stats are updated and check
> fragmentation.
> --
> Thomas
>
> "Frank Rizzo" wrote:
>|||There is a big difference between a parameter, variable and constant. In sho
rt:
WHERE col = @.parm
The optimizer will sniff the parm value from the call if the proc and determ
ine selectivity based on
that.
WHERE col = @.var
The optimizer has no idea about the value of the variable and have to guess.
In some case it can use
density, but it still doesn't know the value of the variable.
WHERE col = 23
Optimizer does know the value and determine selectivity based on that.
I suggest you google on "parameter sniffing" for more info.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Frank Rizzo" <none@.none.com> wrote in message news:OtyVwOk5FHA.620@.TK2MSFTNGP12.phx.gbl...[
vbcol=seagreen]
> Ok, I have this stored proc that does a lot of things and as of recently i
t runs really really
> slow, like 2 minutes (versus 7-8 seconds before). In an effort isolate the
problem, I cut and
> pasted the stored proc source code into Query Analyzer. I then replaced t
he sproc parameters with
> declarations and assigned them values that I pass into the stored proc. T
hen I ran it. The
> source code itself runs fast (7-8 seconds as the sproc did before). In ad
dition, the query plan
> is different between the 2 scenarios.
> What could be causing anything like this?[/vbcol]|||I am sorry, I neglected to mention in the original post that I tried
this approach as well as creating the sproc with the recompile option to
begin with.
Bobby Henningsen wrote:
> Hi there,
> fragmenatation is not an issue because it would hurt both the SP and the
> Ad-hoc query and it doesn't seem like the ad-hoc query has problems. Have
> you tried to recompile your SP ?
> Try
> "EXEC Your_SP With Recompile".
> If it generates the same execution plan as the Ad-hoc query then run
> "Exec SP_Recompile Your_SP". This will "mark" the SP for a recompilatio
n
> at next execute and generate and cache the new executionplan. The problem
in
> SP's sometimes is that the exeplan is static. It is generated and cached a
t
> first execute and then reused. Eventually check if your SP is recompiling
> while executing. You can trace that with your Profiler.
> Regards
> Bobby Henningsen
> "Thomas" <Thomas@.discussions.microsoft.com> wrote in message
> news:93A1541E-2C06-4670-BC54-0747A865BBFB@.microsoft.com...
>
>
>|||On Thu, 10 Nov 2005 14:11:21 -0800, Frank Rizzo <none@.none.com> wrote:
>Ok, I have this stored proc that does a lot of things and as of recently
>it runs really really slow, like 2 minutes (versus 7-8 seconds before).
> In an effort isolate the problem, I cut and pasted the stored proc
>source code into Query Analyzer. I then replaced the sproc parameters
>with declarations and assigned them values that I pass into the stored
>proc. Then I ran it. The source code itself runs fast (7-8 seconds as
>the sproc did before). In addition, the query plan is different between
>the 2 scenarios.
>What could be causing anything like this?
Does the SP run fast or slow when called from QA?
I've been plagued recently with SPs that run fine when called
individually but pathologically slowly when called in production under
load, even with the same parameters.
My only "fix" is recoding with ever-simpler intermediate steps until
it behaves better even under load. I found one where it was the
unusual data configuration only under load (that was actually on a QA
box, not production), on the others, I just don't know.
This problem may be worse under sp4. That is, we made some database
changes about the same time as installing sp4, and have noticed the
problems more recently. However, I do believe they also occurred on
sp3a. I have not yet been able to run the production system with the
profiler capturing query plans, though I guess I'd better do so, if I
can find an appropriate filter so the trace doesn't slow production
and generate gigabytes of trace per minute.
J.
it runs really really slow, like 2 minutes (versus 7-8 seconds before).
In an effort isolate the problem, I cut and pasted the stored proc
source code into Query Analyzer. I then replaced the sproc parameters
with declarations and assigned them values that I pass into the stored
proc. Then I ran it. The source code itself runs fast (7-8 seconds as
the sproc did before). In addition, the query plan is different between
the 2 scenarios.
What could be causing anything like this?You might want to check to ensure the stats are updated and check
fragmentation.
--
Thomas
"Frank Rizzo" wrote:
> Ok, I have this stored proc that does a lot of things and as of recently
> it runs really really slow, like 2 minutes (versus 7-8 seconds before).
> In an effort isolate the problem, I cut and pasted the stored proc
> source code into Query Analyzer. I then replaced the sproc parameters
> with declarations and assigned them values that I pass into the stored
> proc. Then I ran it. The source code itself runs fast (7-8 seconds as
> the sproc did before). In addition, the query plan is different between
> the 2 scenarios.
> What could be causing anything like this?
>|||Hi there,
fragmenatation is not an issue because it would hurt both the SP and the
Ad-hoc query and it doesn't seem like the ad-hoc query has problems. Have
you tried to recompile your SP ?
Try
"EXEC Your_SP With Recompile".
If it generates the same execution plan as the Ad-hoc query then run
"Exec SP_Recompile Your_SP". This will "mark" the SP for a recompilation
at next execute and generate and cache the new executionplan. The problem in
SP's sometimes is that the exeplan is static. It is generated and cached at
first execute and then reused. Eventually check if your SP is recompiling
while executing. You can trace that with your Profiler.
Regards
Bobby Henningsen
"Thomas" <Thomas@.discussions.microsoft.com> wrote in message
news:93A1541E-2C06-4670-BC54-0747A865BBFB@.microsoft.com...[vbcol=seagreen]
> You might want to check to ensure the stats are updated and check
> fragmentation.
> --
> Thomas
>
> "Frank Rizzo" wrote:
>|||There is a big difference between a parameter, variable and constant. In sho
rt:
WHERE col = @.parm
The optimizer will sniff the parm value from the call if the proc and determ
ine selectivity based on
that.
WHERE col = @.var
The optimizer has no idea about the value of the variable and have to guess.
In some case it can use
density, but it still doesn't know the value of the variable.
WHERE col = 23
Optimizer does know the value and determine selectivity based on that.
I suggest you google on "parameter sniffing" for more info.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Frank Rizzo" <none@.none.com> wrote in message news:OtyVwOk5FHA.620@.TK2MSFTNGP12.phx.gbl...[
vbcol=seagreen]
> Ok, I have this stored proc that does a lot of things and as of recently i
t runs really really
> slow, like 2 minutes (versus 7-8 seconds before). In an effort isolate the
problem, I cut and
> pasted the stored proc source code into Query Analyzer. I then replaced t
he sproc parameters with
> declarations and assigned them values that I pass into the stored proc. T
hen I ran it. The
> source code itself runs fast (7-8 seconds as the sproc did before). In ad
dition, the query plan
> is different between the 2 scenarios.
> What could be causing anything like this?[/vbcol]|||I am sorry, I neglected to mention in the original post that I tried
this approach as well as creating the sproc with the recompile option to
begin with.
Bobby Henningsen wrote:
> Hi there,
> fragmenatation is not an issue because it would hurt both the SP and the
> Ad-hoc query and it doesn't seem like the ad-hoc query has problems. Have
> you tried to recompile your SP ?
> Try
> "EXEC Your_SP With Recompile".
> If it generates the same execution plan as the Ad-hoc query then run
> "Exec SP_Recompile Your_SP". This will "mark" the SP for a recompilatio
n
> at next execute and generate and cache the new executionplan. The problem
in
> SP's sometimes is that the exeplan is static. It is generated and cached a
t
> first execute and then reused. Eventually check if your SP is recompiling
> while executing. You can trace that with your Profiler.
> Regards
> Bobby Henningsen
> "Thomas" <Thomas@.discussions.microsoft.com> wrote in message
> news:93A1541E-2C06-4670-BC54-0747A865BBFB@.microsoft.com...
>
>
>|||On Thu, 10 Nov 2005 14:11:21 -0800, Frank Rizzo <none@.none.com> wrote:
>Ok, I have this stored proc that does a lot of things and as of recently
>it runs really really slow, like 2 minutes (versus 7-8 seconds before).
> In an effort isolate the problem, I cut and pasted the stored proc
>source code into Query Analyzer. I then replaced the sproc parameters
>with declarations and assigned them values that I pass into the stored
>proc. Then I ran it. The source code itself runs fast (7-8 seconds as
>the sproc did before). In addition, the query plan is different between
>the 2 scenarios.
>What could be causing anything like this?
Does the SP run fast or slow when called from QA?
I've been plagued recently with SPs that run fine when called
individually but pathologically slowly when called in production under
load, even with the same parameters.
My only "fix" is recoding with ever-simpler intermediate steps until
it behaves better even under load. I found one where it was the
unusual data configuration only under load (that was actually on a QA
box, not production), on the others, I just don't know.
This problem may be worse under sp4. That is, we made some database
changes about the same time as installing sp4, and have noticed the
problems more recently. However, I do believe they also occurred on
sp3a. I have not yet been able to run the production system with the
profiler capturing query plans, though I guess I'd better do so, if I
can find an appropriate filter so the trace doesn't slow production
and generate gigabytes of trace per minute.
J.
Execution plan whackyness
Ok, I have this stored proc that does a lot of things and as of recently
it runs really really slow, like 2 minutes (versus 7-8 seconds before).
In an effort isolate the problem, I cut and pasted the stored proc
source code into Query Analyzer. I then replaced the sproc parameters
with declarations and assigned them values that I pass into the stored
proc. Then I ran it. The source code itself runs fast (7-8 seconds as
the sproc did before). In addition, the query plan is different between
the 2 scenarios.
What could be causing anything like this?You might want to check to ensure the stats are updated and check
fragmentation.
--
Thomas
"Frank Rizzo" wrote:
> Ok, I have this stored proc that does a lot of things and as of recently
> it runs really really slow, like 2 minutes (versus 7-8 seconds before).
> In an effort isolate the problem, I cut and pasted the stored proc
> source code into Query Analyzer. I then replaced the sproc parameters
> with declarations and assigned them values that I pass into the stored
> proc. Then I ran it. The source code itself runs fast (7-8 seconds as
> the sproc did before). In addition, the query plan is different between
> the 2 scenarios.
> What could be causing anything like this?
>|||Hi there,
fragmenatation is not an issue because it would hurt both the SP and the
Ad-hoc query and it doesn't seem like the ad-hoc query has problems. Have
you tried to recompile your SP ?
Try
"EXEC Your_SP With Recompile".
If it generates the same execution plan as the Ad-hoc query then run
"Exec SP_Recompile Your_SP". This will "mark" the SP for a recompilation
at next execute and generate and cache the new executionplan. The problem in
SP's sometimes is that the exeplan is static. It is generated and cached at
first execute and then reused. Eventually check if your SP is recompiling
while executing. You can trace that with your Profiler.
Regards :)
Bobby Henningsen
"Thomas" <Thomas@.discussions.microsoft.com> wrote in message
news:93A1541E-2C06-4670-BC54-0747A865BBFB@.microsoft.com...
> You might want to check to ensure the stats are updated and check
> fragmentation.
> --
> Thomas
>
> "Frank Rizzo" wrote:
>> Ok, I have this stored proc that does a lot of things and as of recently
>> it runs really really slow, like 2 minutes (versus 7-8 seconds before).
>> In an effort isolate the problem, I cut and pasted the stored proc
>> source code into Query Analyzer. I then replaced the sproc parameters
>> with declarations and assigned them values that I pass into the stored
>> proc. Then I ran it. The source code itself runs fast (7-8 seconds as
>> the sproc did before). In addition, the query plan is different between
>> the 2 scenarios.
>> What could be causing anything like this?|||There is a big difference between a parameter, variable and constant. In short:
WHERE col = @.parm
The optimizer will sniff the parm value from the call if the proc and determine selectivity based on
that.
WHERE col = @.var
The optimizer has no idea about the value of the variable and have to guess. In some case it can use
density, but it still doesn't know the value of the variable.
WHERE col = 23
Optimizer does know the value and determine selectivity based on that.
I suggest you google on "parameter sniffing" for more info.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Frank Rizzo" <none@.none.com> wrote in message news:OtyVwOk5FHA.620@.TK2MSFTNGP12.phx.gbl...
> Ok, I have this stored proc that does a lot of things and as of recently it runs really really
> slow, like 2 minutes (versus 7-8 seconds before). In an effort isolate the problem, I cut and
> pasted the stored proc source code into Query Analyzer. I then replaced the sproc parameters with
> declarations and assigned them values that I pass into the stored proc. Then I ran it. The
> source code itself runs fast (7-8 seconds as the sproc did before). In addition, the query plan
> is different between the 2 scenarios.
> What could be causing anything like this?|||I am sorry, I neglected to mention in the original post that I tried
this approach as well as creating the sproc with the recompile option to
begin with.
Bobby Henningsen wrote:
> Hi there,
> fragmenatation is not an issue because it would hurt both the SP and the
> Ad-hoc query and it doesn't seem like the ad-hoc query has problems. Have
> you tried to recompile your SP ?
> Try
> "EXEC Your_SP With Recompile".
> If it generates the same execution plan as the Ad-hoc query then run
> "Exec SP_Recompile Your_SP". This will "mark" the SP for a recompilation
> at next execute and generate and cache the new executionplan. The problem in
> SP's sometimes is that the exeplan is static. It is generated and cached at
> first execute and then reused. Eventually check if your SP is recompiling
> while executing. You can trace that with your Profiler.
> Regards :)
> Bobby Henningsen
> "Thomas" <Thomas@.discussions.microsoft.com> wrote in message
> news:93A1541E-2C06-4670-BC54-0747A865BBFB@.microsoft.com...
>>You might want to check to ensure the stats are updated and check
>>fragmentation.
>>--
>>Thomas
>>
>>"Frank Rizzo" wrote:
>>
>>Ok, I have this stored proc that does a lot of things and as of recently
>>it runs really really slow, like 2 minutes (versus 7-8 seconds before).
>> In an effort isolate the problem, I cut and pasted the stored proc
>>source code into Query Analyzer. I then replaced the sproc parameters
>>with declarations and assigned them values that I pass into the stored
>>proc. Then I ran it. The source code itself runs fast (7-8 seconds as
>>the sproc did before). In addition, the query plan is different between
>>the 2 scenarios.
>>What could be causing anything like this?
>
>|||On Thu, 10 Nov 2005 14:11:21 -0800, Frank Rizzo <none@.none.com> wrote:
>Ok, I have this stored proc that does a lot of things and as of recently
>it runs really really slow, like 2 minutes (versus 7-8 seconds before).
> In an effort isolate the problem, I cut and pasted the stored proc
>source code into Query Analyzer. I then replaced the sproc parameters
>with declarations and assigned them values that I pass into the stored
>proc. Then I ran it. The source code itself runs fast (7-8 seconds as
>the sproc did before). In addition, the query plan is different between
>the 2 scenarios.
>What could be causing anything like this?
Does the SP run fast or slow when called from QA?
I've been plagued recently with SPs that run fine when called
individually but pathologically slowly when called in production under
load, even with the same parameters.
My only "fix" is recoding with ever-simpler intermediate steps until
it behaves better even under load. I found one where it was the
unusual data configuration only under load (that was actually on a QA
box, not production), on the others, I just don't know.
This problem may be worse under sp4. That is, we made some database
changes about the same time as installing sp4, and have noticed the
problems more recently. However, I do believe they also occurred on
sp3a. I have not yet been able to run the production system with the
profiler capturing query plans, though I guess I'd better do so, if I
can find an appropriate filter so the trace doesn't slow production
and generate gigabytes of trace per minute.
J.
it runs really really slow, like 2 minutes (versus 7-8 seconds before).
In an effort isolate the problem, I cut and pasted the stored proc
source code into Query Analyzer. I then replaced the sproc parameters
with declarations and assigned them values that I pass into the stored
proc. Then I ran it. The source code itself runs fast (7-8 seconds as
the sproc did before). In addition, the query plan is different between
the 2 scenarios.
What could be causing anything like this?You might want to check to ensure the stats are updated and check
fragmentation.
--
Thomas
"Frank Rizzo" wrote:
> Ok, I have this stored proc that does a lot of things and as of recently
> it runs really really slow, like 2 minutes (versus 7-8 seconds before).
> In an effort isolate the problem, I cut and pasted the stored proc
> source code into Query Analyzer. I then replaced the sproc parameters
> with declarations and assigned them values that I pass into the stored
> proc. Then I ran it. The source code itself runs fast (7-8 seconds as
> the sproc did before). In addition, the query plan is different between
> the 2 scenarios.
> What could be causing anything like this?
>|||Hi there,
fragmenatation is not an issue because it would hurt both the SP and the
Ad-hoc query and it doesn't seem like the ad-hoc query has problems. Have
you tried to recompile your SP ?
Try
"EXEC Your_SP With Recompile".
If it generates the same execution plan as the Ad-hoc query then run
"Exec SP_Recompile Your_SP". This will "mark" the SP for a recompilation
at next execute and generate and cache the new executionplan. The problem in
SP's sometimes is that the exeplan is static. It is generated and cached at
first execute and then reused. Eventually check if your SP is recompiling
while executing. You can trace that with your Profiler.
Regards :)
Bobby Henningsen
"Thomas" <Thomas@.discussions.microsoft.com> wrote in message
news:93A1541E-2C06-4670-BC54-0747A865BBFB@.microsoft.com...
> You might want to check to ensure the stats are updated and check
> fragmentation.
> --
> Thomas
>
> "Frank Rizzo" wrote:
>> Ok, I have this stored proc that does a lot of things and as of recently
>> it runs really really slow, like 2 minutes (versus 7-8 seconds before).
>> In an effort isolate the problem, I cut and pasted the stored proc
>> source code into Query Analyzer. I then replaced the sproc parameters
>> with declarations and assigned them values that I pass into the stored
>> proc. Then I ran it. The source code itself runs fast (7-8 seconds as
>> the sproc did before). In addition, the query plan is different between
>> the 2 scenarios.
>> What could be causing anything like this?|||There is a big difference between a parameter, variable and constant. In short:
WHERE col = @.parm
The optimizer will sniff the parm value from the call if the proc and determine selectivity based on
that.
WHERE col = @.var
The optimizer has no idea about the value of the variable and have to guess. In some case it can use
density, but it still doesn't know the value of the variable.
WHERE col = 23
Optimizer does know the value and determine selectivity based on that.
I suggest you google on "parameter sniffing" for more info.
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Frank Rizzo" <none@.none.com> wrote in message news:OtyVwOk5FHA.620@.TK2MSFTNGP12.phx.gbl...
> Ok, I have this stored proc that does a lot of things and as of recently it runs really really
> slow, like 2 minutes (versus 7-8 seconds before). In an effort isolate the problem, I cut and
> pasted the stored proc source code into Query Analyzer. I then replaced the sproc parameters with
> declarations and assigned them values that I pass into the stored proc. Then I ran it. The
> source code itself runs fast (7-8 seconds as the sproc did before). In addition, the query plan
> is different between the 2 scenarios.
> What could be causing anything like this?|||I am sorry, I neglected to mention in the original post that I tried
this approach as well as creating the sproc with the recompile option to
begin with.
Bobby Henningsen wrote:
> Hi there,
> fragmenatation is not an issue because it would hurt both the SP and the
> Ad-hoc query and it doesn't seem like the ad-hoc query has problems. Have
> you tried to recompile your SP ?
> Try
> "EXEC Your_SP With Recompile".
> If it generates the same execution plan as the Ad-hoc query then run
> "Exec SP_Recompile Your_SP". This will "mark" the SP for a recompilation
> at next execute and generate and cache the new executionplan. The problem in
> SP's sometimes is that the exeplan is static. It is generated and cached at
> first execute and then reused. Eventually check if your SP is recompiling
> while executing. You can trace that with your Profiler.
> Regards :)
> Bobby Henningsen
> "Thomas" <Thomas@.discussions.microsoft.com> wrote in message
> news:93A1541E-2C06-4670-BC54-0747A865BBFB@.microsoft.com...
>>You might want to check to ensure the stats are updated and check
>>fragmentation.
>>--
>>Thomas
>>
>>"Frank Rizzo" wrote:
>>
>>Ok, I have this stored proc that does a lot of things and as of recently
>>it runs really really slow, like 2 minutes (versus 7-8 seconds before).
>> In an effort isolate the problem, I cut and pasted the stored proc
>>source code into Query Analyzer. I then replaced the sproc parameters
>>with declarations and assigned them values that I pass into the stored
>>proc. Then I ran it. The source code itself runs fast (7-8 seconds as
>>the sproc did before). In addition, the query plan is different between
>>the 2 scenarios.
>>What could be causing anything like this?
>
>|||On Thu, 10 Nov 2005 14:11:21 -0800, Frank Rizzo <none@.none.com> wrote:
>Ok, I have this stored proc that does a lot of things and as of recently
>it runs really really slow, like 2 minutes (versus 7-8 seconds before).
> In an effort isolate the problem, I cut and pasted the stored proc
>source code into Query Analyzer. I then replaced the sproc parameters
>with declarations and assigned them values that I pass into the stored
>proc. Then I ran it. The source code itself runs fast (7-8 seconds as
>the sproc did before). In addition, the query plan is different between
>the 2 scenarios.
>What could be causing anything like this?
Does the SP run fast or slow when called from QA?
I've been plagued recently with SPs that run fine when called
individually but pathologically slowly when called in production under
load, even with the same parameters.
My only "fix" is recoding with ever-simpler intermediate steps until
it behaves better even under load. I found one where it was the
unusual data configuration only under load (that was actually on a QA
box, not production), on the others, I just don't know.
This problem may be worse under sp4. That is, we made some database
changes about the same time as installing sp4, and have noticed the
problems more recently. However, I do believe they also occurred on
sp3a. I have not yet been able to run the production system with the
profiler capturing query plans, though I guess I'd better do so, if I
can find an appropriate filter so the trace doesn't slow production
and generate gigabytes of trace per minute.
J.
Execution plan whackyness
Ok, I have this stored proc that does a lot of things and as of recently
it runs really really slow, like 2 minutes (versus 7-8 seconds before).
In an effort isolate the problem, I cut and pasted the stored proc
source code into Query Analyzer. I then replaced the sproc parameters
with declarations and assigned them values that I pass into the stored
proc. Then I ran it. The source code itself runs fast (7-8 seconds as
the sproc did before). In addition, the query plan is different between
the 2 scenarios.
What could be causing anything like this?
You might want to check to ensure the stats are updated and check
fragmentation.
Thomas
"Frank Rizzo" wrote:
> Ok, I have this stored proc that does a lot of things and as of recently
> it runs really really slow, like 2 minutes (versus 7-8 seconds before).
> In an effort isolate the problem, I cut and pasted the stored proc
> source code into Query Analyzer. I then replaced the sproc parameters
> with declarations and assigned them values that I pass into the stored
> proc. Then I ran it. The source code itself runs fast (7-8 seconds as
> the sproc did before). In addition, the query plan is different between
> the 2 scenarios.
> What could be causing anything like this?
>
|||Hi there,
fragmenatation is not an issue because it would hurt both the SP and the
Ad-hoc query and it doesn't seem like the ad-hoc query has problems. Have
you tried to recompile your SP ?
Try
"EXEC Your_SP With Recompile".
If it generates the same execution plan as the Ad-hoc query then run
"Exec SP_Recompile Your_SP". This will "mark" the SP for a recompilation
at next execute and generate and cache the new executionplan. The problem in
SP's sometimes is that the exeplan is static. It is generated and cached at
first execute and then reused. Eventually check if your SP is recompiling
while executing. You can trace that with your Profiler.
Regards
Bobby Henningsen
"Thomas" <Thomas@.discussions.microsoft.com> wrote in message
news:93A1541E-2C06-4670-BC54-0747A865BBFB@.microsoft.com...[vbcol=seagreen]
> You might want to check to ensure the stats are updated and check
> fragmentation.
> --
> Thomas
>
> "Frank Rizzo" wrote:
|||There is a big difference between a parameter, variable and constant. In short:
WHERE col = @.parm
The optimizer will sniff the parm value from the call if the proc and determine selectivity based on
that.
WHERE col = @.var
The optimizer has no idea about the value of the variable and have to guess. In some case it can use
density, but it still doesn't know the value of the variable.
WHERE col = 23
Optimizer does know the value and determine selectivity based on that.
I suggest you google on "parameter sniffing" for more info.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Frank Rizzo" <none@.none.com> wrote in message news:OtyVwOk5FHA.620@.TK2MSFTNGP12.phx.gbl...
> Ok, I have this stored proc that does a lot of things and as of recently it runs really really
> slow, like 2 minutes (versus 7-8 seconds before). In an effort isolate the problem, I cut and
> pasted the stored proc source code into Query Analyzer. I then replaced the sproc parameters with
> declarations and assigned them values that I pass into the stored proc. Then I ran it. The
> source code itself runs fast (7-8 seconds as the sproc did before). In addition, the query plan
> is different between the 2 scenarios.
> What could be causing anything like this?
|||I am sorry, I neglected to mention in the original post that I tried
this approach as well as creating the sproc with the recompile option to
begin with.
Bobby Henningsen wrote:
> Hi there,
> fragmenatation is not an issue because it would hurt both the SP and the
> Ad-hoc query and it doesn't seem like the ad-hoc query has problems. Have
> you tried to recompile your SP ?
> Try
> "EXEC Your_SP With Recompile".
> If it generates the same execution plan as the Ad-hoc query then run
> "Exec SP_Recompile Your_SP". This will "mark" the SP for a recompilation
> at next execute and generate and cache the new executionplan. The problem in
> SP's sometimes is that the exeplan is static. It is generated and cached at
> first execute and then reused. Eventually check if your SP is recompiling
> while executing. You can trace that with your Profiler.
> Regards
> Bobby Henningsen
> "Thomas" <Thomas@.discussions.microsoft.com> wrote in message
> news:93A1541E-2C06-4670-BC54-0747A865BBFB@.microsoft.com...
>
>
|||On Thu, 10 Nov 2005 14:11:21 -0800, Frank Rizzo <none@.none.com> wrote:
>Ok, I have this stored proc that does a lot of things and as of recently
>it runs really really slow, like 2 minutes (versus 7-8 seconds before).
> In an effort isolate the problem, I cut and pasted the stored proc
>source code into Query Analyzer. I then replaced the sproc parameters
>with declarations and assigned them values that I pass into the stored
>proc. Then I ran it. The source code itself runs fast (7-8 seconds as
>the sproc did before). In addition, the query plan is different between
>the 2 scenarios.
>What could be causing anything like this?
Does the SP run fast or slow when called from QA?
I've been plagued recently with SPs that run fine when called
individually but pathologically slowly when called in production under
load, even with the same parameters.
My only "fix" is recoding with ever-simpler intermediate steps until
it behaves better even under load. I found one where it was the
unusual data configuration only under load (that was actually on a QA
box, not production), on the others, I just don't know.
This problem may be worse under sp4. That is, we made some database
changes about the same time as installing sp4, and have noticed the
problems more recently. However, I do believe they also occurred on
sp3a. I have not yet been able to run the production system with the
profiler capturing query plans, though I guess I'd better do so, if I
can find an appropriate filter so the trace doesn't slow production
and generate gigabytes of trace per minute.
J.
it runs really really slow, like 2 minutes (versus 7-8 seconds before).
In an effort isolate the problem, I cut and pasted the stored proc
source code into Query Analyzer. I then replaced the sproc parameters
with declarations and assigned them values that I pass into the stored
proc. Then I ran it. The source code itself runs fast (7-8 seconds as
the sproc did before). In addition, the query plan is different between
the 2 scenarios.
What could be causing anything like this?
You might want to check to ensure the stats are updated and check
fragmentation.
Thomas
"Frank Rizzo" wrote:
> Ok, I have this stored proc that does a lot of things and as of recently
> it runs really really slow, like 2 minutes (versus 7-8 seconds before).
> In an effort isolate the problem, I cut and pasted the stored proc
> source code into Query Analyzer. I then replaced the sproc parameters
> with declarations and assigned them values that I pass into the stored
> proc. Then I ran it. The source code itself runs fast (7-8 seconds as
> the sproc did before). In addition, the query plan is different between
> the 2 scenarios.
> What could be causing anything like this?
>
|||Hi there,
fragmenatation is not an issue because it would hurt both the SP and the
Ad-hoc query and it doesn't seem like the ad-hoc query has problems. Have
you tried to recompile your SP ?
Try
"EXEC Your_SP With Recompile".
If it generates the same execution plan as the Ad-hoc query then run
"Exec SP_Recompile Your_SP". This will "mark" the SP for a recompilation
at next execute and generate and cache the new executionplan. The problem in
SP's sometimes is that the exeplan is static. It is generated and cached at
first execute and then reused. Eventually check if your SP is recompiling
while executing. You can trace that with your Profiler.
Regards
Bobby Henningsen
"Thomas" <Thomas@.discussions.microsoft.com> wrote in message
news:93A1541E-2C06-4670-BC54-0747A865BBFB@.microsoft.com...[vbcol=seagreen]
> You might want to check to ensure the stats are updated and check
> fragmentation.
> --
> Thomas
>
> "Frank Rizzo" wrote:
|||There is a big difference between a parameter, variable and constant. In short:
WHERE col = @.parm
The optimizer will sniff the parm value from the call if the proc and determine selectivity based on
that.
WHERE col = @.var
The optimizer has no idea about the value of the variable and have to guess. In some case it can use
density, but it still doesn't know the value of the variable.
WHERE col = 23
Optimizer does know the value and determine selectivity based on that.
I suggest you google on "parameter sniffing" for more info.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
"Frank Rizzo" <none@.none.com> wrote in message news:OtyVwOk5FHA.620@.TK2MSFTNGP12.phx.gbl...
> Ok, I have this stored proc that does a lot of things and as of recently it runs really really
> slow, like 2 minutes (versus 7-8 seconds before). In an effort isolate the problem, I cut and
> pasted the stored proc source code into Query Analyzer. I then replaced the sproc parameters with
> declarations and assigned them values that I pass into the stored proc. Then I ran it. The
> source code itself runs fast (7-8 seconds as the sproc did before). In addition, the query plan
> is different between the 2 scenarios.
> What could be causing anything like this?
|||I am sorry, I neglected to mention in the original post that I tried
this approach as well as creating the sproc with the recompile option to
begin with.
Bobby Henningsen wrote:
> Hi there,
> fragmenatation is not an issue because it would hurt both the SP and the
> Ad-hoc query and it doesn't seem like the ad-hoc query has problems. Have
> you tried to recompile your SP ?
> Try
> "EXEC Your_SP With Recompile".
> If it generates the same execution plan as the Ad-hoc query then run
> "Exec SP_Recompile Your_SP". This will "mark" the SP for a recompilation
> at next execute and generate and cache the new executionplan. The problem in
> SP's sometimes is that the exeplan is static. It is generated and cached at
> first execute and then reused. Eventually check if your SP is recompiling
> while executing. You can trace that with your Profiler.
> Regards
> Bobby Henningsen
> "Thomas" <Thomas@.discussions.microsoft.com> wrote in message
> news:93A1541E-2C06-4670-BC54-0747A865BBFB@.microsoft.com...
>
>
|||On Thu, 10 Nov 2005 14:11:21 -0800, Frank Rizzo <none@.none.com> wrote:
>Ok, I have this stored proc that does a lot of things and as of recently
>it runs really really slow, like 2 minutes (versus 7-8 seconds before).
> In an effort isolate the problem, I cut and pasted the stored proc
>source code into Query Analyzer. I then replaced the sproc parameters
>with declarations and assigned them values that I pass into the stored
>proc. Then I ran it. The source code itself runs fast (7-8 seconds as
>the sproc did before). In addition, the query plan is different between
>the 2 scenarios.
>What could be causing anything like this?
Does the SP run fast or slow when called from QA?
I've been plagued recently with SPs that run fine when called
individually but pathologically slowly when called in production under
load, even with the same parameters.
My only "fix" is recoding with ever-simpler intermediate steps until
it behaves better even under load. I found one where it was the
unusual data configuration only under load (that was actually on a QA
box, not production), on the others, I just don't know.
This problem may be worse under sp4. That is, we made some database
changes about the same time as installing sp4, and have noticed the
problems more recently. However, I do believe they also occurred on
sp3a. I have not yet been able to run the production system with the
profiler capturing query plans, though I guess I'd better do so, if I
can find an appropriate filter so the trace doesn't slow production
and generate gigabytes of trace per minute.
J.
Subscribe to:
Posts (Atom)