473,767 Members | 2,138 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

auto recompile in sql server

Hi,
I have a question in SQL Server 2K, I use SQL Profile to trace, and
find Stored Procedure was auto recompiled, like this row in the
trace:
SP:Recompile 15 1680 76 2004-02-27 16:01:11.610

How can I stop the auto recompile.

Thanks
Harold
Jul 20 '05 #1
7 5046

"Harold" <ch******@hotma il.com> wrote in message
news:6f******** *************** ***@posting.goo gle.com...
Hi,
I have a question in SQL Server 2K, I use SQL Profile to trace, and
find Stored Procedure was auto recompiled, like this row in the
trace:
SP:Recompile 15 1680 76 2004-02-27 16:01:11.610

How can I stop the auto recompile.

Thanks
Harold


http://support.microsoft.com/default...&Product=sql2k

Simon
Jul 20 '05 #2
Harold (ch******@hotma il.com) writes:
I have a question in SQL Server 2K, I use SQL Profile to trace, and
find Stored Procedure was auto recompiled, like this row in the
trace:
SP:Recompile 15 1680 76 2004-02-27 16:01:11.610

How can I stop the auto recompile.


Simon posted a very useful link. But permit me some short notes.

Recompiles are a mixed blessing. Sometimes they kill your performance,
sometimes they save the day. Not at all knowing your situation, it is
difficult to tell.

The most common reason for recompiles are temp tables that are filled
with data in the procedure. There are two remedies: use table variables
instead, or use OPTION (KEEPFIXED PLAN).

Table variables does not have statistics, which is why they cannot cause
recompile. But that also means that SQL Server has less information about
them when building a plan. Also, be aware of that insering data into a
table variable precludes parallellism. This can also be a performance
killer.

If you litter your code with OPTION (KEEPFIXED PLAN) you can prevent
recompiles, but forget it in one place, and you are in for it again.

A war story: some time back, I fought with a procedure that took 1½
minute to run. I figured I try to cut that down, and since there
were several recompiles, I tried to switching to table variables
plus a few more tricks. Sure, the recompiles went away - but I lost
on the roundabouts, so the execution time was still 1½ minute.
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3

"Erland Sommarskog" <so****@algonet .se> wrote in message
news:Xn******** **************@ 127.0.0.1...
Harold (ch******@hotma il.com) writes:
I have a question in SQL Server 2K, I use SQL Profile to trace, and
find Stored Procedure was auto recompiled, like this row in the
trace:
SP:Recompile 15 1680 76 2004-02-27 16:01:11.610

How can I stop the auto recompile.
Simon posted a very useful link. But permit me some short notes.


I'm going to jump in with my own real life experience here.

We went through the steps MS recommended.... big first step was making sure
we called all of our stored procs fully qualified with names, etc.

i.e. dbo.stored_proc as opposed to just stored_proc.

This helped. We got about 10% improvement in throughput.

Just last week, we found another issue (which I think is partly related to
the ODBC drivers, but that's beyond the scope here.)

In any case, rather than doing: exec stored_proc @foo=123 @bar='xyz' etc.

we wrapped the stored_proc call in a sp_executesql.. .. exec
sp_executesql(s tored_proc, etc etc.)

What used to take two sql boxes to handle the load for (and even then we
were getting a lot of problems) we now run on ONE box and have processing
power to spare.

One thing that helped us track this down was a recent article in SQL Server
Magazine that provided some stored procs on tracking wait states.

Whereas over a 2 minute period we'd get MILLIONS of LCK_MX_I (I think I got
that right off the top of my head) we now get hundreds to thousands.)

So, in this case, making the change made a major difference for us. (in our
case this stored proc gets called millions of times a day.)

So, in our case, the savings was HUGE.


Recompiles are a mixed blessing. Sometimes they kill your performance,
sometimes they save the day. Not at all knowing your situation, it is
difficult to tell.

The most common reason for recompiles are temp tables that are filled
with data in the procedure. There are two remedies: use table variables
instead, or use OPTION (KEEPFIXED PLAN).

Table variables does not have statistics, which is why they cannot cause
recompile. But that also means that SQL Server has less information about
them when building a plan. Also, be aware of that insering data into a
table variable precludes parallellism. This can also be a performance
killer.

If you litter your code with OPTION (KEEPFIXED PLAN) you can prevent
recompiles, but forget it in one place, and you are in for it again.

A war story: some time back, I fought with a procedure that took 1½
minute to run. I figured I try to cut that down, and since there
were several recompiles, I tried to switching to table variables
plus a few more tricks. Sure, the recompiles went away - but I lost
on the roundabouts, so the execution time was still 1½ minute.
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp

Jul 20 '05 #4
Greg D. Moore (Strider) (mo************ ****@greenms.co m) writes:
Just last week, we found another issue (which I think is partly related to
the ODBC drivers, but that's beyond the scope here.)

In any case, rather than doing: exec stored_proc @foo=123 @bar='xyz' etc.

we wrapped the stored_proc call in a sp_executesql.. .. exec
sp_executesql(s tored_proc, etc etc.)

What used to take two sql boxes to handle the load for (and even then we
were getting a lot of problems) we now run on ONE box and have processing
power to spare.


Interesting.

But I don't really understand. Did you change from using sp_executesql,
or to using it?

Assuming that changed to, how did you call the procedures before that?
Did you send EXEC statements over the wire, or did you call the procedures
through RPC? How do you call sp_executesql now? EXEC statement or RPC?
How are you passing the parameters to the procedures? Just part of the
EXEC string, or as parameters to sp_executesql?

Intuitively, I would think that wrapping the call in sp_executesql would
just be overhead, but I've been wrong before.
--
Erland Sommarskog, SQL Server MVP, so****@algonet. se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #5
Thank all of you!

Erland,
The OPTION (KEEPFIXED PLAN) only affect when Auto Update
Statistics(the properties of the database) is true, I turned of the
Auto Update Statistics.

This is from SQL 2K BOOK:
Forces the query optimizer not to recompile a query due to changes in
statistics or to the indexed column (update, delete, or insert).
Specifying KEEPFIXED PLAN ensures that a query will be recompiled only
if the schema of the underlying tables is changed or sp_recompile is
executed against those tables.

I think it may other cause the recompiler.

Thanks
Harold
Jul 20 '05 #6
Harold (ch******@hotma il.com) writes:
The OPTION (KEEPFIXED PLAN) only affect when Auto Update
Statistics(the properties of the database) is true, I turned of the
Auto Update Statistics.
Have you done that for tempdb as well? (Which I am not sure that I would
recommend.)
This is from SQL 2K BOOK:
Forces the query optimizer not to recompile a query due to changes in
statistics or to the indexed column (update, delete, or insert).
Specifying KEEPFIXED PLAN ensures that a query will be recompiled only
if the schema of the underlying tables is changed or sp_recompile is
executed against those tables.

I think it may other cause the recompiler.


Of course. If you have a procedure outer_sp that creates a temp
table and then calls inner_sp to operate on that table, then inner_sp
will be create at least once for each call to outer_sp, since it is a
new temp table each time.

But that's a common problem in these newsgroups. People post to little
information, so it often becomes a guessing game.

By the way, to identify why a procedure is being recompiled, this link
is useful.
http://support.microsoft.com/default...;EN-US;q308737.

--
Erland Sommarskog, SQL Server MVP, so****@algonet. se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #7
Erland,
I did not turn of the Auto Update Statistics config at tempdb, you
are right, so the temp table still cause the recompiler.

Thank you so much!
Harold
Jul 20 '05 #8

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

Similar topics

3
4313
by: P | last post by:
I would like to call my stored proc and invoke the WITH RECOMPILE option. I can't figure out what to set in ADO to make that happen. Anyone know how to make this work? BTW, I _don't_ want to create the stored proc using the WITH RECOMPILE.
4
4666
by: J?r?my | last post by:
Hello: The installation details: W2K SP4, SQL Server 2000 Ent with 1GB RAM. It is a Bi-P3. When I run the Profiler to trace Stored Procedure performance, I get a bunch of SP:CacheMiss for couple of stored procedure I invoke quite often in a web app. But I do not see SP:Recompile.
3
2472
by: Robin Tucker | last post by:
Hi there, I have this really frustrating problem with Visual Studio (Microsoft Visual Basic .NET 2003 69586-335-0000007-18843). I have got used to using the autocomplete and auto indent features of this excellent source editor but recently it has only operated on some of my source files and not others. I have made sure the settings in "tools->options->text editor" are set correctly but to no avail. For example, hitting enter at the...
1
1328
by: stuart Dee | last post by:
Hi, When I upload my binaries or aspx is there any way to auto recompile or compile them all before i start the application Tia
9
18851
by: Beowulf | last post by:
I was having this problem: http://groups.google.com/group/microsoft.public.sqlserver.server/msg/e36e423972323378?dmode=source with it taking an inordinate amount of time to enumerate the databases on my local SQL Server instance, so I went through all the local databases and unchecked "Auto Close" on the "Options" tab of the Database properties in Enterprise Manager. This cleared up the problem nicely. In EM or through SQL-DMO, the...
1
5750
by: yashgt | last post by:
Hi, We have an application that has been deployed into a virtual folder along with ascx, aspx and the code-behind files. It runs smoothly as long as we don't change any code-behind file. If we change a file, we expect ASP .NET to recompile the website when a user next accesses it. However, on next access the user gets the following error: Description: An error occurred during the compilation of a resource required to service this...
5
14490
by: Ben | last post by:
Hi! I need to refresh an entire database. I can recompile SPs with sp_recompile (or DBCC FLUSHPROCINDB), and refresh views with sp_refreshView, but I cannot find any way to refresh my user-defined functions (some of them are like views, with parameters). Any help appreciated :) !
11
10752
by: mp- | last post by:
I want to be able to allow people to check their email from my PHP online application. Given only the users 1) email address, 2) username (if applicable) and 3) password - how can I auto detect a remote IMAP/POP3 server so that I can connect and fetch mail for the user. (Ultimately, I don't want users to have to know what the IMAP/POP3 server name / port is .... I would like to auto-detect all of that). At first I thought I could use...
3
2710
by: Fiddler2 | last post by:
I noticed that after running compact/repair, I have to recompile my code for the program not to break the next time I open it. What happens is the auto exec macro runs the main() module, then hangs with the second line of code highlighted. No error message, just hangs. If I stop it and recompile the code, it runs again. Does anyone know anything about this? Is there some way to run something to recompile the code automatically after compacting...
0
9571
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10169
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9960
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9841
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8838
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5424
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3930
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3533
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2807
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.