"Parameter Sniffing" and Inner Join Questions

From: alien2_51 (anonymous_at_discussions.microsoft.com)
Date: 09/23/04


Date: Thu, 23 Sep 2004 16:07:45 -0700

What version of SQL Server are you running..? Are you
using any of your incoming parameters in the where clause
of any of your queries..?

CREATE PROCEDURE proc1 @p1 int
AS
    SELECT * FROM table1 WHERE col1 = @p1
GO

Look at KB320208

>-----Original Message-----
>I have two questions regarding a situation that we ran
into (and solved)
>recently that have got me wondering what's really
happening.
>
>1) We ran into a stored procedure that seemed to be
exhibiting a
>parameter sniffing issue (sorta). The stored procedure
was performing
>poorly in that it took about twenty minutes to execute.
We took the
>bulk of the code out and ran it as a script and it took
about one minute
>to execute. These results were consistent no matter
which executed
>first.
>
>We looked at estimated execution plan but saw nothing
that would suggest
>poor use of indexes, etc.
>
>Seemed to me that this could be a parameter sniffing
issue BUT the
>stored procedure performs poorly even on the first
execution (when the
>plan should be tailored to the data passed in). Our
first attempt was
>to add the WITH RECOMPILE option but no improvement. Now
it seems like
>it's not parameter sniffing. Several futile attempts
later we tried to
>simply copy the parameters into local variables and use
the locals in
>the body of the procedure. This fixed the problem.
>
>Question: Can anyone explain the difference in execution
time between
>the procedure and the script? Why does the use of local
variables help?
>
>
>2) In the course of working through this issue, my
colleague tried
>replacing the original join syntax:
>
> TableA a JOIN TableB b on a.MyKey = b.MyKey
>
>with this:
>
> TableA a INNER JOIN TableB b on a.MyKey = b.MyKey
>
>and reports a noticeable increase in execution speed. I
don't have
>metrics on this and have not confirmed his findings.
>
>Question: Since the "JOIN" syntax is equivalent to "INNER
JOIN", can
>anyone shed light on why this would be happening.
>
>TIA
>
>=======================================
>Everyone here speaks SQL; some are more fluent, others
less. When
>describing your SQL object (table, etc.), do so in the
language that we
>all understand - SQL, not English. It makes it easier to
understand
>your issue and makes it more likely that you will get the
assistance
>that you are asking for.
>
>*** Sent via Developersdex http://www.developersdex.com
***
>Don't just participate in USENET...get rewarded for it!
>.
>



Relevant Pages

  • Re: Performance problem on initial call of stored procedure
    ... It's the behaviour like SQL works. ... creates or validates access plans. ... For dynamic embedded SQL no access plan is stored in the program object ... After the first execution the data path will be closed again. ...
    (comp.sys.ibm.as400.misc)
  • Re: JDBC and Stored procedure performance problems
    ... After the SQL statement is executed. ... The second execution may be faster, but the access plan and the access ... After the second execution the data path stays open, ... Further the wait time may depend on the query engine that is used. ...
    (comp.sys.ibm.as400.misc)
  • Re: Poor performance after upgrading to sql server 2005
    ... I've included the SQL 2005 execution plan but I do not know ... <RunTimeInformation> ... <DefinedValues> ...
    (microsoft.public.sqlserver.setup)
  • Re: Query performance
    ... ADO.NET or SQL Management Studio. ... query takes a lot longer to execute. ... I can only examine the execution plan in SQL Management Studio, ...
    (microsoft.public.sqlserver.clients)
  • Re: derived table issue
    ... LEFT JOIN tableB B ... > I got a timeout error in running a complex SQL, part of the SQL are as ... > There are about 600,000 records in tableA, with condA, it will return ... > it runs faster a lot and the timeout problem has gone. ...
    (microsoft.public.sqlserver.programming)