Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 7,2000
»
T-SQL
»
stored procedure vs individual insert...
stored procedure vs individual insert statements
Rate Topic
Display Mode
Topic Options
Author
Message
mgraulich
mgraulich
Posted Wednesday, January 09, 2008 11:17 AM
SSC Journeyman
Group: General Forum Members
Last Login: Sunday, October 04, 2009 7:33 AM
Points: 84,
Visits: 43
Why is it that if I run the individual insert statements in Example A one at a time, the overall time to run is 20 minutes. If I put all of the insert statements into a stored proc, it takes an hour and a half? Same inserts.
Example A
insert into prod1
select *
from test1
insert into prod2
select *
from test2
insert into test3
select *
from test3
etc
Post #440824
Sergiy
Sergiy
Posted Wednesday, January 09, 2008 3:34 PM
SSCarpal Tunnel
Group: General Forum Members
Last Login: Today @ 7:03 AM
Points: 4,557,
Visits: 8,236
What happens if you execute those inserts in a batch?
Post #440929
mgraulich
mgraulich
Posted Wednesday, January 09, 2008 3:41 PM
SSC Journeyman
Group: General Forum Members
Last Login: Sunday, October 04, 2009 7:33 AM
Points: 84,
Visits: 43
Pardon for my ignorance but what do you mean by batch?
Post #440933
Sergiy
Sergiy
Posted Wednesday, January 09, 2008 3:54 PM
SSCarpal Tunnel
Group: General Forum Members
Last Login: Today @ 7:03 AM
Points: 4,557,
Visits: 8,236
I mean executing all 3 statements in one go but without wrapping it in a procedure.
Just as you pasted it here.
Post #440937
Jeremy-475548
Jeremy-475548
Posted Wednesday, January 09, 2008 8:47 PM
SSC-Enthusiastic
Group: General Forum Members
Last Login: Sunday, September 23, 2012 7:57 PM
Points: 168,
Visits: 789
Is it a typo, or are you really intending on selecting the same table into itself?
I've noticed this on occasion as well (something runs well/as expected in query analyzer, but the moment it is a procedure, performance plummets). Perhaps greater SQL minds than mine have some insight into this problem. These are just my random musings, but I wonder if it has something to do with transaction management/locking and latching. I wonder if wrapping each statement in a begin tran/commit block would help, since it would force out writes to the transaction log.
The other thing is if you are really selecting the same table into itself, depending on its size, consider copying out the records to a temp table, and copying them back in to prevent contention or latching or locking to the table. SQL Gurus, please step in if I've misstated something here, because this area has always been somewhat of a mystery to me.
Hope this at least sparks some interesting thought.
Thanks!
Post #440977
Sergiy
Sergiy
Posted Wednesday, January 09, 2008 9:35 PM
SSCarpal Tunnel
Group: General Forum Members
Last Login: Today @ 7:03 AM
Points: 4,557,
Visits: 8,236
Jeremy,
there is no any point in wrapping each statement in a begin tran/commit block because they are transactions anyway.
And I would guess that was a typo.
I really doubt real tables have got such funny names. :)
Regarding this I would say that devil is usually in details.
Posting real statements could be very helpful.
The real reason could be anything we don't see: misuse of parameters, remote calls, even typo in script.
Post #440985
Jerome.J.N
Jerome.J.N
Posted Wednesday, January 09, 2008 9:41 PM
Mr or Mrs. 500
Group: General Forum Members
Last Login: Thursday, June 13, 2013 3:05 AM
Points: 541,
Visits: 93
Can u pls paste those queries here so that v can check if they need some fine tuning or u can check if ur tables r indexed properly.
All this while I was under the impression that stored procedures run faster cuz they r pre compiled. Correct me if I'm wrong.
Post #440986
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.