Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

The First execution of a Stored Proc shows a delay between SP:StmtStarting and SP:Starting

$
0
0

We experience a performanceproblem with some of our Stored Procedures. SQL Server is "Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64)"

Situation:
SQL Server Proc1 executes some SQL Statement and starts some other SQL Stored Procedures. I open a SQL Management Studio Session "example session_id 105", trace the session 105 with the SQL Server Profiler.
I start Proc 1, when Proc1 starts the execution of Proc 2, the Profiler Trace shows a delay of 6 seconds between SP:StmtStarting "execute db..proc2 @SomeVar" and SP:Starting "execute db..proc2 @SomeVar".
All following executions of Proc1 in the Session 105 runs without a delay between SP:StmtStarting "execute db..proc2 @SomeVar" and SP:Starting "execute db..proc2 @SomeVar".

But when i open a new SQL Server Management Session "session_id 124", the first execution of Proc1 when it executes Proc 1, there is again the delay of 6 seconds between SP:StmtStarting "execute db..proc2 @SomeVar" and SP:Starting "execute db..proc2 @SomeVar".

Proc 1 starts the execution of Proc2 with a simple execute statement like this:
Execute DB..Proc2 @SomeVar

So its not dynamic SQL.

What is SQL Server doing? I understand that SQL Server has to do some work when it executes the first time a Stored Procedure. But why is the SQL Server doing it in every new Session?

How can i prevent this behavior or how to make it faster?

Best Regards
Paolo


Viewing all articles
Browse latest Browse all 23857

Trending Articles



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