<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.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>Query performance and plan cache issues when parameter length not specified correctly</title><link>http://blogs.msdn.com/b/psssql/archive/2010/10/05/query-performance-and-plan-cache-issues-when-parameter-length-not-specified-correctly.aspx</link><description>We recently worked with a customer who reported his update to a linked server table runs very slow. This only happens when he doesn&amp;rsquo;t specify the character parameter length in the .NET code. This actually brings up plan cache issue as well. So this</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Query performance and plan cache issues when parameter length not specified correctly</title><link>http://blogs.msdn.com/b/psssql/archive/2010/10/05/query-performance-and-plan-cache-issues-when-parameter-length-not-specified-correctly.aspx#10252323</link><pubDate>Sun, 01 Jan 2012 20:23:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10252323</guid><dc:creator>Milind Trivedi</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Just want to confirm from you that, if table column length has varchar(50) and query variable length has varchar(25) does this difference make any difference in the query execution?&lt;/p&gt;
&lt;p&gt;Example:&lt;/p&gt;
&lt;p&gt;--==============&lt;/p&gt;
&lt;p&gt;Create table TableName (Col1 int, Col2 varchar(50))&lt;/p&gt;
&lt;p&gt;go&lt;/p&gt;
&lt;p&gt;declare @str varchar(25)&lt;/p&gt;
&lt;p&gt;select @str = &amp;#39;my text&amp;#39;&lt;/p&gt;
&lt;p&gt;select * from TableName where Col2 = @str&lt;/p&gt;
&lt;p&gt;--==============&lt;/p&gt;
&lt;p&gt;As per execution plan there is no difference. Can you please confirm? Is that SQL internally adjusting the length or it will ignore because of length is less than actual length?&lt;/p&gt;
&lt;p&gt;Thanks..&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10252323" width="1" height="1"&gt;</description></item><item><title>re: Query performance and plan cache issues when parameter length not specified correctly</title><link>http://blogs.msdn.com/b/psssql/archive/2010/10/05/query-performance-and-plan-cache-issues-when-parameter-length-not-specified-correctly.aspx#10072205</link><pubDate>Wed, 06 Oct 2010 13:30:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10072205</guid><dc:creator>JackLi</dc:creator><description>&lt;p&gt;Regarding Michael&amp;#39;s comment about nvarchar and varchar, it&amp;#39;s a typo. &amp;nbsp;It&amp;#39;s corrected now. thanks for pointing this out. &amp;nbsp; The example intended to use varchar data type though the problem also occurs for nvarchar data type. &amp;nbsp;If your column is varchar, you will need to use SqlDbType.VarChar. &amp;nbsp; If your column is nvarchar, you will need to use SqlDbType.NVarChar. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regarding JR&amp;#39;s question: &amp;nbsp; None of the two problems described here apply to stored procedure. &amp;nbsp;Stored procedure will perform just fine and there will be not cache bloating either.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10072205" width="1" height="1"&gt;</description></item><item><title>re: Query performance and plan cache issues when parameter length not specified correctly</title><link>http://blogs.msdn.com/b/psssql/archive/2010/10/05/query-performance-and-plan-cache-issues-when-parameter-length-not-specified-correctly.aspx#10072051</link><pubDate>Wed, 06 Oct 2010 05:47:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10072051</guid><dc:creator>Michael Codanti</dc:creator><description>&lt;p&gt;I noticed that in addition to specifying the size you changed the type from NVARCHAR to VARCHAR:&lt;/p&gt;
&lt;p&gt;Orig: cmd.Parameters.Add(&amp;quot;@c2&amp;quot;, SqlDbType.NVarChar).Value = str; &lt;/p&gt;
&lt;p&gt;New: &amp;nbsp;cmd.Parameters.Add(&amp;quot;@c2&amp;quot;, SqlDbType.VarChar, 500).Value = str;&lt;/p&gt;
&lt;p&gt;Would that have anything to do with the linked query performance issue?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10072051" width="1" height="1"&gt;</description></item><item><title>re: Query performance and plan cache issues when parameter length not specified correctly</title><link>http://blogs.msdn.com/b/psssql/archive/2010/10/05/query-performance-and-plan-cache-issues-when-parameter-length-not-specified-correctly.aspx#10071901</link><pubDate>Tue, 05 Oct 2010 21:27:30 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10071901</guid><dc:creator>JR</dc:creator><description>&lt;p&gt;Does this affect stored procedure execution where CommandType is StoredProcedure?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10071901" width="1" height="1"&gt;</description></item></channel></rss>