473,388 Members | 864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Same query - different execution plans??

Hi,

We are trying to solve a real puzzle. We have a stored procedure that
exhibits *drastically* different execution times depending on how its
executed.

When run from QA, it can take as little as 3 seconds. When it is
called from an Excel vba application, it can take up to 180 seconds.
Although, at other times, it can take as little as 20 seconds from
Excel.

Here's a little background. The 180 second response time *usually*
occurs after a data load into a table that is referenced by the stored
procedure.

A check of DBCC show_statistics shows that the statistics DO get
updated after a large amount of data is loaded into the table.

*** So, my first question is, does the updated statistics force a
recompile of the stored procedure?

Next, we checked syscacheobjects to see what was going on with the
execution plan for this stored procedure. What I expected to see was
ONE execution plan for the stored procedure.

This is not the case at all. What is happening is that TWO separate
COMPILED PLANs are being created, depending on whether the sp is run
from QA or from Excel.

In addition, there are several EXECUTABLE PLANs that correspond to the
two COMPILED PLANs. Depending on *where* the sp is run, the usecount
increases for the various EXECUTABLE PLANS.

To me, this does not make any sense! Why are there *multiple* compile
and executable plans for the SAME sp?

One theory we have is, that we need to call the sp with the dbo
qualifier, ie) EXEC dbo.sp

Has anyone seen this? I just want to get to the bottom of this and
find out why sometimes the query takes 180 seconds and other times
only takes 3 seconds!!

Please help.

Thanks much

Jul 16 '07 #1
5 10718
sqlgirl (to*******@gmail.com) writes:
This is not the case at all. What is happening is that TWO separate
COMPILED PLANs are being created, depending on whether the sp is run
from QA or from Excel.
Yes, that is actually to be expected. :-)

Here is the scoop: certain SET commands affects the query plan so much,
that different combinations of SET commands yields different cache
entries. When you connect from Excel, you use an API that issues
turns on a number of SET commands. In QA you can set up under Options->
Connection Properties how to connect. But the QA default includes
SET ARITHABORT ON, which is not set when you connect from a client
application.

That explains why you see different plans. It does not explain why
you get such difference in performance. It may just be bad luck, but
there is also a real possibility: somewhere there is an indexed view
or an indexed computed columns. For these indexes, six SET commands
must be on and a seventh must be OFF. And one of the six are SET
ARITHABORT ON.

Try to get your VBA application to issue SET ARITHABORT ON and see
what happens.

--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jul 16 '07 #2
Hi, thanks for the information. Is ARITHABORT the only setting we need
to be concerned with?

We ran a test. Cleared out the cache entry for our sp by altering it.
Verified that it was no longer listed in syscacheobjects.

Next, we ran the query from QA, it added an entry to syscacheobjects.
Then, we ran it from excel. It still creates a second entry in
syscacheobjects.

Which still leaves me scratching my head.
Jul 16 '07 #3
sqlgirl (to*******@gmail.com) writes:
Hi, thanks for the information. Is ARITHABORT the only setting we need
to be concerned with?

We ran a test. Cleared out the cache entry for our sp by altering it.
Verified that it was no longer listed in syscacheobjects.

Next, we ran the query from QA, it added an entry to syscacheobjects.
Then, we ran it from excel. It still creates a second entry in
syscacheobjects.
And by then you had added SET ARITHABORT ON to the VBA code?

There are indeed other options that matter, but ARITHABORT is typically
the tricky one.

You can look at the column setopts in syscacheobjects, to see if there is
any difference. Unfortunately, Books Online does not specify which bit
that corresponds to which setting. (I assume that since you look in
syscacheobjects, that you are on SQL 2000. In SQL 2005 this information
is available in a more digestable form.)

You can also examine the SET option, by looking at the processes from
Profiler, keep an eye on Current connections, and Audit:Login, as well
as StmtCompleted.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Jul 17 '07 #4
It is not explicitly stated, so I'll ask:

Does each environment call the stored procedures with the exact same
parameters?

Does each environment call the stored procedure after a set of data is
loaded?

Do you have the execution plan for each scenario?

If you explicitly update statistics for the system after the new data
is loaded, does the execution time improve?

Jul 17 '07 #5
In addition to the other responses: when using stored procedures,
parameter sniffing can influence the query plan. So if two execution
plans are cached (because of differing connection settings), then the
parameter values of the first call will determine the query plan. If
these differ, the plan can differ.

Gert-Jan
sqlgirl wrote:
>
Hi,

We are trying to solve a real puzzle. We have a stored procedure that
exhibits *drastically* different execution times depending on how its
executed.

When run from QA, it can take as little as 3 seconds. When it is
called from an Excel vba application, it can take up to 180 seconds.
Although, at other times, it can take as little as 20 seconds from
Excel.

Here's a little background. The 180 second response time *usually*
occurs after a data load into a table that is referenced by the stored
procedure.

A check of DBCC show_statistics shows that the statistics DO get
updated after a large amount of data is loaded into the table.

*** So, my first question is, does the updated statistics force a
recompile of the stored procedure?

Next, we checked syscacheobjects to see what was going on with the
execution plan for this stored procedure. What I expected to see was
ONE execution plan for the stored procedure.

This is not the case at all. What is happening is that TWO separate
COMPILED PLANs are being created, depending on whether the sp is run
from QA or from Excel.

In addition, there are several EXECUTABLE PLANs that correspond to the
two COMPILED PLANs. Depending on *where* the sp is run, the usecount
increases for the various EXECUTABLE PLANS.

To me, this does not make any sense! Why are there *multiple* compile
and executable plans for the SAME sp?

One theory we have is, that we need to call the sp with the dbo
qualifier, ie) EXEC dbo.sp

Has anyone seen this? I just want to get to the bottom of this and
find out why sometimes the query takes 180 seconds and other times
only takes 3 seconds!!

Please help.

Thanks much
Jul 17 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Paul Mateer | last post by:
Hi, I have been running some queries against a table in a my database and have noted an odd (at least it seems odd to me) performance issue. The table has approximately 5 million rows and...
10
by: Thomas R. Hummel | last post by:
I have a stored procedure that suddenly started performing horribly. The query plan didn't look right to me, so I copy/pasted the code and ran it (it's a single SELECT statement). That ran pretty...
3
by: James Walker | last post by:
Hi there - hoping someone can help me here! I have a database that has been underperforming on a number of queries recently - in a test environment they take only a few seconds, but on the live...
2
by: jc | last post by:
Hi. A question I have is with regard to the use of views with SQL2000. If I have a view called "A_view" and used in the following manner; ---------------- SELECT ... FROM A_View WHERE .... ...
5
by: sql-db2-dba | last post by:
We have DB2 UDB v8.1 fixpak3 on AIX 5. Production and Development configuarations (at least for DB2) are identical albeit production is a 2-way server while development has only one processor....
22
by: Marc Mones | last post by:
Hello, I'working with IBM DB2 V8.1 and CLI/ODBC. I've got a problem with the following statement: ******************************************************************************** SELECT...
5
by: vijaylohkare | last post by:
HI All, I want to know the command that will display all the execution plans which are generated by the parser in PostgreSQL. Is there any command to instruct PostgreSQL to choose a specific...
2
by: Luke.Schollmeyer | last post by:
I found an unusual problem between 2000 and 2005 I haven't been able to decipher from any documentation. The query structure is as follows: select * from tableA a join tableB b ON...
12
by: Yash | last post by:
My SQL query is like: SELECT ..... FROM tblCLAIM C INNER join tblXXX .... INNER join tblYYY ....(5 more joins) WHERE C.created_date between @start_date and @end_date AND...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.