Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 15264

When do #temp and @temp tables cause recompiles?

$
0
0

In olden days any temp table creation would cause a recompile of the entire SP.

However, I found that was already not the case even as early as SQL 2000, and I'm wondering what is the case in SQL 2008 and later.

Can anyone point me at a fairly current discussion of this?

My situation is that I have some existing and rather long (1000-3000 lines) SPs that use a lot of temp tables.  They *are* doing a lot of recompiles.  This is unfortunate because this is on an OLTP-ish system, and we want response times as fast as possible, and by my estimate the recompiles alone run about one second.  I'm not clear exactly what the current rules are.  Would using @temp tables avoidall recompilations (at some other semantic costs)?  I know they avoid statistics-triggered recompilations.

Thanks.

Josh

ps - for extra credit, does anyone have a way of estimating all the time the instance is spending on compilations?  perfmon offers counts, but not time.  I can calculate it from a full profiler trace, but it seems to require both compilation and statement start/end times to compute and that kind of trace is very expensive.  We can get it in SSMS with "set statistics time on" and adding up all the messages, but I'd like to get it monitoring the production box.



Viewing all articles
Browse latest Browse all 15264

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>