all groups > sql server (alternate) > december 2004 >
You're in the

sql server (alternate)

group:

why is execution of a storedprocedure in QueryAnalyzer faster than executing this SP as scheduled job?


Re: why is execution of a storedprocedure in QueryAnalyzer faster than executing this SP as scheduled job? Andrew J. Kelly
12/30/2004 12:41:07 PM
sql server (alternate):
I assume you mean ON and not OFF?

--
Andrew J. Kelly SQL MVP


[quoted text, click to view]

Re: why is execution of a storedprocedure in QueryAnalyzer faster than executing this SP as scheduled job? Dan Guzman
12/30/2004 2:38:14 PM
[quoted text, click to view]

It appears you have an INSERT trigger on the table that iterates over the
inserted table.

To improve performance, add SET NOCOUNT ON at the beginning of the trigger
and/or proc to suppress DONE_IN_PROC messages. Also, consider revising the
trigger code to use a set-based technique.

--
Happy Holidays

Dan Guzman
SQL Server MVP

[quoted text, click to view]

Re: why is execution of a storedprocedure in QueryAnalyzer faster than executing this SP as scheduled job? Erland Sommarskog
12/30/2004 2:39:03 PM
Heiko Pliefke (sledge_hammer@freenet.de) writes:
[quoted text, click to view]

I think Tibor addressed this:

Anyhow, it is indeed the " rows affected" messages that causes the
difference between QA and Agent. Agent has a delay for each such "DONE
IN PROC" signal.

There are also differences between QA and Agent with regarding to the
default for some SET options, so with Agent ARITHABORT and QUOTED_IDENTIFIER
are off. This can have severe effect if there is an indexed view or an
indexed computed column somewhere. The optimizer does not consider
these indexes when these two options are off. (There are four more
options that must be on.)


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server SP3 at
why is execution of a storedprocedure in QueryAnalyzer faster than executing this SP as scheduled job? Heiko Pliefke
12/30/2004 3:25:33 PM
Hi NG!

I wrote a stored procedure which at first deletes 100.000 rows and then
inserts 100.000 new rows.

There is a huge difference between executing this SP in the
query-analyzer (runtime approx. 2 minutes), and scheduling this SP as an
Job (runtime > 30 minutes!!!).

Why? Whats the issue?
And how can i improve the "job"-runtime?

The INSERT-Statement gets the data from a joined and grouped SELECT -
here is the code (exemplary):


INSERT INTO [Table1]
(Field1, Field2,... )
SELECT DISTINCT Field1, Count(field2), (Count(field2) * (-1))
FROM Table2 T2
INNER JOIN Table3 T3 ON T2.[ID] = T3.[ID]
INNER JOIN Table4 T4 ON T2.[DID] = T4.[ID]
INNER JOIN Table5 T5 ON T2.[SID] = T5.[ID]
GROUP BY field1, field2...


I have noticed something strange: After executing the SP the
queryanalyzer outputs "1 Row(s) affected." line by line - 100.000
times... Obviously every line is inserted one by one.

Any idea?

Would it help, to create a temporary-table with SELECT INTO, and then
just INSERT this data (w/o aggregation) into the target table?


Any help is greatly appreciated, tia and best regards

---
Re: why is execution of a storedprocedure in QueryAnalyzer faster than executing this SP as scheduled job? Tibor Karaszi
12/30/2004 3:33:30 PM
Strange. If you have several "1 rows affected", you are executing several statements. You get one
such message per DML (INSERT, UPDATE, DELETE or SELECT) statement you are executing. So it sounds to
like you either have a loop of some kind (cursor perhaps) or in some other way a whole bunch of DML
statements. I would look into this as the first step.

Anyhow, it is indeed the " rows affected" messages that causes the difference between QA and Agent.
Agent has a delay for each such "DONE IN PROC" signal. You can lesser the effect by adding SET
NOCOUNT ON in the beginning of the proc code. If there still is a significant difference, try using
a CmdExec jobstep instead from where you execute the proc using OSQL.EXE.

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/


[quoted text, click to view]

Re: why is execution of a storedprocedure in QueryAnalyzer faster than executing this SP as scheduled job? Tibor Karaszi
12/30/2004 3:47:13 PM
[quoted text, click to view]

Good catch, Dan!

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/


[quoted text, click to view]

Re: why is execution of a storedprocedure in QueryAnalyzer faster than executing this SP as scheduled job? Heiko Pliefke
12/30/2004 4:47:47 PM
Hi!

Thank you all for your answers!
I think I know what to do now - i will try and feedback how it works ;)

But there's still one question: Maybe there is a trigger, why is the
execution in QA 10-15times faster than the Job? Doesn't the trigger have
the same "performance-impact" on this two ways?

Dan Guzman schrieb:
[quoted text, click to view]


Best regards,

Re: why is execution of a storedprocedure in QueryAnalyzer faster than executing this SP as scheduled job? Heiko Pliefke
12/30/2004 6:15:36 PM
Hi!

You are great! Thank you very much, Dan and Tibor!
With NOCOUNT OFF the runtime is reduced to < 30 seconds! Super!



Best regards and Happy new year!!

--
Heiko


Tibor Karaszi schrieb:
[quoted text, click to view]
Re: why is execution of a storedprocedure in QueryAnalyzer faster than executing this SP as scheduled job? Heiko Pliefke
12/30/2004 6:18:01 PM
Hi!

You are great! Thank you very much, Dan and Tibor!
With NOCOUNT OFF the runtime is reduced to < 30 seconds! Super!



Best regards and Happy new year!!

--
Re: why is execution of a storedprocedure in QueryAnalyzer faster than executing this SP as scheduled job? Dan Guzman
12/30/2004 6:51:04 PM
[quoted text, click to view]

SQL Agent jobs are more susceptible to DONE_IN_PROC messages as Tibor
stated. See http://support.microsoft.com/default.aspx?scid=kb;en-us;249730

--
Happy Holidays

Dan Guzman
SQL Server MVP

[quoted text, click to view]

Re: why is execution of a storedprocedure in QueryAnalyzer faster than executing this SP as scheduled job? Tibor Karaszi
12/30/2004 7:40:21 PM
[quoted text, click to view]

See my first reply regarding the wait Agent introduces for "rows affected" messages.

--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/


[quoted text, click to view]

AddThis Social Bookmark Button