<?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>Kalen Delaney : statistics</title><link>http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/statistics/default.aspx</link><description>Tags: statistics</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Geek City: More statistics info available!</title><link>http://www2.sqlblog.com/blogs/kalen_delaney/archive/2013/04/09/more-statistics-info.aspx</link><pubDate>Wed, 10 Apr 2013 01:39:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:48605</guid><dc:creator>Kalen Delaney</dc:creator><slash:comments>1</slash:comments><comments>http://www2.sqlblog.com/blogs/kalen_delaney/comments/48605.aspx</comments><wfw:commentRss>http://www2.sqlblog.com/blogs/kalen_delaney/commentrss.aspx?PostID=48605</wfw:commentRss><description>I just started using a new DMV (one that’s actually an ‘F’ not a ‘V’, as in Function) that gives us more info about distribution statistics. It returns info about the last statistics update date (which is also available with a function STATS_DATE())....(&lt;a href="http://www2.sqlblog.com/blogs/kalen_delaney/archive/2013/04/09/more-statistics-info.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://www2.sqlblog.com/aggbug.aspx?PostID=48605" width="1" height="1"&gt;</description><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/statistics/default.aspx">statistics</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/DMVs/default.aspx">DMVs</category></item><item><title>Geek City: Accessing Distribution Statistics</title><link>http://www2.sqlblog.com/blogs/kalen_delaney/archive/2013/01/18/accessing-distribution-statistics.aspx</link><pubDate>Fri, 18 Jan 2013 20:08:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:47218</guid><dc:creator>Kalen Delaney</dc:creator><slash:comments>4</slash:comments><comments>http://www2.sqlblog.com/blogs/kalen_delaney/comments/47218.aspx</comments><wfw:commentRss>http://www2.sqlblog.com/blogs/kalen_delaney/commentrss.aspx?PostID=47218</wfw:commentRss><description>Distribution statistics are one of the most important sources of information that the Query Optimizer uses to determine a good query plan. In this post, I’m not going to tell you everything about distribution statistics. I’m just going to show you a few...(&lt;a href="http://www2.sqlblog.com/blogs/kalen_delaney/archive/2013/01/18/accessing-distribution-statistics.aspx"&gt;read more&lt;/a&gt;)&lt;img src="http://www2.sqlblog.com/aggbug.aspx?PostID=47218" width="1" height="1"&gt;</description><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/internals/default.aspx">internals</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/statistics/default.aspx">statistics</category></item><item><title>Geek City: String Statistics</title><link>http://www2.sqlblog.com/blogs/kalen_delaney/archive/2008/02/13/string-statistics.aspx</link><pubDate>Wed, 13 Feb 2008 22:18:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:5065</guid><dc:creator>Kalen Delaney</dc:creator><slash:comments>6</slash:comments><comments>http://www2.sqlblog.com/blogs/kalen_delaney/comments/5065.aspx</comments><wfw:commentRss>http://www2.sqlblog.com/blogs/kalen_delaney/commentrss.aspx?PostID=5065</wfw:commentRss><description>&lt;P&gt;If you’ve ever run DBCC SHOW_STATISTICS,&amp;nbsp; you know you get 3 sections of information back. The first section is basic information about the last time the statistics were updated, the number of rows, the number of steps, etc. The second section is density information for each left-based subset of columns. The third section is the histogram for the first column in the statistics. I won't be going into detail on what any of these things mean (i.e. steps, density, histogram), but you can get lots more information from this whitepaper: 
&lt;P&gt;&lt;A href="http://www.microsoft.com/technet/prodtechnol/sql/2005/qrystats.mspx"&gt;Statistics Used by the Query Optimizer in Microsoft SQL Server 2005&lt;/A&gt; 
&lt;P&gt;What you might &lt;STRONG&gt;not&lt;/STRONG&gt; know is that you can get each of the three sections independently by adding an option to the DBCC command: 
&lt;P&gt;DBCC SHOW_STATISTICS ('AdventureWorks.Person.Contact',&lt;BR&gt;'IX_Contact_EmailAddress') &lt;B&gt;WITH STAT_HEADER&lt;/B&gt;; 
&lt;P&gt;DBCC SHOW_STATISTICS ('AdventureWorks.Person.Contact',&lt;BR&gt;'IX_Contact_EmailAddress') &lt;B&gt;WITH DENSITY_VECTOR&lt;/B&gt;; 
&lt;P&gt;DBCC SHOW_STATISTICS ('AdventureWorks.Person.Contact',&lt;BR&gt;'IX_Contact_EmailAddress') &lt;B&gt;WITH HISTOGRAM&lt;/B&gt;; 
&lt;P&gt;These options are documented as part of the DBCC SHOW_STATISTICS command for SQL Server 2005. These options were actually available in SQL Server 2000, but they just aren’t documented.&amp;nbsp; 
&lt;P&gt;In SQL Server 2005, the first section contains a column of output called "String Index", which I like to call "String Statistics". I just wrote an article for &lt;A href="http://www.sqlcommunity.com/"&gt;www.SQLCommunity.com&lt;/A&gt; about what these string statistics do for you. 
&lt;P&gt;&lt;A title=http://www.sqlcommunity.com/default.aspx?tabid=77&amp;amp;id=178 href="http://www.sqlcommunity.com/default.aspx?tabid=77&amp;amp;id=178"&gt;http://www.sqlcommunity.com/default.aspx?tabid=77&amp;amp;id=178&lt;/A&gt; 
&lt;P&gt;Have fun! 
&lt;P&gt;&lt;FONT color=#ff00ff&gt;~Kalen&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://www2.sqlblog.com/aggbug.aspx?PostID=5065" width="1" height="1"&gt;</description><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/nonclustered+index/default.aspx">nonclustered index</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/showplan/default.aspx">showplan</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/statistics/default.aspx">statistics</category></item><item><title>Did You Know? Statistics vs Indexes</title><link>http://www2.sqlblog.com/blogs/kalen_delaney/archive/2008/02/04/statistics-vs-indexes.aspx</link><pubDate>Mon, 04 Feb 2008 19:44:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:4882</guid><dc:creator>Kalen Delaney</dc:creator><slash:comments>7</slash:comments><comments>http://www2.sqlblog.com/blogs/kalen_delaney/comments/4882.aspx</comments><wfw:commentRss>http://www2.sqlblog.com/blogs/kalen_delaney/commentrss.aspx?PostID=4882</wfw:commentRss><description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;What is the difference between statistics and indexes? Do auto created statistics indicate that you should build an index?&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;I will be posting answers to some of the interesting questions I get from my students and my readers (these are not two disjoint sets, of course) on the new SQLCommunity site.&lt;/P&gt;
&lt;P&gt;Check out this the answer to this question at:&lt;/P&gt;
&lt;P&gt;&lt;A title=http://www.sqlcommunity.com/Articles/SQLServerArticlesCategorized/tabid/153/language/en-US/Default.aspx href="http://www.sqlcommunity.com/Articles/SQLServerArticlesCategorized/tabid/153/language/en-US/Default.aspx"&gt;http://www.sqlcommunity.com/Articles/SQLServerArticlesCategorized/tabid/153/language/en-US/Default.aspx&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;The article has some geeky stuff in it too. For example, it explains how to interpret the strangely named statistics, such as _WA_Sys_00000010_2EDAF651. &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have fun!&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff00ff&gt;~Kalen&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://www2.sqlblog.com/aggbug.aspx?PostID=4882" width="1" height="1"&gt;</description><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/statistics/default.aspx">statistics</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/indexes/default.aspx">indexes</category></item><item><title>Did you know? Cloning is Legal (and Available in SQL Server 2005)</title><link>http://www2.sqlblog.com/blogs/kalen_delaney/archive/2007/11/21/cloning-in-sql-server-2005.aspx</link><pubDate>Wed, 21 Nov 2007 18:50:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:3465</guid><dc:creator>Kalen Delaney</dc:creator><slash:comments>5</slash:comments><comments>http://www2.sqlblog.com/blogs/kalen_delaney/comments/3465.aspx</comments><wfw:commentRss>http://www2.sqlblog.com/blogs/kalen_delaney/commentrss.aspx?PostID=3465</wfw:commentRss><description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I first heard about the possibility of database cloning way back in version 7.0 and thought it sounded like a great idea. Who wouldn't love to have a bunch of identical little databases running around, of smaller size and easier manageability? &lt;/P&gt;
&lt;P&gt;Cloning a database means creating a statistics only copy of it, so that you can examine execution plans for poorly performing queries&amp;nbsp;in a test environment that takes hardly any space at all.&amp;nbsp; A clone database has all the metadata for all your objects, including function and stored procedure definitions. It has all the statistics for all the objects including the histograms and density information returned by DBCC SHOW_STATISTICS. Looking at space usage information shows you only the pages used, but not the pages allocated but unused. &lt;/P&gt;
&lt;P&gt;So how can you get a little clone of your own? The original plan was to have a toolbar option to just click and presto, there would be your clone. That never happened. Later, one of the optimizer engineers at Microsoft created a stored procedure, called something like sp_clone_db that took a database name as a parameter, and created a new database with all the metadata and statistics, but none of the data, of the original. That procedure was never&amp;nbsp;included with any version of the product.&lt;/P&gt;
&lt;P&gt;Instead, what we have in SQL Server 2005 is the ability to script a database, and include the statistics and histogram information.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;In SQL Server Management Studio's Object Explorer, right-click your database name and choose Tasks, and then Generate Scripts....&lt;/P&gt;
&lt;P&gt;Choose the name of the database to script, and select the box to "Script all objects in the selected database".&amp;nbsp; Next you'll see a "Choose Script Options" dialog with several dozen options to choose from, mostly indicating whether your want to include certain properties or objects in your database. Most of these you can leave at the default, or deselect the ones you're not interested in. I usually select the option to create the database, so it will include the CREATE DATABASE statement and any necessary filegroups. If you don't do this, and your database has objects created on filegroups other than the primary, your script will need a lot more manual editing. &lt;/P&gt;
&lt;P&gt;There are two&amp;nbsp;options that you &lt;STRONG&gt;must&lt;/STRONG&gt; change in this "Choose Script Options" dialog. In the General section&amp;nbsp;is the one called "Script Statistics". When you click in the list of options on the right side, you'll see three different options. The default is "Do not script statistics". &lt;FONT color=#ff0000&gt;Choose the option to "Script statistics and histograms."&lt;/FONT&gt; When you make this selection, you'll get a warning like the following:&lt;/P&gt;&lt;A href="http://sqlblog.com/blogs/kalen_delaney/WindowsLiveWriter/87e4c1029f59_B0F8/image05.png"&gt;&lt;IMG style="BORDER-TOP-WIDTH:0px;BORDER-LEFT-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-RIGHT-WIDTH:0px;" height=116 src="http://sqlblog.com/blogs/kalen_delaney/WindowsLiveWriter/87e4c1029f59_B0F8/image0_thumb3.png" width=545 border=0&gt;&lt;/A&gt; 
&lt;P&gt;If you want a clone, you'll have to use this option, so don't let this warning scare you.&lt;/P&gt;
&lt;P&gt;In the Table/View Options section (you'll have to scroll down) &lt;FONT color=#ff0000&gt;change "Script Indexes" to True.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Click Ok, and after you click Next to&amp;nbsp;leave this "Choose Script Options" dialog, the&amp;nbsp;"Output Options" dialog opens. &amp;nbsp; (If you forget to check the box for scripting all objects in the database in the very&amp;nbsp;first dialog, you'll get about 10 different dialogs asking you to choose which objects you want to copy, before you get to the "Output Options" dialog. Don't say I didn't warn you.)&lt;/P&gt;
&lt;P&gt;I usually just choose to copy to a New&amp;nbsp;Query Window and click Next. I then get a chance to confirm my choices, and then I click Finish. The copy process begins.&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff0000&gt;&lt;STRONG&gt;WARNING: If you notice in the confirmation list that you forgot something, or want to go back and make any changes, the option to Script Indexes will be set back to false. You'll need to make sure to reset it to True before going forward again.&lt;/STRONG&gt;&lt;/FONT&gt; &lt;/P&gt;
&lt;P&gt;Once I get the script in the new window, I need to make sure I change all references to the original database name to a new name. (If you are creating the clone on a different server that doesn't have the original database, then you won't have to do this step.) Make sure you check the filenames and make sure they don't duplicate existing names.&amp;nbsp; Execute when ready.&lt;/P&gt;
&lt;P&gt;Or, you might want to spend a few minutes examining the script. You'll see UPDATE STATISTICS statements like you've never seen before, looking something like the following. (My clone was created on the AdventureWorks database):&lt;/P&gt;
&lt;P&gt;UPDATE STATISTICS [Sales].[CreditCard]([AK_CreditCard_CardNumber]) WITH STATS_STREAM = 0x0100000002000144 &amp;lt;huge big long hex value&amp;gt; 000000000000510D0000000000,&amp;nbsp; ROWCOUNT = 19118, PAGECOUNT = 93&lt;/P&gt;
&lt;P&gt;So the UPDATE STATISTICS statements force a particular histogram into the statistics, as well as the page count and row count.&lt;/P&gt;
&lt;P&gt;Once you've created the new database, you should be able run queries to look at sizing information. &lt;/P&gt;
&lt;P&gt;EXEC sp_spaceused 'Sales.SalesOrderDetail' &lt;/P&gt;
&lt;P&gt;returns the following:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; rows&amp;nbsp;&amp;nbsp;&amp;nbsp;reserved data&amp;nbsp;&amp;nbsp;&amp;nbsp; index_size unused&lt;BR&gt;---------------- ------ -------- ------- ---------- ------&lt;BR&gt;SalesOrderDetail 121317&amp;nbsp;0 KB&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 9880 KB&amp;nbsp;0 KB&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0 KB&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;FONT size=2&gt;&lt;FONT face=ta&gt;&lt;FONT face=Tahoma&gt;However&lt;/FONT&gt;,&lt;/FONT&gt; &lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;SELECT count(*) FROM Sales.SalesOrderDetail &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;returns 0.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;You can look at execution plans for queries involving any of the cloned tables and pre-existing indexes. You can create new indexes, but be careful. Any new indexes will have statistics created based on the real data in the clone database, which is 0 rows. So the statistics on your new indexes will not be very accurate.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT size=2&gt;Of course, your clone database cannot be used for timing tests, or troubleshooting concurrency issues, since there is no data to lock, but for examining how plans change as you rewrite queries, it's a great idea.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Have fun!&lt;/P&gt;
&lt;P&gt;&lt;FONT color=#ff00ff&gt;~Kalen&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://www2.sqlblog.com/aggbug.aspx?PostID=3465" width="1" height="1"&gt;</description><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/metadata/default.aspx">metadata</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/Tools/default.aspx">Tools</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/execution+plan/default.aspx">execution plan</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/scripts/default.aspx">scripts</category><category domain="http://www2.sqlblog.com/blogs/kalen_delaney/archive/tags/statistics/default.aspx">statistics</category></item></channel></rss>