 




<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: SQL Server 2005 Query Very Slow in the first run</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/itanswers/sql-server-2005-query-very-slow-in-the-first-run/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/itanswers/sql-server-2005-query-very-slow-in-the-first-run/</link>
	<description></description>
	<lastBuildDate>Sat, 18 May 2013 20:55:13 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
	<item>
		<title>By: kccrosser</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/sql-server-2005-query-very-slow-in-the-first-run/#comment-66028</link>
		<dc:creator>kccrosser</dc:creator>
		<pubDate>Fri, 24 Jul 2009 15:25:39 +0000</pubDate>
		<guid isPermaLink="false">#comment-66028</guid>
		<description><![CDATA[Actually, if the performance is due to initial loading of the data rows into memory (which is what it sounds like), using a stored procedure won&#039;t make that much difference.
The real key is to understand the query operation and make sure it is only loading those rows that it really needs.]]></description>
		<content:encoded><![CDATA[<p>Actually, if the performance is due to initial loading of the data rows into memory (which is what it sounds like), using a stored procedure won&#8217;t make that much difference.<br />
The real key is to understand the query operation and make sure it is only loading those rows that it really needs.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: findsarfaraz</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/sql-server-2005-query-very-slow-in-the-first-run/#comment-66003</link>
		<dc:creator>findsarfaraz</dc:creator>
		<pubDate>Fri, 24 Jul 2009 08:30:44 +0000</pubDate>
		<guid isPermaLink="false">#comment-66003</guid>
		<description><![CDATA[Also, you can use store procedure instead of query. As in stored procedure you can use temp tables which will definitely enhance your query performance. 

Regards,
Sarfaraz Ahmed
&lt;a href=&quot;http://findsarfaraz.blogspot.com&quot;&gt;Microsoft Excel help&lt;/a&gt;]]></description>
		<content:encoded><![CDATA[<p>Also, you can use store procedure instead of query. As in stored procedure you can use temp tables which will definitely enhance your query performance. </p>
<p>Regards,<br />
Sarfaraz Ahmed<br />
<a href="http://findsarfaraz.blogspot.com">Microsoft Excel help</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jsql</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/sql-server-2005-query-very-slow-in-the-first-run/#comment-65824</link>
		<dc:creator>jsql</dc:creator>
		<pubDate>Tue, 21 Jul 2009 06:04:57 +0000</pubDate>
		<guid isPermaLink="false">#comment-65824</guid>
		<description><![CDATA[Thank you very much Carlosdl and kccrosser.

This will help me to research further.]]></description>
		<content:encoded><![CDATA[<p>Thank you very much Carlosdl and kccrosser.</p>
<p>This will help me to research further.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: kccrosser</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/sql-server-2005-query-very-slow-in-the-first-run/#comment-65807</link>
		<dc:creator>kccrosser</dc:creator>
		<pubDate>Mon, 20 Jul 2009 19:42:10 +0000</pubDate>
		<guid isPermaLink="false">#comment-65807</guid>
		<description><![CDATA[Some specific areas to look at in your query above are all the joins that include functions on the underlying columns - ltrim, rtrim, len, and substring.

Any time you apply a function to a column in the where/join clause, you eliminate the ability of the query optimizer to use indexes on the column.  Further, if the query optimizer doesn&#039;t have other good indexes to use, it may &quot;invert&quot; the query (as I call it) where it uses the primary key of the table to do a cartesian product join with another table, and then apply the functions to the resulting giant intermediate result set.
&lt;b&gt;Avoid functions on columns in a where/join clause like the plague...&lt;/b&gt;

Some of your joins are using &quot;ltrim(rtrim(&lt;column&gt;))&quot;.  Much better would be to enforce removal of leading/trailing blanks on data entry (with a trigger, perhaps), which would allow you to do direct compares of the data in the columns without the functions, and therefore allow use of indexes on those columns.

Also note that &quot;len(ltrim(remarks)) &gt; 0&quot; should be the same as &quot;remarks is not null&quot; if you eliminate leading/trailing blanks on entry.  The &quot;len(trim())&quot; expression could cause a table scan, while &quot;remarks is not null&quot; *could* use an index on that column (it might not, depending on the actual distribution of data in the records).

Finally, if there is no good way to avoid leading/trailing blanks in the data, you might consider creating materialized views of the data where the view contains the blank-stripped data and has a column containing the field lengths where needed.  Then, your query can go against that view.  Depending on the volume of updates to the table and view, this could dramatically speed up the query.  (Note that a &quot;materialized&quot; view is a &quot;real&quot; table containing the massaged data from the underlying tables, and that this table can be indexed like any other tables - just creating a standard &quot;view&quot; will NOT generally gain any performance, as the view will be constructed at query time with no advantage over just running the query.)]]></description>
		<content:encoded><![CDATA[<p>Some specific areas to look at in your query above are all the joins that include functions on the underlying columns &#8211; ltrim, rtrim, len, and substring.</p>
<p>Any time you apply a function to a column in the where/join clause, you eliminate the ability of the query optimizer to use indexes on the column.  Further, if the query optimizer doesn&#8217;t have other good indexes to use, it may &#8220;invert&#8221; the query (as I call it) where it uses the primary key of the table to do a cartesian product join with another table, and then apply the functions to the resulting giant intermediate result set.<br />
<b>Avoid functions on columns in a where/join clause like the plague&#8230;</b></p>
<p>Some of your joins are using &#8220;ltrim(rtrim(&lt;column&gt;))&#8221;.  Much better would be to enforce removal of leading/trailing blanks on data entry (with a trigger, perhaps), which would allow you to do direct compares of the data in the columns without the functions, and therefore allow use of indexes on those columns.</p>
<p>Also note that &#8220;len(ltrim(remarks)) &gt; 0&#8243; should be the same as &#8220;remarks is not null&#8221; if you eliminate leading/trailing blanks on entry.  The &#8220;len(trim())&#8221; expression could cause a table scan, while &#8220;remarks is not null&#8221; *could* use an index on that column (it might not, depending on the actual distribution of data in the records).</p>
<p>Finally, if there is no good way to avoid leading/trailing blanks in the data, you might consider creating materialized views of the data where the view contains the blank-stripped data and has a column containing the field lengths where needed.  Then, your query can go against that view.  Depending on the volume of updates to the table and view, this could dramatically speed up the query.  (Note that a &#8220;materialized&#8221; view is a &#8220;real&#8221; table containing the massaged data from the underlying tables, and that this table can be indexed like any other tables &#8211; just creating a standard &#8220;view&#8221; will NOT generally gain any performance, as the view will be constructed at query time with no advantage over just running the query.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: carlosdl</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/sql-server-2005-query-very-slow-in-the-first-run/#comment-65779</link>
		<dc:creator>carlosdl</dc:creator>
		<pubDate>Mon, 20 Jul 2009 14:02:12 +0000</pubDate>
		<guid isPermaLink="false">#comment-65779</guid>
		<description><![CDATA[Have a look at the following pages:

&lt;a href=&quot;http://www.sql-server-performance.com/tips/query_execution_plan_analysis_p1.aspx&quot;&gt;SQL Server Query Execution Plan Analysis&lt;/a&gt;
&lt;a href=&quot;http://www.simple-talk.com/sql/performance/execution-plan-basics/&quot;&gt;Execution Plan Basics&lt;/a&gt;
&lt;a href=&quot;http://blogs.techrepublic.com.com/datacenter/?p=269&quot;&gt;Capture execution plans with SQL Server 2005 Profiler&lt;/a&gt;]]></description>
		<content:encoded><![CDATA[<p>Have a look at the following pages:</p>
<p><a href="http://www.sql-server-performance.com/tips/query_execution_plan_analysis_p1.aspx">SQL Server Query Execution Plan Analysis</a><br />
<a href="http://www.simple-talk.com/sql/performance/execution-plan-basics/">Execution Plan Basics</a><br />
<a href="http://blogs.techrepublic.com.com/datacenter/?p=269">Capture execution plans with SQL Server 2005 Profiler</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jsql</title>
		<link>http://itknowledgeexchange.techtarget.com/itanswers/sql-server-2005-query-very-slow-in-the-first-run/#comment-65770</link>
		<dc:creator>jsql</dc:creator>
		<pubDate>Mon, 20 Jul 2009 05:31:08 +0000</pubDate>
		<guid isPermaLink="false">#comment-65770</guid>
		<description><![CDATA[Hi Kccrosser,

Thanks for your valuable answer.

I can see this kind of effect in any simple sql query. 

Can you point me to the right source where I can find detailed information on how to read the execution plan and do the performance tuning.

Thanks,
John]]></description>
		<content:encoded><![CDATA[<p>Hi Kccrosser,</p>
<p>Thanks for your valuable answer.</p>
<p>I can see this kind of effect in any simple sql query. </p>
<p>Can you point me to the right source where I can find detailed information on how to read the execution plan and do the performance tuning.</p>
<p>Thanks,<br />
John</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using memcached
Database Caching 3/10 queries in 0.041 seconds using memcached
Object Caching 337/343 objects using memcached

Served from: itknowledgeexchange.techtarget.com @ 2013-05-18 23:07:55 -->