<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>DBCC show_statistics</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/dbcc_show_statistics/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/dbcc_show_statistics/feed.xml</link>
    <description />
    <lastBuildDate>Wed, 17 Apr 2019 03:48:20 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>What DBCC SHOW_STATISTICS tells me</title>
      <link>https://docs.microsoft.com/archive/blogs/dbcc_show_statistics/what-dbcc-show_statistics-tells-me</link>
      <pubDate>Fri, 06 Mar 2015 15:53:00 GMT</pubDate>
      <dc:creator><![CDATA[Vivek Janakiraman]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/dbcc_show_statistics/2015/03/06/what-dbcc-show_statistics-tells-me/</guid>
      <description><![CDATA[DBCC show_statistics explained********************************DBCC SHOW_STATISTICS&nbsp;displays...]]></description>
      <content:encoded><![CDATA[<p><span style="font-family: courier new,courier; font-size: small;">DBCC show_statistics explained</span><br /><span style="font-family: courier new,courier; font-size: small;">********************************</span><br /><br /><span style="font-family: courier new,courier; font-size: small;"><span style="color: #222222; text-transform: none; line-height: 18.47px; text-indent: 0px; letter-spacing: normal; font-style: normal; font-variant: normal; font-weight: normal; word-spacing: 0px; white-space: normal; font-size-adjust: none; font-stretch: normal; background-color: #ffffff; -webkit-text-stroke-width: 0px;">DBCC SHOW_STATISTICS</span><span style="color: #222222; text-transform: none; line-height: 18.47px; text-indent: 0px; letter-spacing: normal; font-style: normal; font-variant: normal; font-weight: normal; word-spacing: 0px; float: none; display: inline !important; white-space: normal; font-size-adjust: none; font-stretch: normal; background-color: #ffffff; -webkit-text-stroke-width: 0px;"><span class="Apple-converted-space">&nbsp;</span>displays current query optimization statistics for a table or indexed view.&nbsp; Basically it shows you the statistics, or a summary of the data, that SQL Server will use to help generate an execution plan.</span></span></p>
<p><span style="font-family: courier new,courier; font-size: small;">=&gt;&nbsp;Create below database and table.<br /><br /><span style="background-color: #ffff00;">Create database Test</span><br /><span style="background-color: #ffff00;">go</span><br /><span style="background-color: #ffff00;">USE Test</span><br /><span style="background-color: #ffff00;">GO</span><br /><span style="background-color: #ffff00;">CREATE TABLE [dbo].[Table1](</span><br /><span style="background-color: #ffff00;">&nbsp;&nbsp;&nbsp;&nbsp; [Col1] [int] NULL,</span><br /><span style="background-color: #ffff00;">&nbsp;&nbsp;&nbsp;&nbsp; [Col2] [int] NULL,</span><br /><span style="background-color: #ffff00;">&nbsp;&nbsp;&nbsp;&nbsp; [Col3] [int] NULL,</span><br /><span style="background-color: #ffff00;">&nbsp;) ON [PRIMARY]</span><br /><span style="background-color: #ffff00;">GO</span><br /><br />=&gt;&nbsp;You will see a clustered index created automatically. Add the below non clustered index.&nbsp;</span></p>
<p><span style="font-family: courier new,courier; font-size: small; background-color: #ffff00;">USE Test<br />GO<br />CREATE NONCLUSTERED INDEX [IX_Table1] ON [dbo].[Table1]<br />(<br />&nbsp;&nbsp;&nbsp;&nbsp; [Col1] ASC,<br />&nbsp;&nbsp;&nbsp;&nbsp; [Col2] ASC,<br />&nbsp;&nbsp;&nbsp;&nbsp; [Col3] ASC<br />)WITH (PAD_INDEX&nbsp; = OFF, STATISTICS_NORECOMPUTE&nbsp; = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS&nbsp;= ON, ALLOW_PAGE_LOCKS&nbsp; = ON) ON [PRIMARY]<br />GO&nbsp;</span></p>
<p><span style="font-family: courier new,courier; font-size: small;"><span>=&gt; </span>Insert some sample rows.&nbsp;</span></p>
<p><span style="font-family: courier new,courier; font-size: small;"><span style="background-color: #ffff00;">insert into Table1 values (1,2,3)</span><br /><span style="background-color: #ffff00;">go 10</span><br /><span style="background-color: #ffff00;">set nocount on</span><br /><span style="background-color: #ffff00;">declare @i int</span><br /><span style="background-color: #ffff00;">set @i =2</span><br /><span style="background-color: #ffff00;">while (@i&lt;20)</span><br /><span style="background-color: #ffff00;">begin</span><br /><span style="background-color: #ffff00;">insert into Table1 values(@i,12,13)</span><br /><span style="background-color: #ffff00;">set @i=@i+1</span><br /><span style="background-color: #ffff00;">end</span><br /><br />=&gt;&nbsp;Lets run dbcc show_statistics and see the output. We have inserted some rows, but we don&rsquo;t see any output.<br /><br /><span style="background-color: #ffff00;">dbcc show_statistics ('Table1','IX_Table1')</span></span></p>
<p><span style="font-family: courier new,courier; font-size: small;"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/69/81/7382.1.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-69-81/7382.1.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/69/81/7382.1.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-69-81/7382.1.png" alt="" border="0" /></a></span></p>
<p><span style="font-family: courier new,courier; font-size: small;">=&gt; Running update statistics with fullscan and then dbcc show_statistics and we get the below output. This seems to show what we have inserted.</span><br /><br /><span style="font-family: courier new,courier; font-size: small; background-color: #ffff00;">update statistics Table1 with fullscan</span><br /><span style="font-family: courier new,courier; font-size: small; background-color: #ffff00;">dbcc show_statistics('Table1','IX_Table1')</span></p>
<p><span style="font-family: courier new,courier; font-size: small;"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/69/81/3683.2.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-69-81/3683.2.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/69/81/3683.2.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-69-81/3683.2.png" alt="" border="0" /></a></span></p>
<p><span style="font-family: courier new,courier; font-size: small; text-decoration: underline;">Tab1 from above screenshot</span></p>
<p><span style="font-size: small;"><span style="font-family: courier new,courier; text-decoration: underline;"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/69/81/7802.3.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-69-81/7802.3.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/69/81/7802.3.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-69-81/7802.3.png" alt="" border="0" /></a></span><span style="font-family: courier new,courier;"><br />[$] Name : Name of the index.<br /></span></span><br /><span style="font-size: small;"><span style="font-family: courier new,courier;">[$] Updated : Date when the statistics </span><span style="font-family: courier new,courier;">for this index is updated&nbsp;</span><span style="font-family: courier new,courier;">or the time when it was last </span><span style="font-family: courier new,courier;">rebuilt.<br /></span></span><br /><span style="font-size: small;"><span style="font-family: courier new,courier;">[$] Rows : Number of rows in the </span><span style="font-family: courier new,courier;">underlying table.<br /></span></span><br /><span style="font-size: small;"><span style="font-family: courier new,courier;">[$] Rows Sampled : Number of rows </span><span style="font-family: courier new,courier;">sampled. In our case we&nbsp;</span><span style="font-family: courier new,courier;">performed an update statistics </span><span style="font-family: courier new,courier;">with fullscan, hence we see&nbsp;</span><span style="font-family: courier new,courier;">all the rows sampled. In most of </span><span style="font-family: courier new,courier;">the case, you will see less&nbsp;</span><span style="font-family: courier new,courier;">number of rows in &ldquo;Rows Sampled&rdquo; </span><span style="font-family: courier new,courier;">than the &ldquo;Rows&rdquo; indicating&nbsp;</span><span style="font-family: courier new,courier;">we have a sample value set.<br /></span></span><br /><span style="font-size: small;"><span style="font-family: courier new,courier;">[$] Steps : Number of steps in the </span><span style="font-family: courier new,courier;">histogram. In our case it is&nbsp;</span><span style="font-family: courier new,courier;">10, since the number of rows in </span><span style="font-family: courier new,courier;">tab 3 as per the above&nbsp;</span><span style="font-family: courier new,courier;">screenshot is just 10.<br /></span></span><br /><span style="font-size: small;"><span style="font-family: courier new,courier;">[$] Density : Calculated </span><span style="font-family: courier new,courier;">as 1 /&nbsp;<em>distinct values</em>&nbsp;for all values </span><span style="font-family: courier new,courier;">in&nbsp;</span><span style="font-family: courier new,courier;">the first key column of the </span><span style="font-family: courier new,courier;">statistics object, excluding the&nbsp;</span><span style="font-family: courier new,courier;">histogram&nbsp;boundary values. This </span><span style="font-family: courier new,courier;">Density value is not used by&nbsp;</span><span style="font-family: courier new,courier;">the query optimizer and is </span><span style="font-family: courier new,courier;">displayed for backward&nbsp;</span><span style="font-family: courier new,courier;">compatibility with versions before&nbsp;</span></span><span style="font-family: courier new,courier; font-size: small;">SQL Server 2008.<br /></span><br /><span style="font-size: small;"><span style="font-family: courier new,courier;">[$] Average Key Length : Average number of </span><span style="font-family: courier new,courier;">bytes per value for&nbsp;</span><span style="font-family: courier new,courier;">all of the key columns in the </span><span style="font-family: courier new,courier;">statistics object. In our case&nbsp;</span><span style="font-family: courier new,courier;">3 columns are int.So, 4+4+4 = 12.<br /></span></span><span style="font-size: small;"><span style="font-family: courier new,courier;"><br />[$] String Index : Yes indicates the </span><span style="font-family: courier new,courier;">statistics object contains&nbsp;</span><span style="font-family: courier new,courier;">string summary statistics to </span><span style="font-family: courier new,courier;">improve the cardinality&nbsp;</span><span style="font-family: courier new,courier;">estimates for query&nbsp;predicates </span><span style="font-family: courier new,courier;">that use the LIKE operator;&nbsp;</span><span style="font-family: courier new,courier;">for example, WHERE ProductName </span><span style="font-family: courier new,courier;">LIKE '%Bike'. String summary&nbsp;</span><span style="font-family: courier new,courier;">statistics are stored separately </span><span style="font-family: courier new,courier;">from&nbsp;the histogram and are&nbsp;</span><span style="font-family: courier new,courier;">created on the first key column of </span><span style="font-family: courier new,courier;">the statistics object when&nbsp;</span><span style="font-family: courier new,courier;">it is of type char, varchar, </span><span style="font-family: courier new,courier;">nchar, nvarchar, varchar(max),&nbsp;</span><span style="font-family: courier new,courier;">nvarchar(max), text, or ntext..</span></span><br /><span style="font-size: small;"><span style="font-family: courier new,courier;"><br />[$] Unfiltered Rows : Total number of </span><span style="font-family: courier new,courier;">rows in the table before&nbsp;</span><span style="font-family: courier new,courier;">applying the filter expression. If </span><span style="font-family: courier new,courier;">Filter Expression is NULL,&nbsp;</span><span style="font-family: courier new,courier;">Unfiltered Rows is equal to Rows.&nbsp;<br /><br /></span><span style="font-family: courier new,courier; text-decoration: underline;">Tab2 from above screenshot.<br /><br /></span><span style="font-family: courier new,courier;"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/69/81/0434.4.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-69-81/0434.4.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/69/81/0434.4.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-69-81/0434.4.png" alt="" border="0" /></a></span></span></p>
<p><span style="font-size: small;"><span style="font-family: courier new,courier;">[$] All Density : It is the value of </span><span style="font-family: courier new,courier;">1/distinct rows.&nbsp;<br /></span><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select distinct col1 from </span><span style="font-family: courier new,courier;">Table1<br /></span><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&gt; </span><span style="font-family: courier new,courier;">Returns 19 rows =&gt; 1/19 = 0.05263158<br /><br /></span><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; select distinct col1,col2 from Table1<br /></span><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&gt; </span><span style="font-family: courier new,courier;">Returns 19 rows =&gt; 1/19 = 0.05263158<br /><br /></span><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select distinct </span><span style="font-family: courier new,courier;">col1,col2,col3 from Table1<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp; =&gt; Returns 19 rows =&gt; 1/19 =</span><span style="font-family: courier new,courier;">0.05263158</span></span></p>
<p><span style="font-size: small;"><span style="font-family: courier new,courier;">[$] Average length : Average length, in bytes, to </span><span style="font-family: courier new,courier;">store a list of&nbsp;</span><span style="font-family: courier new,courier;">the column values for the column </span><span style="font-family: courier new,courier;">prefix.</span></span></p>
<p><span style="font-size: small;"><span style="font-family: courier new,courier;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: courier new,courier;">Col1 =&gt; 4<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: courier new,courier;">Col1, Col2 =&gt; 4+4 = 8<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-family: courier new,courier;">Col1, Col2, col3 =&gt; 4+4+4 = 12</span></span></p>
<p><span style="font-size: small;"><span style="font-family: courier new,courier;">[$] Columns : Names of the columns&nbsp;in the prefix for which All&nbsp;</span><span style="font-family: courier new,courier;">density and Average length are </span><span style="font-family: courier new,courier;">displayed.</span></span></p>
<p><span style="font-family: courier new,courier; font-size: small; text-decoration: underline;">Tab3 from above screenshot</span></p>
<p><span style="font-family: courier new,courier; font-size: small;"><a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/69/81/2061.5.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-69-81/2061.5.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/69/81/2061.5.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-69-81/2061.5.png" alt="" border="0" /></a></span></p>
<p>&nbsp;</p>
<p><span style="font-size: small;"><span style="font-family: courier new,courier;">SQL Server </span><span style="font-family: courier new,courier;">builds the histogram from the sorted set of column values in three steps as per </span><span style="font-family: courier new,courier;"><a href="https://technet.microsoft.com/en-us/library/dd535534(v=SQL.100).aspx">https://technet.microsoft.com/en-us/library/dd535534(v=SQL.100).aspx</a>.</span></span></p>
<p><span style="font-size: small;"><span style="font-family: courier new,courier;">=&gt; Histogram&nbsp;</span><span style="font-family: courier new,courier;">initialization: In the first step, a sequence of values starting at the </span><span style="font-family: courier new,courier;">beginning of the sorted set is processed, and up to&nbsp;200 values of RANGE_HI_KEY,</span><span style="font-family: courier new,courier;">EQ_ROWS, RANGE_ROWS, and DISTINCT_RANGE_ROWS are collected (RANGE_ROWS and </span><span style="font-family: courier new,courier;">DISTINCT_RANGE_ROWS are always&nbsp;zero during this step). The first step ends </span><span style="font-family: courier new,courier;">either when all input has been exhausted, or when 200 values have been found.<br /><br /></span><span style="font-family: courier new,courier;">=&gt; Scan with bucket </span><span style="font-family: courier new,courier;">merge: Each additional value from the leading column of the statistics key is </span><span style="font-family: courier new,courier;">processed in the second step, in sorted&nbsp;order; for each successive value, </span><span style="font-family: courier new,courier;">either the value is added to the last range, or a new range at the end is </span><span style="font-family: courier new,courier;">created (this is possible&nbsp;because the input values are sorted). If a new range </span><span style="font-family: courier new,courier;">is created, one pair of existing, neighboring ranges is collapsed into a single </span><span style="font-family: courier new,courier;">range. This pair of ranges is selected in order to minimize information loss. </span><span style="font-family: courier new,courier;">The number of histogram steps after the ranges are&nbsp;collapsed stays at 200 </span><span style="font-family: courier new,courier;">throughout this step. This method is based on a variation of the maxdiff </span><span style="font-family: courier new,courier;">histogram.</span></span></p>
<p><span style="font-size: small;"><span style="font-family: courier new,courier;">=&gt; Histogram </span><span style="font-family: courier new,courier;">consolidation: In the third step, more ranges can be collapsed if a significant </span><span style="font-family: courier new,courier;">amount of information is not lost. Therefore,&nbsp;even if the column has more than </span><span style="font-family: courier new,courier;">200 unique values, the histogram might have less than 200 steps.</span></span></p>
<p><span style="font-size: small;"><span style="font-family: courier new,courier;">[$] </span><span style="font-family: courier new,courier;">RANGE_HI_KEY : This is the key value. This value can be&nbsp;</span><span style="font-family: courier new,courier;">anything from the below output.</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><br /><span style="font-family: courier new,courier; font-size: small;">select distinct col1 from Table1</span><br /><span style="font-size: small;"><span style="font-family: courier new,courier;"><br />[$] RANGE_ROWS : Number of rows whose </span><span style="font-family: courier new,courier;">column value falls between&nbsp;</span><span style="font-family: courier new,courier;">the values as marked in below </span><span style="font-family: courier new,courier;">screenshot. If we take the&nbsp;</span><span style="font-family: courier new,courier;">second row, We&nbsp;have 1 column </span><span style="font-family: courier new,courier;">between RANGE_HI_KEY &ldquo;1&rdquo; and </span><span style="font-family: courier new,courier;">&ldquo;3&rdquo;, which is value &ldquo;2&rdquo;.</span></span></p>
<p><span style="font-size: small;"><span style="font-family: courier new,courier;">&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/69/81/1346.6.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-69-81/1346.6.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/69/81/1346.6.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-69-81/1346.6.png" alt="" border="0" /></a></span><span style="font-family: courier new,courier;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />To understand this further, insert </span><span style="font-family: courier new,courier;">close to 100000 rows,&nbsp;<br /><br /></span><span style="background-color: #ffff00;"><span style="font-family: courier new,courier;">set nocount on<br /></span><span style="font-family: courier new,courier;">declare @i int<br /></span><span style="font-family: courier new,courier;">set @i =29<br /></span><span style="font-family: courier new,courier;">while (@i&lt;100000)<br /></span><span style="font-family: courier new,courier;">begin<br /></span><span style="font-family: courier new,courier;">insert into Table1 values(@i,12,13)<br /></span><span style="font-family: courier new,courier;">set @i=@i+1<br /></span><span style="font-family: courier new,courier;">end</span></span></span></p>
<p><span style="font-size: small;"><span style="font-family: courier new,courier;">Now check the output of TAB3 </span><span style="font-family: courier new,courier;">again,</span></span></p>
<p><span style="font-family: courier new,courier; font-size: small;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/69/81/6835.7.png" original-url="https://blogs.msdn.com/cfs-file.ashx/__key/communityserver-blogs-components-weblogfiles/00-00-01-69-81/6835.7.png"><img src="https://msdnshared.blob.core.windows.net/media/MSDNBlogsFS/prod.evol.blogs.msdn.com/CommunityServer.Blogs.Components.WeblogFiles/00/00/01/69/81/6835.7.png" original-url="https://blogs.msdn.com/resized-image.ashx/__size/550x0/__key/communityserver-blogs-components-weblogfiles/00-00-01-69-81/6835.7.png" alt="" border="0" /></a></span></p>
<p><span style="font-size: small;"><span style="font-family: courier new,courier;">It is pretty evident, that </span><span style="font-family: courier new,courier;">between RANGE_HI_KEY &ldquo;1&rdquo; and&nbsp;</span><span style="font-family: courier new,courier;">&ldquo;99998&rdquo; we have 99987 rows.&nbsp;<br /><br /></span><span style="font-family: courier new,courier;">[$] EQ_ROWS : Total number of rows equal to </span><span style="font-family: courier new,courier;">corresponding&nbsp;</span><span style="font-family: courier new,courier;">RANGE_HI_KEY.&nbsp;</span></span><br /><span style="font-family: courier new,courier; font-size: small;">From the above screenshot,</span><br /><span style="font-size: small;"><span style="font-family: courier new,courier;"><br />Row 1 =&gt; RANGE_HI_KEY is 1 </span><span style="font-family: courier new,courier;">=&gt; select COUNT(*) from table1&nbsp;</span><span style="font-family: courier new,courier;">where </span><span style="font-family: courier new,courier;">col1=1 =&gt; 10, which is equal to EQ_ROWS.</span></span></p>
<p><span style="font-size: small;"><span style="font-family: courier new,courier;">Row 2 =&gt; </span><span style="font-family: courier new,courier;">RANGE_HI_KEY is 99998 =&gt; select COUNT(*) from table1&nbsp;</span><span style="font-family: courier new,courier;">where </span><span style="font-family: courier new,courier;">col1=99998 =&gt; 1, which is equal to EQ_ROWS.</span></span></p>
<p><span style="font-size: small;"><span style="font-family: courier new,courier;">Row 3 =&gt; </span><span style="font-family: courier new,courier;">RANGE_HI_KEY is 99999 =&gt; select COUNT(*) from table1&nbsp;</span><span style="font-family: courier new,courier;">where </span><span style="font-family: courier new,courier;">col1=99999 =&gt; 1, which is equal to EQ_ROWS.</span></span></p>
<p><span style="font-size: small;"><span style="font-family: courier new,courier;">[$] DISTINCT_RANGE_ROWS : Number of distinct rows between </span><span style="font-family: courier new,courier;">each of&nbsp;</span><span style="font-family: courier new,courier;">the values in RANGE_HI_KEY. From the </span><span style="font-family: courier new,courier;">above screenshot,</span></span></p>
<p><span style="font-size: small;"><span style="font-family: courier new,courier;">Row 1 =&gt; RANGE_HI_KEY is 1 =&gt; </span><span style="font-family: courier new,courier;">This is the first row and it&nbsp;</span><span style="font-family: courier new,courier;">will always be 0.</span></span></p>
<p><span style="font-size: small;"><span style="font-family: courier new,courier;">Row 2 =&gt; </span><span style="font-family: courier new,courier;">RANGE_HI_KEY is 99998 =&gt; select distinct count(col1)&nbsp;</span><span style="font-family: courier new,courier;">from </span><span style="font-family: courier new,courier;">table1 where col1&gt;1 </span><span style="font-family: courier new,courier;">and col1&lt;99998 </span><span style="font-family: courier new,courier;">=&gt; 99987, which is&nbsp;</span><span style="font-family: courier new,courier;">equal to&nbsp; DISTINCT_RANGE_ROWS.</span></span></p>
<p><span style="font-size: small;"><span style="font-family: courier new,courier;">Row 3 =&gt; </span><span style="font-family: courier new,courier;">RANGE_HI_KEY is 99999 =&gt; select distinct count(col1)&nbsp;</span><span style="font-family: courier new,courier;">from </span><span style="font-family: courier new,courier;">table1 where col1&gt;99998 </span><span style="font-family: courier new,courier;">and col1&lt;99999 </span><span style="font-family: courier new,courier;">=&gt; 0, which is&nbsp;</span><span style="font-family: courier new,courier;">equal to&nbsp;DISTINCT_RANGE_ROWS.</span></span></p>
<p><span style="font-size: small;"><span style="font-family: courier new,courier;">[$] AVG_RANGE_ROWS : Average number of rows with duplicate </span><span style="font-family: courier new,courier;">column&nbsp;</span><span style="font-family: courier new,courier;">values within a histogram step, </span><span style="font-family: courier new,courier;">excluding the upper bound</span><span style="font-family: courier new,courier;">&nbsp;(RANGE_ROWS / DISTINCT_RANGE_ROWS for </span><span style="font-family: courier new,courier;">DISTINCT_RANGE_ROWS &gt;&nbsp;</span><span style="font-family: courier new,courier;">0).</span></span></p>
<p><span style="font-size: small;"><span style="font-family: courier new,courier;">Row 1 =&gt; RANGE_HI_KEY is 1 =&gt; </span><span style="font-family: courier new,courier;">DISTINCT_RANGE_ROWS = 0, Hence&nbsp;</span><span style="font-family: courier new,courier;">AVG_RANGE_ROWS is 1.</span></span></p>
<p><span style="font-size: small;"><span style="font-family: courier new,courier;">Row 2 =&gt; </span><span style="font-family: courier new,courier;">RANGE_HI_KEY is 99998 =&gt; DISTINCT_RANGE_ROWS &gt; 0,&nbsp;</span><span style="font-family: courier new,courier;">(RANGE_ROWS / DISTINCT_RANGE_ROWS) =&gt;</span><span style="font-family: courier new,courier;">(99987 / 99987) =&gt; 1,&nbsp;</span><span style="font-family: courier new,courier;">which is same&nbsp;as AVG_RANGE_ROWS.<br /></span></span><br /><span style="font-size: small;"><span style="font-family: courier new,courier;">Row 3 =&gt; RANGE_HI_KEY is 99999 </span><span style="font-family: courier new,courier;">=&gt; DISTINCT_RANGE_ROWS = 0,&nbsp;</span><span style="font-family: courier new,courier;">Hence AVG_RANGE_ROWS is 1.</span></span></p>
<p><span style="font-family: courier new,courier; font-size: small;">Thank You,<br />Vivek Janakiraman</span></p>
<p style="font: 10.94px/1.5em Verdana, Tahoma, Arial, sans-serif; margin: 7.5pt 0px; padding: 0px; text-align: left; color: #2a2a2a; text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; font-size-adjust: none; font-stretch: normal; background-color: #fafcff; -webkit-text-stroke-width: 0px;"><span style="font-size: small;"><strong>Disclaimer:<br /></strong>The views expressed on this blog are mine alone and do not reflect the views of my company or anyone else. All postings on this blog are provided &ldquo;AS IS&rdquo; with no warranties, and confers no rights.</span></p>
<p>&nbsp;</p>]]></content:encoded>
    </item>
  </channel>
</rss>