<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www2.sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>The Hidden Costs of INSERT EXEC</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2009/06/25/the-hidden-costs-of-insert-exec.aspx</link><description>INSERT and EXEC: relational brothers in arms, helping you get your data and then put it somewhere. But like all brothers, their relationship has its ups and downs and sometimes you need to look just below the surface to see the real issues. In this post</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>re: The Hidden Costs of INSERT EXEC</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2009/06/25/the-hidden-costs-of-insert-exec.aspx#14927</link><pubDate>Thu, 25 Jun 2009 20:47:06 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:14927</guid><dc:creator>Florian Reischl</dc:creator><description>&lt;p&gt;Very nice Article, Adam!&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Flo&lt;/p&gt;
</description></item><item><title>re: The Hidden Costs of INSERT EXEC</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2009/06/25/the-hidden-costs-of-insert-exec.aspx#14938</link><pubDate>Fri, 26 Jun 2009 10:44:29 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:14938</guid><dc:creator>LeoPasta</dc:creator><description>&lt;p&gt;Great article, Adam!&lt;/p&gt;
&lt;p&gt;Well done.&lt;/p&gt;
</description></item><item><title>re: The Hidden Costs of INSERT EXEC</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2009/06/25/the-hidden-costs-of-insert-exec.aspx#14954</link><pubDate>Fri, 26 Jun 2009 20:10:59 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:14954</guid><dc:creator>jerryhung</dc:creator><description>&lt;p&gt;1st try&lt;/p&gt;
&lt;p&gt;CPU time - INSERT inside EXEC	CPU time - INSERT EXEC&lt;/p&gt;
&lt;p&gt;396.800000	43.800000&lt;/p&gt;
&lt;p&gt;2nd &amp;amp; 3rd aren't as bad&lt;/p&gt;
&lt;p&gt;87.600000	34.400000&lt;/p&gt;
&lt;p&gt;96.800000	31.400000&lt;/p&gt;
&lt;p&gt;But something new learned today indeed&lt;/p&gt;
</description></item><item><title>re: The Hidden Costs of INSERT EXEC</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2009/06/25/the-hidden-costs-of-insert-exec.aspx#14989</link><pubDate>Sun, 28 Jun 2009 21:59:54 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:14989</guid><dc:creator>Bruce W Cassidy</dc:creator><description>&lt;p&gt;Sometimes it's the things you take for granted that can turn around and bite you. &amp;nbsp;I've always tended to veer to the INSERT... &amp;nbsp;EXEC form myself, proabably for stylistic reasons. &amp;nbsp;Now I will need to challenge that.&lt;/p&gt;
&lt;p&gt;Cheers, good little article! &amp;nbsp;Thought provoking as usual.&lt;/p&gt;
</description></item><item><title>re: The Hidden Costs of INSERT EXEC</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2009/06/25/the-hidden-costs-of-insert-exec.aspx#15034</link><pubDate>Wed, 01 Jul 2009 13:38:32 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15034</guid><dc:creator>ValeriyNY</dc:creator><description>&lt;p&gt;Great post, thought provoking! I usually prefer direct INSERT SELECT, but recently realized the overhead of recompilation if temp table is used. Thus, switching to INSERT EXEC made perfect sense in my case. Of course, as usual, YMMV and the answer is &amp;quot;it depends, test, test, test&amp;quot;. &lt;/p&gt;
</description></item><item><title>re: The Hidden Costs of INSERT EXEC</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2009/06/25/the-hidden-costs-of-insert-exec.aspx#15077</link><pubDate>Fri, 03 Jul 2009 11:47:16 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15077</guid><dc:creator>Nima</dc:creator><description>&lt;p&gt;Hi Adam!&lt;/p&gt;
&lt;p&gt;Great post :)&lt;/p&gt;
&lt;p&gt;Why do I get different results from writes column in sys.dm_exec_requests?&lt;/p&gt;
</description></item><item><title>re: The Hidden Costs of INSERT EXEC</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2009/06/25/the-hidden-costs-of-insert-exec.aspx#15078</link><pubDate>Fri, 03 Jul 2009 11:51:27 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15078</guid><dc:creator>Nima</dc:creator><description>&lt;p&gt;Sorry I mean: different result each time that I query sys.dm_exec_requests!&lt;/p&gt;
</description></item><item><title>re: The Hidden Costs of INSERT EXEC</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2009/06/25/the-hidden-costs-of-insert-exec.aspx#15079</link><pubDate>Fri, 03 Jul 2009 13:53:17 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15079</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Hi Nima,&lt;/p&gt;
&lt;p&gt;I don't understand your question. Can you post a script that shows what you're seeing?&lt;/p&gt;
</description></item><item><title>re: The Hidden Costs of INSERT EXEC</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2009/06/25/the-hidden-costs-of-insert-exec.aspx#15086</link><pubDate>Sat, 04 Jul 2009 17:32:13 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15086</guid><dc:creator>Nima</dc:creator><description>&lt;p&gt;Sorry for my poor explanation!&lt;/p&gt;
&lt;p&gt;I mean when I query sys.dm_exec_requests, it returns 24, next time 26, next time 20 and ....&lt;/p&gt;
</description></item><item><title>re: The Hidden Costs of INSERT EXEC</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2009/06/25/the-hidden-costs-of-insert-exec.aspx#15093</link><pubDate>Sun, 05 Jul 2009 17:21:33 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15093</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Hi Nima,&lt;/p&gt;
&lt;p&gt;Great question! What seems to be causing this is the partially-filled pages that remain from previous inserts. Sometimes more pages have to be allocated to make the insert work and other times some pages that were allocated on the previous run can be reused. This may translate into fewer writes for those attempts since not as many allocations need to be logged.&lt;/p&gt;
</description></item><item><title>re: The Hidden Costs of INSERT EXEC</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2009/06/25/the-hidden-costs-of-insert-exec.aspx#15102</link><pubDate>Mon, 06 Jul 2009 11:25:54 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15102</guid><dc:creator>Nima</dc:creator><description>&lt;p&gt;Thanks Adam!&lt;/p&gt;
&lt;p&gt;What about 'Reads' column? It is always 0 in my batch:&lt;/p&gt;
&lt;p&gt;SELECT * FROM northwind..Orders&lt;/p&gt;
&lt;p&gt;SELECT &amp;nbsp; &amp;nbsp;reads&lt;/p&gt;
&lt;p&gt;FROM sys.dm_exec_requests&lt;/p&gt;
&lt;p&gt;WHERE &amp;nbsp; &amp;nbsp; session_id = @@SPID&lt;/p&gt;
</description></item><item><title>re: The Hidden Costs of INSERT EXEC</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2009/06/25/the-hidden-costs-of-insert-exec.aspx#15140</link><pubDate>Tue, 07 Jul 2009 15:57:20 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15140</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Hi Nima,&lt;/p&gt;
&lt;p&gt;The &amp;quot;reads&amp;quot; column in sys.dm_exec_requests appears to refer to physical reads (it's not documented in exactly that way, but that's the best I've been able to determine). Try the logical_reads column instead.&lt;/p&gt;
</description></item><item><title>re: The Hidden Costs of INSERT EXEC</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2009/06/25/the-hidden-costs-of-insert-exec.aspx#15155</link><pubDate>Wed, 08 Jul 2009 07:13:25 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15155</guid><dc:creator>Nima</dc:creator><description>&lt;p&gt;Thanks indeed! :-)&lt;/p&gt;
</description></item><item><title>re: The Hidden Costs of INSERT EXEC</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2009/06/25/the-hidden-costs-of-insert-exec.aspx#15368</link><pubDate>Mon, 20 Jul 2009 16:07:21 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15368</guid><dc:creator>Roy Harvey</dc:creator><description>&lt;p&gt;&amp;gt;&amp;gt;The answer might just send you racing to check your stored procedures: the additional cost for the Parameter Table is well over 100% as compared with doing the insert inside of the EXEC.&amp;lt;&amp;lt;&lt;/p&gt;
&lt;p&gt;I suspect the percentage would fall if the table has indexes, though the absolute effect would be as described.&lt;/p&gt;
&lt;p&gt;The same idea as INSERT/EXEC is now being written widely with an INSERT/SELECT against a Table Valued Function. &amp;nbsp;An in-line TVF would be fine, since it is just seen as a parameterized view and compiled into the base query as a view would be. &amp;nbsp;However a complex TVF has to be staged into a temporary table and probably has the same overhead as you describe for INSERT/EXEC.&lt;/p&gt;
</description></item><item><title>re: The Hidden Costs of INSERT EXEC</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2009/06/25/the-hidden-costs-of-insert-exec.aspx#15406</link><pubDate>Wed, 22 Jul 2009 10:06:18 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15406</guid><dc:creator>Arif</dc:creator><description>&lt;p&gt;Great article, Adam!&lt;/p&gt;
&lt;p&gt;i have one question&lt;/p&gt;
&lt;p&gt;Does SQL Server cache the plan for dynamic queries ?&lt;/p&gt;
&lt;p&gt;if yes then what is the disadvantage of a simple dynamic query&lt;/p&gt;
</description></item><item><title>re: The Hidden Costs of INSERT EXEC</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2009/06/25/the-hidden-costs-of-insert-exec.aspx#15523</link><pubDate>Mon, 27 Jul 2009 15:06:32 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15523</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Hi Arif,&lt;/p&gt;
&lt;p&gt;Yes, plans are cached for dynamic queries. I'm not sure what you mean when you ask about the &amp;quot;disadvantage of a simple dynamic query.&amp;quot; There are advantages and disadvantages, depending on what it is that you're doing. You might want to read Erland Sommarskog's article, &amp;quot;The Curse and Blessings of Dynamic SQL&amp;quot;:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://sommarskog.se/dynamic_sql.html"&gt;http://sommarskog.se/dynamic_sql.html&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>re: The Hidden Costs of INSERT EXEC</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2009/06/25/the-hidden-costs-of-insert-exec.aspx#39143</link><pubDate>Tue, 18 Oct 2011 08:40:06 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:39143</guid><dc:creator>Ranu Mandan</dc:creator><description>&lt;p&gt;Do it solves nested EXEC restriction ?&lt;/p&gt;
</description></item></channel></rss>