<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Edwin M SarmientoSQL Server Index Internals and How Filtered Indexes Look Like (Part 2) &#8211; Edwin M Sarmiento</title>
	<atom:link href="https://www.edwinmsarmiento.com/index-internals-and-what-filtered-indexes-look-like-part-2/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.edwinmsarmiento.com</link>
	<description>Intentional Excellence</description>
	<lastBuildDate>Mon, 13 Apr 2026 21:00:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
<site xmlns="com-wordpress:feed-additions:1">84283043</site>		<item>
		<title>SQL Server Index Internals and How Filtered Indexes Look Like (Part 2)</title>
		<link>https://www.edwinmsarmiento.com/index-internals-and-what-filtered-indexes-look-like-part-2/</link>
		<comments>https://www.edwinmsarmiento.com/index-internals-and-what-filtered-indexes-look-like-part-2/#respond</comments>
		<pubDate>Mon, 08 Jul 2013 19:38:58 +0000</pubDate>
		<dc:creator>Edwin M Sarmiento</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[DBCC IND]]></category>
		<category><![CDATA[DBCC PAGE]]></category>
		<category><![CDATA[filtered indexes]]></category>
		<category><![CDATA[SQL Server Index Internals]]></category>
		<guid isPermaLink="false">http://bassplayerdoc.wordpress.com/?p=784</guid>

				<description><![CDATA[In the first part of this series, I talked about how SQL Server navigates thru the index structure and used a clustered index as an example to demonstrate how the process works. To continue this series, we&#8217;ll look at filtered indexes and how they look like from a storage perspective. If you look at the [&#8230;]]]></description>
					<content:encoded><![CDATA[<p><em>In the <a href="https://www.edwinmsarmiento.com/sql-server-index-internals-and-how-filtered-indexes-look-like-part-1/" target="_blank">first part</a> of this series, I talked about how SQL Server navigates thru the index structure and used a clustered index as an example to demonstrate how the process works. To continue this series, we&#8217;ll look at filtered indexes and how they look like from a storage perspective.</em></p>
<p>If you look at the non-clustered index definitions, the only difference between the two is the inclusion of a <strong>WHERE</strong> clause. Now, if the WHERE clause returns just a subset of the entire table, we can expect a smaller storage requirement for a filtered index. Let&#8217;s take a look at the size of the index using the T-SQL query below.</p>
<p><code style="font-size: 14px;"><span style="color: blue;">USE </span><span style="color: black;">SampleDB<br />
GO<br />
</span><span style="color: blue;">SELECT<br />
</span><span style="color: magenta;">OBJECT_NAME</span><span style="color: gray;">(</span><span style="color: black;">i.</span><span style="color: magenta;">OBJECT_ID</span><span style="color: gray;">) </span><span style="color: blue;">AS </span><span style="color: black;">TableName</span><span style="color: gray;">,<br />
</span><span style="color: black;">i.name </span><span style="color: blue;">AS </span><span style="color: black;">IndexName</span><span style="color: gray;">,<br />
</span><span style="color: black;">i.index_id </span><span style="color: blue;">AS </span><span style="color: black;">IndexID</span><span style="color: gray;">,<br />
</span><span style="color: black;">8 </span><span style="color: gray;">* </span><span style="color: magenta;">SUM</span><span style="color: gray;">(</span><span style="color: black;">a.used_pages</span><span style="color: gray;">) </span><span style="color: blue;">AS </span><span style="color: red;">'Indexsize(KB)'<br />
</span><span style="color: blue;">FROM </span><span style="color: black;">sys.indexes </span><span style="color: blue;">AS </span><span style="color: black;">i<br />
</span><span style="color: blue;">JOIN </span><span style="color: black;">sys.partitions </span><span style="color: blue;">AS </span><span style="color: black;">p </span><span style="color: blue;">ON </span><span style="color: black;">p.</span><span style="color: magenta;">OBJECT_ID </span><span style="color: blue;">= </span><span style="color: black;">i.</span><span style="color: magenta;">OBJECT_ID </span><span style="color: gray;">AND </span><span style="color: black;">p.index_id </span><span style="color: blue;">= </span><span style="color: black;">i.index_id<br />
</span><span style="color: blue;">JOIN </span><span style="color: black;">sys.allocation_units </span><span style="color: blue;">AS </span><span style="color: black;">a </span><span style="color: blue;">ON </span><span style="color: black;">a.container_id </span><span style="color: blue;">= </span><span style="color: black;">p.partition_id<br />
</span><span style="color: blue;">WHERE </span><span style="color: magenta;">OBJECT_NAME</span><span style="color: gray;">(</span><span style="color: black;">i.</span><span style="color: magenta;">OBJECT_ID</span><span style="color: gray;">) </span><span style="color: blue;">=</span><span style="color: red;">'SalesOrderDetail'<br />
</span><span style="color: blue;">GROUP BY </span><span style="color: black;">i.</span><span style="color: magenta;">OBJECT_ID</span><span style="color: gray;">,</span><span style="color: black;">i.index_id</span><span style="color: gray;">,</span><span style="color: black;">i.name<br />
</span></code></p>
<p><img fetchpriority="high" decoding="async" class="aligncenter" src="http://bassplayerdoc.files.wordpress.com/2013/07/idx6.jpg" alt="" width="748" height="347" /></p>
<p>Looking at the screenshot, my guess is that the entire table contains half of the records that have a <strong>ModifiedDate</strong> greater than <strong>2004-01-01</strong>. Let&#8217;s use DBCC IND and DBCC PAGE &#8211; similar to what we did with the clustered index &#8211; to analyze the contents of the filtered index. This time, we&#8217;ll use IndexID value 3, the index ID of the filtered index.</p>
<p><code style="font-size: 14px;"><span style="color: blue;">DBCC </span><span style="color: black;">IND </span><span style="color: gray;">(</span><span style="color: black;">SampleDB</span><span style="color: gray;">, </span><span style="color: black;">SalesOrderDetail</span><span style="color: gray;">, </span><span style="color: black;">3</span><span style="color: gray;">)</span></code></p>
<p><img decoding="async" class="aligncenter" src="http://bassplayerdoc.files.wordpress.com/2013/07/idx7.jpg" alt="" width="748" height="347" /></p>
<p>I&#8217;ve already sorted out the index levels and found out that the page with the highest level is <strong>page number 880</strong>. Let&#8217;s use DBCC PAGE this time to navigate thru the index pages.</p>
<p><code style="font-size: 14px;"><span style="color: blue;">DBCC </span><span style="color: black;">TRACEON </span><span style="color: gray;">(</span><span style="color: black;">3604</span><span style="color: gray;">)<br />
</span><span style="color: black;">GO<br />
</span><span style="color: blue;">DBCC </span><span style="color: black;">PAGE </span><span style="color: gray;">(</span><span style="color: black;">SampleDB</span><span style="color: gray;">, </span><span style="color: black;">1</span><span style="color: gray;">, </span><span style="color: black;">880</span><span style="color: gray;">, </span><span style="color: black;">3</span><span style="color: gray;">)</span></code></p>
<p><img decoding="async" class="aligncenter" src="http://bassplayerdoc.files.wordpress.com/2013/07/idx8.jpg" alt="" width="748" height="347" /></p>
<p>If you look closely, all of the index pages have a <strong>ModifiedDate</strong> greater than <strong>2004-01-01</strong>. Compare this with the non-clustered index without the <strong>WHERE</strong> clause where the index pages contain all of the ModifiedDate values &#8211; a value for each record in the table.</p>
<p><code style="font-size: 14px;"><span style="color: blue;">DBCC </span><span style="color: black;">PAGE </span><span style="color: gray;">(</span><span style="color: black;">SampleDB</span><span style="color: gray;">, </span><span style="color: black;">1</span><span style="color: gray;">, </span><span style="color: black;">248</span><span style="color: gray;">, </span><span style="color: black;">3</span><span style="color: gray;">)</span></code></p>
<p><img loading="lazy" decoding="async" class="aligncenter" src="http://bassplayerdoc.files.wordpress.com/2013/07/idx9.jpg" alt="" width="748" height="347" /></p>
<p>With fewer pages to navigate thru, it will be faster to run a query that references the ModifiedDate column.</p>
<p><strong>Side Note:</strong> While working on this blog post, I stumbled upon a bug that got me spinning around in circles trying to figure out if there was something wrong with what I was doing. I did the usual thing of using DBCC IND and DBCC PAGE to navigate the index structure. However, I couldn&#8217;t get the tabular result to display when both the filtered and non-filtered indexes exist on the database. It took me a while to figure out that it was the filtered index that caused DBCC PAGE to not display the tabular result. I asked the question on the internal SQL Server MVP mailing list before I found out about this <a href="http://connect.microsoft.com/SQLServer/feedback/details/776144/dbcc-page-incorrect-output-with-filtered-indexes" target="_blank">Connect item</a>. Apparently, DBCC PAGE does not return a tabular result for the non-leaf level pages when a filtered index exists on a database. You will experience this behavior when running DBCC PAGE on a SQL Server 2012 instance. All the sample code that I used for these blog posts were on SQL Server 2008 R2 instance.</p>
]]></content:encoded>
			

		<wfw:commentRss>https://www.edwinmsarmiento.com/index-internals-and-what-filtered-indexes-look-like-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
				<post-id xmlns="com-wordpress:feed-additions:1">784</post-id>	</item>
	</channel>
</rss>