SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Insert Exec Performance issue ??


Insert Exec Performance issue ??

Author
Message
aakash214
aakash214
SSC Journeyman
SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)SSC Journeyman (76 reputation)

Group: General Forum Members
Points: 76 Visits: 253
Hi,

I have a procedure which has a code something like

My SP is dynamic something like

WHILE(@i <= @max)

BEGIN

SELECT @db_name = db_name, @db_server_name = db_server_name from #dbs where id = @i

SET @SQL = 'EXEC '+@db_server_name+'.'+@db_name+'.dbo.SP_NAME '+@param1+','+@param2


INSERT into #temp(...)

EXEC (@SQL)

END

When I execute SP without insert statement (without insert into #temp(..)) SP returns in 2 seconds. But, when data is inserted into temp table it takes 7-8 seconds.

Only 36 records are returned.

I tried using Table Variables but it doesn't help. Even tried Permanent table but still no use.

My question is why is INSERT.. EXEC.. taking too long time than just an EXEC .. And is there any better option than that. I tried googling out to find solution and came across various posts saying INSERT.. EXEC.. has performance impact. Few pointed out to Linked Server being slow. But, I was not able to find any solution.

Thanks for your help. Will be happy to provide any other information requried.
Lynn Pettis
Lynn Pettis
SSC-Dedicated
SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)SSC-Dedicated (38K reputation)

Group: General Forum Members
Points: 38903 Visits: 38508
aakash214 (3/7/2013)
Hi,

I have a procedure which has a code something like

My SP is dynamic something like

WHILE(@i <= @max)

BEGIN

SELECT @db_name = db_name, @db_server_name = db_server_name from #dbs where id = @i

SET @SQL = 'EXEC '+@db_server_name+'.'+@db_name+'.dbo.SP_NAME '+@param1+','+@param2


INSERT into #temp(...)

EXEC (@SQL)

END

When I execute SP without insert statement (without insert into #temp(..)) SP returns in 2 seconds. But, when data is inserted into temp table it takes 7-8 seconds.

Only 36 records are returned.

I tried using Table Variables but it doesn't help. Even tried Permanent table but still no use.

My question is why is INSERT.. EXEC.. taking too long time than just an EXEC .. And is there any better option than that. I tried googling out to find solution and came across various posts saying INSERT.. EXEC.. has performance impact. Few pointed out to Linked Server being slow. But, I was not able to find any solution.

Thanks for your help. Will be happy to provide any other information requried.


Just a guess, but it could be because SQL Server has to run the insert in a distributed transact and it is taking a little extra time for that to be accomplished. I don't have a distributed environment in which I can test this theory.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search