<?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>How to Find the Statistics Used to Compile an Execution Plan</title><link>http://sqlblog.com/blogs/paul_white/archive/2011/09/21/how-to-find-the-statistics-used-to-compile-an-execution-plan.aspx</link><description>In this post, I show you how to determine exactly which statistics objects were used by the query optimizer to produce an execution plan. Trace Flags We will need three undocumented trace flags.&amp;#160; The first one ( 3604 ) is well-known – it redirects</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>re: How to Find the Statistics Used to Compile an Execution Plan</title><link>http://sqlblog.com/blogs/paul_white/archive/2011/09/21/how-to-find-the-statistics-used-to-compile-an-execution-plan.aspx#38597</link><pubDate>Tue, 20 Sep 2011 15:40:53 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:38597</guid><dc:creator>Thiago Dantas</dc:creator><description>&lt;p&gt;awsome!&lt;/p&gt;</description></item><item><title>re: How to Find the Statistics Used to Compile an Execution Plan</title><link>http://sqlblog.com/blogs/paul_white/archive/2011/09/21/how-to-find-the-statistics-used-to-compile-an-execution-plan.aspx#38598</link><pubDate>Tue, 20 Sep 2011 15:42:30 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:38598</guid><dc:creator>csm</dc:creator><description>&lt;p&gt;How #@~€&amp;amp;^ do you know this kind of things? &amp;nbsp; :-)&lt;/p&gt;
&lt;p&gt;Cooool!!! &amp;nbsp; &lt;/p&gt;</description></item><item><title>re: How to Find the Statistics Used to Compile an Execution Plan</title><link>http://sqlblog.com/blogs/paul_white/archive/2011/09/21/how-to-find-the-statistics-used-to-compile-an-execution-plan.aspx#38599</link><pubDate>Tue, 20 Sep 2011 16:08:53 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:38599</guid><dc:creator>Grant Fritchey</dc:creator><description>&lt;p&gt;Hilarious! I just posted one talking about the fact that this information wasn't stored in the plan itself. Maybe we need to coordinate so I can send people over to you more directly. Ha!&lt;/p&gt;
&lt;p&gt;Nice work.&lt;/p&gt;</description></item><item><title>re: How to Find the Statistics Used to Compile an Execution Plan</title><link>http://sqlblog.com/blogs/paul_white/archive/2011/09/21/how-to-find-the-statistics-used-to-compile-an-execution-plan.aspx#38600</link><pubDate>Tue, 20 Sep 2011 16:20:36 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:38600</guid><dc:creator>Paul White</dc:creator><description>&lt;p&gt;Hey Grant,&lt;/p&gt;
&lt;p&gt;Yes I saw it and went to leave the TF details in a comment there, but it didn't stick for some reason. &amp;nbsp;When I tried resubmitting, it said I had already left that comment. &amp;nbsp;So, I gave up and jotted the details down here instead.&lt;/p&gt;
&lt;p&gt;Paul&lt;/p&gt;
</description></item><item><title>re: How to Find the Statistics Used to Compile an Execution Plan</title><link>http://sqlblog.com/blogs/paul_white/archive/2011/09/21/how-to-find-the-statistics-used-to-compile-an-execution-plan.aspx#38607</link><pubDate>Tue, 20 Sep 2011 16:57:15 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:38607</guid><dc:creator>Paul White</dc:creator><description>&lt;p&gt;csm,&lt;/p&gt;
&lt;p&gt;I go looking for them :)&lt;/p&gt;
&lt;p&gt;Thanks for posting the link on Grant's blog. &amp;nbsp;I must confess I'm not sure how being able to extract the stats_ids from the plan would help Grant or Gail - they'd still need to connect to the database to check the metadata for those ids. &amp;nbsp;Might as well extract the query text from the plan and use the techniques shown here...?&lt;/p&gt;
&lt;p&gt;Paul&lt;/p&gt;
</description></item><item><title>re: How to Find the Statistics Used to Compile an Execution Plan</title><link>http://sqlblog.com/blogs/paul_white/archive/2011/09/21/how-to-find-the-statistics-used-to-compile-an-execution-plan.aspx#38610</link><pubDate>Tue, 20 Sep 2011 18:10:02 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:38610</guid><dc:creator>Alejandro Mesa</dc:creator><description>&lt;p&gt;Paul,&lt;/p&gt;
&lt;p&gt;You know what, I have no comment.&lt;/p&gt;
&lt;p&gt;Outstanding post!!!&lt;/p&gt;
&lt;p&gt;--&lt;/p&gt;
&lt;p&gt;AMB&lt;/p&gt;</description></item><item><title>re: How to Find the Statistics Used to Compile an Execution Plan</title><link>http://sqlblog.com/blogs/paul_white/archive/2011/09/21/how-to-find-the-statistics-used-to-compile-an-execution-plan.aspx#38612</link><pubDate>Tue, 20 Sep 2011 18:36:10 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:38612</guid><dc:creator>Luan Moreno</dc:creator><description>&lt;p&gt;Paul White,&lt;/p&gt;
&lt;p&gt;Your posts is always a great opportunity to descover new things. I'm big fan.&lt;/p&gt;
&lt;p&gt;Tks Internal Man.....&lt;/p&gt;</description></item><item><title>re: How to Find the Statistics Used to Compile an Execution Plan</title><link>http://sqlblog.com/blogs/paul_white/archive/2011/09/21/how-to-find-the-statistics-used-to-compile-an-execution-plan.aspx#38613</link><pubDate>Tue, 20 Sep 2011 19:01:41 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:38613</guid><dc:creator>Paul White</dc:creator><description>&lt;p&gt;@AMB, ha! &amp;nbsp;I have no reply to that!&lt;/p&gt;
&lt;p&gt;@Luan, thanks so much. &amp;nbsp;Internal Man &amp;lt;&amp;lt; that's great :)&lt;/p&gt;
</description></item><item><title>re: How to Find the Statistics Used to Compile an Execution Plan</title><link>http://sqlblog.com/blogs/paul_white/archive/2011/09/21/how-to-find-the-statistics-used-to-compile-an-execution-plan.aspx#38619</link><pubDate>Wed, 21 Sep 2011 07:02:24 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:38619</guid><dc:creator>GrumpyOldDBA</dc:creator><description>&lt;p&gt;hmmm . I echo the others - awesome! and how do you get to learn this type of stuff? &amp;nbsp;If your posts were a book I'm sure it would be a top seller, I constantly learn new stuff from your posts and I'm very grateful, thank you.&lt;/p&gt;</description></item><item><title>re: How to Find the Statistics Used to Compile an Execution Plan</title><link>http://sqlblog.com/blogs/paul_white/archive/2011/09/21/how-to-find-the-statistics-used-to-compile-an-execution-plan.aspx#38624</link><pubDate>Wed, 21 Sep 2011 09:11:24 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:38624</guid><dc:creator>John Alan</dc:creator><description>&lt;p&gt;Paul,&lt;/p&gt;
&lt;p&gt;Maybe you should consider renaming the blog from PFS to 'Page 1, 9'&lt;/p&gt;
&lt;p&gt;It is becoming mandatory reading!&lt;/p&gt;</description></item><item><title>re: How to Find the Statistics Used to Compile an Execution Plan</title><link>http://sqlblog.com/blogs/paul_white/archive/2011/09/21/how-to-find-the-statistics-used-to-compile-an-execution-plan.aspx#38625</link><pubDate>Wed, 21 Sep 2011 10:14:56 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:38625</guid><dc:creator>Grant Fritchey</dc:creator><description>&lt;p&gt;For some reason you were caught by the spam filter. I fixed it. Thanks again for posting this and at the blog.&lt;/p&gt;</description></item><item><title>re: How to Find the Statistics Used to Compile an Execution Plan</title><link>http://sqlblog.com/blogs/paul_white/archive/2011/09/21/how-to-find-the-statistics-used-to-compile-an-execution-plan.aspx#38635</link><pubDate>Wed, 21 Sep 2011 19:51:43 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:38635</guid><dc:creator>Ellon Peterkin</dc:creator><description>&lt;p&gt;Great post. Just what I was looking for . Thanks!&lt;/p&gt;</description></item><item><title>re: How to Find the Statistics Used to Compile an Execution Plan</title><link>http://sqlblog.com/blogs/paul_white/archive/2011/09/21/how-to-find-the-statistics-used-to-compile-an-execution-plan.aspx#38685</link><pubDate>Fri, 23 Sep 2011 13:04:18 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:38685</guid><dc:creator>Paul White</dc:creator><description>&lt;p&gt;@Colin: Thank you. &amp;nbsp;Sometimes I just get lucky messing about with SQL Server and find something I think worth sharing on the blog! &amp;nbsp;I would love to find the time and freedom to put something longer together one day - whether that's a book or a downloadable PDF I'm not sure yet.&lt;/p&gt;
&lt;p&gt;@John: That's an excellent suggestion, I will consider it :c)&lt;/p&gt;
&lt;p&gt;@Grant: How odd. &amp;nbsp;Thanks for fixing it up!&lt;/p&gt;
&lt;p&gt;@Ellon: Cheers - I really appreciate your feedback.&lt;/p&gt;
</description></item><item><title>re: How to Find the Statistics Used to Compile an Execution Plan</title><link>http://sqlblog.com/blogs/paul_white/archive/2011/09/21/how-to-find-the-statistics-used-to-compile-an-execution-plan.aspx#38719</link><pubDate>Sun, 25 Sep 2011 07:25:24 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:38719</guid><dc:creator>ALZDBA</dc:creator><description>&lt;p&gt;Great post, Paul.&lt;/p&gt;
&lt;p&gt;That querytraceon hint is what I've been looking for for a long time.&lt;/p&gt;
&lt;p&gt;I know ... undocumented = handle with caution ... but will come in handy on test instances.&lt;/p&gt;</description></item><item><title>re: How to Find the Statistics Used to Compile an Execution Plan</title><link>http://sqlblog.com/blogs/paul_white/archive/2011/09/21/how-to-find-the-statistics-used-to-compile-an-execution-plan.aspx#44196</link><pubDate>Tue, 03 Jul 2012 21:19:01 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:44196</guid><dc:creator>Fabiano Amorim</dc:creator><description>&lt;p&gt;Hi Paul, I've just blogged about that... there is another way... take a look here... &lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://blogfabiano.com/2012/07/03/statistics-used-in-a-cached-query-plan/"&gt;http://blogfabiano.com/2012/07/03/statistics-used-in-a-cached-query-plan/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Regards&lt;/p&gt;
&lt;p&gt;Fabiano Amorim&lt;/p&gt;</description></item><item><title>re: How to Find the Statistics Used to Compile an Execution Plan</title><link>http://sqlblog.com/blogs/paul_white/archive/2011/09/21/how-to-find-the-statistics-used-to-compile-an-execution-plan.aspx#44197</link><pubDate>Tue, 03 Jul 2012 21:29:03 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:44197</guid><dc:creator>Paul White</dc:creator><description>&lt;p&gt;Very cool Fabiano! &amp;nbsp;Thanks for sharing!&lt;/p&gt;
</description></item><item><title>Temporary Tables in Stored Procedures</title><link>http://sqlblog.com/blogs/paul_white/archive/2011/09/21/how-to-find-the-statistics-used-to-compile-an-execution-plan.aspx#44705</link><pubDate>Tue, 14 Aug 2012 15:22:31 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:44705</guid><dc:creator>Paul White: Page Free Space</dc:creator><description>&lt;p&gt;Ask anyone what the primary advantage of temporary tables over table variables is, and the chances are&lt;/p&gt;</description></item><item><title>re: How to Find the Statistics Used to Compile an Execution Plan</title><link>http://sqlblog.com/blogs/paul_white/archive/2011/09/21/how-to-find-the-statistics-used-to-compile-an-execution-plan.aspx#46221</link><pubDate>Thu, 15 Nov 2012 02:31:43 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:46221</guid><dc:creator>Brett Shearer</dc:creator><description>&lt;p&gt;Hi Paul,&lt;/p&gt;
&lt;p&gt;Just used this technique to try and understand why statistics are applied differently for IsNull and Coalesce (which I could not find any info on). IsNull returns suboptimal estimates, whereas coalesce seems to be much more accurate.&lt;/p&gt;
&lt;p&gt;3000 for isnull&lt;/p&gt;
&lt;p&gt;11500 for coalesce&lt;/p&gt;
&lt;p&gt;13000 real matches&lt;/p&gt;
&lt;p&gt;The stats details returned by the trace flags were identical...&lt;/p&gt;
&lt;p&gt;select count(*) from jobvoydestination&lt;/p&gt;
&lt;p&gt;where&lt;/p&gt;
&lt;p&gt;coalesce(JB_A_ARV, JB_E_ARV)&amp;gt;='1900-01-01 00:00:00.000' &lt;/p&gt;
&lt;p&gt;AND coalesce(JB_A_ARV, JB_E_ARV)&amp;lt;'2012-11-16 00:00:00.000'&lt;/p&gt;
&lt;p&gt;option (recompile, QUERYTRACEON 3604,QUERYTRACEON 9292,QUERYTRACEON 9204)&lt;/p&gt;
&lt;p&gt;select count(*) from jobvoydestination&lt;/p&gt;
&lt;p&gt;where&lt;/p&gt;
&lt;p&gt;isnull(JB_A_ARV, JB_E_ARV)&amp;gt;='1900-01-01 00:00:00.000' &lt;/p&gt;
&lt;p&gt;AND isnull(JB_A_ARV, JB_E_ARV)&amp;lt;'2012-11-16 00:00:00.000'&lt;/p&gt;
&lt;p&gt;option (recompile, QUERYTRACEON 3604,QUERYTRACEON 9292,QUERYTRACEON 9204)&lt;/p&gt;
&lt;p&gt;Stats header loaded: DbName: OdysseyAPOTRN, ObjName: jobvoydestination, IndexId: 7, ColumnName: JB_E_ARV, EmptyTable: FALSE&lt;/p&gt;
&lt;p&gt;Stats loaded: DbName: OdysseyAPOTRN, ObjName: jobvoydestination, IndexId: 7, ColumnName: JB_E_ARV, EmptyTable: FALSE&lt;/p&gt;
&lt;p&gt;Stats header loaded: DbName: OdysseyAPOTRN, ObjName: jobvoydestination, IndexId: 8, ColumnName: JB_A_ARV, EmptyTable: FALSE&lt;/p&gt;
&lt;p&gt;Stats loaded: DbName: OdysseyAPOTRN, ObjName: jobvoydestination, IndexId: 8, ColumnName: JB_A_ARV, EmptyTable: FALSE&lt;/p&gt;
&lt;p&gt;Stats header loaded: DbName: OdysseyAPOTRN, ObjName: jobvoydestination, IndexId: 15, ColumnName: JB_E_ARV, EmptyTable: FALSE&lt;/p&gt;
&lt;p&gt;One thing is odd though - there appears to be two statistics stored on JB_E_ARV (7 and 15)?.&lt;/p&gt;</description></item></channel></rss>