<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://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>Search results matching tag 'Memory Management'</title><link>http://sqlblog.com/search/SearchResults.aspx?o=DateDescending&amp;tag=Memory+Management&amp;orTags=0</link><description>Search results matching tag 'Memory Management'</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>The Myth Around 32-bit SQL Server Instances on 64-bit Operating Systems, and AWE</title><link>http://sqlblog.com/blogs/argenis_fernandez/archive/2012/12/30/the-myth-around-32-bit-sql-server-instances-on-64-bit-operating-systems-and-awe.aspx</link><pubDate>Sun, 30 Dec 2012 23:36:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:46892</guid><dc:creator>Argenis</dc:creator><description>&lt;p&gt;&lt;i&gt;(I’m taking a break from my DBA Best Practices blog series to talk about this today – the series continues after the Holidays!)&lt;/i&gt;&lt;/p&gt;
  
&lt;p&gt;I love to be proved wrong. Really, I do.&lt;/p&gt;
  
&lt;p&gt;Recently we had a discussion in an distribution list where somebody asked whether a SQL Server 32-bit instance could address more than 4Gb of RAM when running on top of a 64-bit OS. One of the really smart guys in Microsoft SQL Server Support, Karthick P.K.&amp;nbsp;[&lt;a href="http://mssqlwiki.com/"&gt;Blog&lt;/a&gt;|&lt;a href="http://blogs.msdn.com/b/karthick_pk/"&gt;Blog&lt;/a&gt;|&lt;a href="https://twitter.com/mssqlwiki"&gt;Twitter&lt;/a&gt;]&amp;nbsp;replied “sure, just add more RAM and enable AWE – SQL will use that memory”. I was much convinced that this was incorrect, so I jumped in and said that AWE does nothing under those circumstances. After all, that is what I had read in the past in many different &lt;a href="http://msdn.microsoft.com/en-us/library/ms187499(v=sql.105).aspx"&gt;articles&lt;/a&gt;. I even had some SQL Server MVPs who have been around the block forever agreeing with me.&lt;/p&gt;
  
&lt;p&gt;But the good news is that I was wrong.&lt;/p&gt;
  
&lt;p&gt;&lt;b&gt;AWE in fact does nothing on 64-bit instances of SQL Server. But on WOW64 - Windows on Windows 64-bit, the subsystem of Windows x64 that allows you to run 32-bit processes and instances of SQL Server, AWE does allow you to address memory above 4Gb&lt;/b&gt;. Let me show you.&lt;/p&gt;
  
&lt;p&gt;Side note: AWE is now deprecated - removed in SQL Server 2012. The last version of SQL Server that supports AWE is SQL Server 2008 R2. Because of this, a SQL Server 2012 x86 instance won’t be able to enjoy over 4Gb of memory – even if running on WOW64.&lt;/p&gt;
  
&lt;p&gt;I setup a vanilla VM in my lab with a 64-bit OS with 8Gb of memory. MSINFO32 looks like this on the VM:&lt;/p&gt;
  
&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/argenis_fernandez/image_285792A7.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/argenis_fernandez/image_thumb_29521335.png" width="1028" height="772"&gt;&lt;/a&gt;&lt;/p&gt;
  
&lt;p&gt;I installed a 32-bit SQL Server 2008 R2 SP2 instance on the VM. @@VERSION looked like this:&lt;/p&gt;
  
&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/argenis_fernandez/image_720B8BF9.png"&gt;&lt;img style="border-width:0px;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/argenis_fernandez/image_thumb_7DA3D9E9.png" width="1128" height="132"&gt;&lt;/a&gt;&lt;/p&gt;
  
&lt;p&gt;&lt;b&gt;I did not enable AWE&lt;/b&gt;. I did grant the “Perform Volume Maintenance Tasks” and “Lock Pages in Memory” privileges using secpol.msc (not pictured!). I wanted to see what memory consumption would look like without AWE enabled.&lt;/p&gt;
  
&lt;p&gt;This screenshot shows the permissions granted to the SQL Server Service Account (NETWORK SERVICE, in this case) – used “whoami /priv”, a quick and dirty way to get the privileges of the service account using xp_cmdshell. Ugh, xp_cmdshell. It’s okay, it’s just a test.&lt;/p&gt;
  
&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/argenis_fernandez/image_34148BEC.png"&gt;&lt;img style="border:0px currentColor;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/argenis_fernandez/image_thumb_612978BA.png" width="720" height="586"&gt;&lt;/a&gt;&lt;/p&gt;
  
&lt;p&gt;I went ahead and created a test database with just one big table – big enough to use all the buffer pool memory on the instance when a size-of-data operation is executed on it. I did set Max Server Memory to 6Gb.&lt;/p&gt;
  
&lt;p&gt;Here’s the CREATE table script:&lt;/p&gt;
  
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;CREATE&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; [dbo].[testTable](
    [id] [&lt;span class="kwrd"&gt;int&lt;/span&gt;] &lt;span class="kwrd"&gt;IDENTITY&lt;/span&gt;(1,1) &lt;span class="kwrd"&gt;NOT&lt;/span&gt; &lt;span class="kwrd"&gt;NULL&lt;/span&gt;,
    [wideColumn] [nvarchar](4000) &lt;span class="kwrd"&gt;NULL&lt;/span&gt;,
        &lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt; &lt;span class="kwrd"&gt;KEY&lt;/span&gt; &lt;span class="kwrd"&gt;CLUSTERED&lt;/span&gt; 
        (
            [id] &lt;span class="kwrd"&gt;ASC&lt;/span&gt;
        )&lt;span class="kwrd"&gt;WITH&lt;/span&gt; (PAD_INDEX  = &lt;span class="kwrd"&gt;OFF&lt;/span&gt;, STATISTICS_NORECOMPUTE  = &lt;span class="kwrd"&gt;OFF&lt;/span&gt;, IGNORE_DUP_KEY = &lt;span class="kwrd"&gt;OFF&lt;/span&gt;, ALLOW_ROW_LOCKS  = &lt;span class="kwrd"&gt;ON&lt;/span&gt;, ALLOW_PAGE_LOCKS  = &lt;span class="kwrd"&gt;ON&lt;/span&gt;) &lt;span class="kwrd"&gt;ON&lt;/span&gt; [&lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt;]
) &lt;span class="kwrd"&gt;ON&lt;/span&gt; [&lt;span class="kwrd"&gt;PRIMARY&lt;/span&gt;]
&lt;span class="kwrd"&gt;GO&lt;/span&gt;
&lt;span class="kwrd"&gt;ALTER&lt;/span&gt; &lt;span class="kwrd"&gt;TABLE&lt;/span&gt; [dbo].[testTable] &lt;span class="kwrd"&gt;ADD&lt;/span&gt; &lt;span class="kwrd"&gt;DEFAULT&lt;/span&gt; (replicate(N&lt;span class="str"&gt;'A'&lt;/span&gt;,(4000))) &lt;span class="kwrd"&gt;FOR&lt;/span&gt; [wideColumn]
GO&lt;/pre&gt;

&lt;p&gt;Next, I went ahead and inserted 1M rows on the table:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;INSERT &lt;span class="kwrd"&gt;INTO&lt;/span&gt; [dbo].[testTable] &lt;span class="kwrd"&gt;DEFAULT&lt;/span&gt; &lt;span class="kwrd"&gt;VALUES&lt;/span&gt;
&lt;span class="kwrd"&gt;GO&lt;/span&gt; 1000000&lt;/pre&gt;

&lt;p&gt;If you do the math very quickly, you will agree with me that this not so little table will be more than 6Gb in size. Let’s check anyway:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/argenis_fernandez/image_0A3417B7.png"&gt;&lt;img style="border:0px currentColor;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/argenis_fernandez/image_thumb_7E9E5A77.png" width="436" height="139"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cool! The table is large enough for the purpose of this test. But how does memory utilization look like after that 1M row insert?&lt;/p&gt;

&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/argenis_fernandez/image_451B4A80.png"&gt;&lt;img style="border:0px currentColor;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/argenis_fernandez/image_thumb_6772DFF9.png" width="776" height="140"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s less than 4Gb. Next I turned on AWE, and restarted the instance. Then I queried the ERRORLOG to confirm that AWE was enabled:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/argenis_fernandez/image_0DD4C345.png"&gt;&lt;img style="border:0px currentColor;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/argenis_fernandez/image_thumb_77157BBB.png" width="776" height="140"&gt;&lt;/a&gt;&lt;/p&gt;









&lt;p&gt;Okay, since I had just restarted the instance my buffer pool was gone – needed to force a size of data operation on the large table. Rebuilding the clustered index did just fine (I know, that’s probably overkill). Then I checked sys.dm_os_process_memory again:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://sqlblog.com/blogs/argenis_fernandez/image_4B64B1BF.png"&gt;&lt;img style="border:0px currentColor;padding-top:0px;padding-right:0px;padding-left:0px;display:inline;background-image:none;" title="image" border="0" alt="image" src="http://sqlblog.com/blogs/argenis_fernandez/image_thumb_34A56A36.png" width="666" height="197"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And there we go! A lot more than 4Gb being used now that AWE is in play. I had set Max Server Memory to 6Gb, as I detailed earlier.&lt;/p&gt;

&lt;p&gt;It looks like there’s quite a lot of incorrect documentation regarding this, so I wanted to clear out any confusion – and learn something new along the way. Don’t you love SQL Server? &lt;img class="wlEmoticon wlEmoticon-smile" alt="Smile" src="http://sqlblog.com/blogs/argenis_fernandez/wlEmoticon-smile_4FDDC337.png"&gt;&lt;/p&gt;

&lt;p&gt;Happy Holidays and Happy New Year!&lt;/p&gt;

&lt;p&gt;-Argenis&lt;/p&gt;&lt;p&gt;P.S.: If you are running IA64 (Itanium) - then this doesn't apply to you. AWE does not work at all on IA64.&lt;/p&gt;</description></item><item><title>Did You Know: Good Stuff!</title><link>http://sqlblog.com/blogs/kalen_delaney/archive/2010/06/30/good-stuff-including-memory-grants.aspx</link><pubDate>Wed, 30 Jun 2010 21:33:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:26635</guid><dc:creator>Kalen Delaney</dc:creator><description>&lt;P&gt;I know, I promised a technical post after my online seminar today, and I'm still planning on that. There weren't all that many really deep questions, just a lot of basic understanding questions, plus questions about topics I'll be covering in my Plan Caching and Recompilation Seminar in August. There was one really interesting question about a particular behavior that I am researching, so that might turn into a post. Also, it's always fun to see people react to using GO with a number, if they've never seen it before, as I discussed here:&lt;/P&gt;
&lt;P&gt;&lt;A title=http://sqlblog.com/blogs/kalen_delaney/archive/2007/07/22/did-you-know-run-a-batch-multiple-times.aspx href="http://sqlblog.com/blogs/kalen_delaney/archive/2007/07/22/did-you-know-run-a-batch-multiple-times.aspx"&gt;http://sqlblog.com/blogs/kalen_delaney/archive/2007/07/22/did-you-know-run-a-batch-multiple-times.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;I don't do a lot of pointers to other bloggers, but this one I just can't resist. I found two excellent posts by Jay Choe, of the SQL Server Engine team at Microsoft, explaining about Memory Grants:&lt;/P&gt;
&lt;P&gt;&lt;A title=http://blogs.msdn.com/b/sqlqueryprocessing/archive/2010/02/16/understanding-sql-server-memory-grant.aspx href="http://blogs.msdn.com/b/sqlqueryprocessing/archive/2010/02/16/understanding-sql-server-memory-grant.aspx"&gt;http://blogs.msdn.com/b/sqlqueryprocessing/archive/2010/02/16/understanding-sql-server-memory-grant.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A title=http://blogs.msdn.com/b/sqlqueryprocessing/archive/2010/03/11/mystery-of-memory-fraction-in-showplan-xml.aspx href="http://blogs.msdn.com/b/sqlqueryprocessing/archive/2010/03/11/mystery-of-memory-fraction-in-showplan-xml.aspx"&gt;http://blogs.msdn.com/b/sqlqueryprocessing/archive/2010/03/11/mystery-of-memory-fraction-in-showplan-xml.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;These should keep your brain busy until my next technical post …&lt;/P&gt;
&lt;P&gt;Have fun!&lt;/P&gt;
&lt;P&gt;&lt;BR&gt;&lt;FONT color=#ff00ff size=4&gt;~Kalen&lt;/FONT&gt;&lt;/P&gt;</description></item><item><title>Did You Know? What PreCon would I take if I were attending TechEd?</title><link>http://sqlblog.com/blogs/kalen_delaney/archive/2010/05/17/precon-at-teched.aspx</link><pubDate>Tue, 18 May 2010 00:27:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:25235</guid><dc:creator>Kalen Delaney</dc:creator><description>&lt;P&gt;TechEd starts in 3 weeks, and I'm not going to make it this year. I had very much wanted to visit New Orleans post-Katrina and see the recovery for myself. I attended a couple of TechEd's there many years ago, but my primary reason for visiting that fabulous city was because my daughter went to school there. She graduated from Tulane University in 1999, but it just so happened that every time TechEd was there, it was after school was over for the year, so I never got to combine my conference trip with a family visit. &lt;/P&gt;
&lt;P&gt;If you're going to the conference, and you're trying to decide what PreCon session to sign up for, I've got a suggestion for you.&lt;/P&gt;
&lt;P&gt;You might be aware that I have a &lt;A href="http://syllabus.kalendelaney.com/"&gt;5-day SQL Server Internals course&lt;/A&gt;, that is based on the material in my book(s). For the last few years, there has only &lt;A href="http://www.karaszi.com/SQLServer/about_me.asp"&gt;been one other person besides me&lt;/A&gt;, in the entire world, whom I have authorized to teach my course.&amp;nbsp; I'm proud to announce that just last week, the second authorized trainer presented my course for the first time. Maciej (&lt;A href="http://www.pronouncenames.com/pronounce/maciej"&gt;how do you pronounce this?&lt;/A&gt;) Pilecki taught the course in Warsaw and will be teaching it again &lt;A href="http://entwickler-akademie.de/codecamps/workshop-maciej-pilecki"&gt;in Germany this November&lt;/A&gt;. &lt;/P&gt;
&lt;P&gt;I just found out today that Maciej will be giving a &lt;A href="http://northamerica.msteched.com/preconferenceseminars?fbid=jCe_dRVPP9R"&gt;full day session at TechEd&lt;/A&gt; called :&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;Secrets of the SQLOS: &lt;BR&gt;Leveraging Microsoft SQL Server Internal Operating System for Improved Scalability and Performance&lt;/STRONG&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So this session goes beyond what I cover in my class, down into the interaction between SQL Server and the operating system, and the topic is one of Maciej's specialties. If you've never heard Maciej talk about SQL Server memory management (or even if you have!), you won't regret taking this precon.&lt;/P&gt;
&lt;P&gt;It's not too late to sign up!&lt;/P&gt;
&lt;P&gt;Have fun!&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff00ff size=4&gt;~Kalen&lt;/FONT&gt;&lt;/P&gt;</description></item><item><title>Geek City: Q &amp;amp; A on my Plan Cache Sizing article in SQL Server Magazine</title><link>http://sqlblog.com/blogs/kalen_delaney/archive/2007/12/15/QA-on-my-plan-cache-sizing-article-in-sql-server-magazine.aspx</link><pubDate>Sun, 16 Dec 2007 03:00:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:4004</guid><dc:creator>Kalen Delaney</dc:creator><description>&lt;BLOCKQUOTE&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="http://www.sqlmag.com/articles/articleid/97373/Managing_PlanCache_Size.html" target=_blank&gt;My December article in SQL Server Magazine&lt;/A&gt;, called Managing Plan Cache Size, expands on the information I talked about in a &lt;A href="http://sqlblog.com/blogs/kalen_delaney/archive/2007/11/04/did-you-know-sp2-does-not-limit-the-amount-of-plan-cache-you-can-have.aspx" target=_blank&gt;post last month on the limits of plan cache&lt;/A&gt;.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;A reader of the article ask some questions on the SQL Server Magazine web site, and I have decided to use my blog to post the answers. &lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Q:&amp;nbsp; Could you give me an illustration how to calculate target memory please? Let say there is a 64 bit system (64 bit hardware, windows 2003 64 bit enterprise edition, SQL Server 2005 Enterprise edition 64 bit, memory 30 GB), max server memory (in sp_configure) is between 16 (min value) - 30 GB (max value)).&lt;/EM&gt; &lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P align=left&gt;A: Target memory refers to the maximum physical memory that can be committed to the buffer pool and ideally is the lesser of the values you’ve configured for “max server memory” and the total amount of visible physical memory available to the OS. On a 64bit system, all your memory is visible, and your max server memory is the same as your physical memory, so target ideally will be 30GB. You can see the target memory value in the metadata view &lt;EM&gt;sys.dm_os_sys_info&lt;/EM&gt; (where it's called &lt;B&gt;bpool_commit_target)&lt;/B&gt;, along with the value for visible memory (called &lt;B&gt;bpool_visible&lt;/B&gt;). 
&lt;P align=left&gt;However, there are other factors that can affect the target value. The BOL entry for &lt;EM&gt;sys.dm_os_sys_info&lt;/EM&gt; defines &lt;B&gt;bpool_commit_target&lt;/B&gt; as follows: 
&lt;P align=left&gt;&lt;EM&gt;"Number of 8-KB buffers needed by the buffer pool. The target amount is calculated using a variety of inputs such as the current state of the system, including its load, the memory requested by current processes, the amount of memory installed on the computer, and configuration parameters."&lt;/EM&gt; 
&lt;P align=left&gt;The exact formula is not published. It's best to just use &lt;EM&gt;sys.dm_os_sys_info&lt;/EM&gt; to see what your system's target memory value is. 
&lt;P align=left&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;Q:&amp;nbsp; In your article, you give an example how to calculate plan-cache pressure limit, for example for SQL Server 2005 RTM and SP1, it calculates for on 28 target memory as follows : (.75 x 8 GB) + (.5 x 20 GB) = 6 GB. Then you add to 10 GB so pressure limit is 16 GB. Where does 10 GB come from?&lt;/EM&gt; 
&lt;BLOCKQUOTE&gt;
&lt;P&gt;A: You have rephrased the expression incorrectly. This is what the article says: 
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (.75 x 8 GB) + (.5 x 20 GB) = 6 GB + 10 GB = 16 GB 
&lt;P&gt;If you do the math, you’ll see that the first term in parentheses (.75 x 8 GB) is equal to 6 GB and the second term (.5 x 20 GB) is equal to 10 GB, so we add the 6 and the 10 together. 
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;Q. You mention "plan-cache pressure limit". Does it mean that when , let's say pressure limit of 28 GB is 16 GB, 16 GB is reached then SQL Server couldn't remove plan cache to make it less than 16 GB, is my understanding right?&lt;/EM&gt; 
&lt;BLOCKQUOTE&gt;
&lt;P&gt;A: No, in the above example, we calculated the pressure limit to be 16 GB. That means when your SQL Server hits 16 GB of memory for plan cache, it will start removing plans from cache to keep cache from getting too big. 
&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;EM&gt;Q: You show how to remove a prepared query by creating a plan guide with recompile hint; is it possible to remove non-prepared query plan on the following sample:&lt;/EM&gt; 
&lt;P&gt;&lt;EM&gt;EXEC sp_create_plan_guide @name = N'RemovePlan1', @stmt = N' SELECT * FROM Sales WHERE ContactID &amp;lt; 3', @type = N'SQL', @module_or_batch = NULL, @params = N', @hints = N'OPTION(RECOMPILE)'; &lt;/EM&gt;
&lt;P&gt;&lt;EM&gt;and I issue query twice as below shown SELECT * FROM Sales WHERE ContactID &amp;lt; 3 &lt;/EM&gt;
&lt;P&gt;&lt;EM&gt;When I check in syscacheobjects with the query: &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/EM&gt;&lt;EM&gt;SELECT usecounts as uses, sql FROM sys.syscacheobjects WHERE dbid = db_id('AdventureWorks'); &lt;/EM&gt;
&lt;P&gt;&lt;EM&gt;It shows that the non-prepared query plan is reused with count equal to 2.&lt;/EM&gt; 
&lt;BLOCKQUOTE&gt;
&lt;P&gt;A: Althought it is possible to create a plan guide for an adhoc (non-prepared) query, your @stmt parameter must be absolutely exactly the same as the query you will run. In your plan guide creation, you have an extra space in front of the SELECT, and your @module_or_batch parameter is incorrect; it should be NULL. A correct plan guide can be used for adhoc queries, but it will NOT remove the adhoc plan from cache when you drop the plan guide, like a plan guide for a prepared query will. You will have to wait for the next version (SQL Server 2008) to get that behavior.&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I hope this helps! 
&lt;P&gt;&lt;FONT color=#ff00ff&gt;~Kalen&lt;/FONT&gt;&lt;/P&gt;</description></item></channel></rss>