<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Indexes on Andy M Mallon - AM²</title><link>https://am2.co/category/indexes/</link><description>Recent content in Indexes on Andy M Mallon - AM²</description><generator>Hugo</generator><language>en-US</language><lastBuildDate>Thu, 29 Aug 2024 11:19:07 -0400</lastBuildDate><atom:link href="https://am2.co/category/indexes/index.xml" rel="self" type="application/rss+xml"/><item><title>Not all stats should be auto-updated</title><link>https://am2.co/2024/08/29/not-all-stats-should-be-auto-updated/</link><pubDate>Thu, 29 Aug 2024 11:19:07 -0400</pubDate><guid>https://am2.co/2024/08/29/not-all-stats-should-be-auto-updated/</guid><description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=CO__LF_m_O8"&gt;&lt;img src="https://am2.co/wp-content/uploads/StatsDog-300x300.png" alt="" width="300" height="300" class="alignright size-medium wp-image-53810" /&gt;&lt;/a&gt;Statistics auto-updates are generally a good thing&amp;ndash;auto-update of &lt;a href="https://learn.microsoft.com/en-us/sql/relational-databases/statistics/statistics?view=sql-server-ver16" rel="noopener" target="_blank"&gt;statistics&lt;/a&gt; is the default behavior in SQL Server. Having the freshest information about the data &amp;ldquo;shape&amp;rdquo; helps to inform the best selection of an execution plan for queries.&lt;/p&gt;&#10;&lt;h2 id="except-for-when-it-doesnt"&gt;Except for when it doesn&amp;rsquo;t.&lt;/h2&gt;&#10;&lt;h3 id="because-it-depends"&gt;Because It Depends™️&lt;/h3&gt;&#10;&lt;p&gt;Let&amp;rsquo;s talk about the trade-offs.&lt;/p&gt;</description></item><item><title>What's the use case of disabling an index?</title><link>https://am2.co/2022/09/25/whats-the-use-case-of-disabling-an-index/</link><pubDate>Sun, 25 Sep 2022 17:10:28 -0400</pubDate><guid>https://am2.co/2022/09/25/whats-the-use-case-of-disabling-an-index/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/317371/52344"&gt;&lt;img src="https://am2.co/wp-content/uploads/blockquote.png" alt="clip art of &#10;a double-quote character" width="100" height="75" class="alignleft size-full wp-image-55062" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I just learned that indexes can be disabled on a table. Even the clustered index can be disabled. After that, users can&amp;rsquo;t access the index or the data if clustered index. When will we disable an index? I just don&amp;rsquo;t understand the use case.&lt;/p&gt;</description></item><item><title>Making non-SARGable queries seek, without changing the query</title><link>https://am2.co/2020/05/06/making-non-sargable-queries-seek-without-changing-the-query/</link><pubDate>Wed, 06 May 2020 08:36:27 -0400</pubDate><guid>https://am2.co/2020/05/06/making-non-sargable-queries-seek-without-changing-the-query/</guid><description>&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=tALDcVmWE9w" rel="noopener noreferrer" target="_blank"&gt;&lt;img src="https://am2.co/wp-content/uploads/sarg-pubs-featured-1024x577.png" alt="" width="512" height="289" class="alignright size-large wp-image-3253" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;p&gt;We&amp;rsquo;ve all been there. You&amp;rsquo;ve got a query where the &lt;code&gt;JOIN&lt;/code&gt; or &lt;code&gt;WHERE&lt;/code&gt; predicate is not &lt;a href="https://dba.stackexchange.com/a/217983/52344" rel="noopener noreferrer" target="_blank"&gt;SARGable&lt;/a&gt;. You&amp;rsquo;ve read about how &lt;a href="https://www.erikdarlingdata.com/2019/04/slightly-less-not-sargable/" rel="noopener noreferrer" target="_blank"&gt;this can be a problem&lt;/a&gt;, and &lt;a href="https://www.erikdarlingdata.com/2019/04/slightly-less-not-sargable/" rel="noopener noreferrer" target="_blank"&gt;how bad it is for performance&lt;/a&gt;.&lt;/p&gt;&#10;&lt;p&gt;Alas, you cannot change the query. Sometimes this reason is political, sometimes it&amp;rsquo;s because you&amp;rsquo;ve got a third-party app and simply don&amp;rsquo;t have access to the code. But you do have access to the database&amp;hellip;&lt;/p&gt;</description></item><item><title>When to put a non-clustered index on your clustering key</title><link>https://am2.co/2019/09/03/when-to-put-a-non-clustered-index-on-your-clustering-key/</link><pubDate>Tue, 03 Sep 2019 21:17:14 -0400</pubDate><guid>https://am2.co/2019/09/03/when-to-put-a-non-clustered-index-on-your-clustering-key/</guid><description>&lt;figure class="wp-caption alignright" style="max-width:400px"&gt;&lt;a href="https://www.youtube.com/watch?v=uvWL6_A7uQc" rel="noopener noreferrer" target="_blank"&gt;&lt;img src="https://am2.co/wp-content/uploads/david-kohler-vIi2aNfPQ00-unsplash.jpg" alt="" width="400" height="600" class="size-medium wp-image-2121" /&gt;&lt;/a&gt; These vines are clustered by Cabernet Sauvignon.&lt;/figure&gt;&#10;#### First off, let's remember the difference between clustered &amp; nonclustered indexes&#10;&lt;p&gt;The &lt;strong&gt;clustered index&lt;/strong&gt; is organized by the key columns. It also includes every other column as part of the row structure (ie, it has the entire row).&lt;/p&gt;</description></item><item><title>Nonclustered index storage on clustered columnstore</title><link>https://am2.co/2017/01/06/nonclustered-index-storage-on-clustered-columnstore/</link><pubDate>Fri, 06 Jan 2017 11:47:02 -0500</pubDate><guid>https://am2.co/2017/01/06/nonclustered-index-storage-on-clustered-columnstore/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/160158/52344"&gt;&lt;img src="https://am2.co/wp-content/uploads/blockquote.png" alt="clip art of &#10;a double-quote character" width="100" height="75" class="alignleft size-full wp-image-55062" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;In SQL Server, a non-unique nonclustered index on a rowstore table incorporates the base object&amp;rsquo;s &lt;em&gt;bookmark&lt;/em&gt; (RID or clustering key) at all levels of the nonclustered index structure. The bookmark is stored as part of the nonclustered index &lt;em&gt;key&lt;/em&gt; at all index levels.&lt;/p&gt;</description></item><item><title>Does it ever make sense to have a clustered and non clustered index for the same column</title><link>https://am2.co/2016/08/16/does-it-ever-make-sense-to-have-a-clustered-and-non-clustered-index-for-the-same-column/</link><pubDate>Tue, 16 Aug 2016 22:08:55 -0400</pubDate><guid>https://am2.co/2016/08/16/does-it-ever-make-sense-to-have-a-clustered-and-non-clustered-index-for-the-same-column/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/147011/52344"&gt;&lt;img src="https://am2.co/wp-content/uploads/blockquote.png" alt="clip art of &#10;a double-quote character" width="100" height="75" class="alignleft size-full wp-image-55062" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;Does it ever make sense to have a clustered and non clustered index for the same column&lt;/p&gt;&#10;&lt;p&gt;I inherited a database and a web service that goes with it.&lt;/p&gt;&#10;&lt;p&gt;Looking at the indexes for duplicates I see an two indexes that point at the same column (1 column and sorted the same way). One is clustered and one is not, that is the only difference I see.&lt;/p&gt;</description></item><item><title>Data Compression: How page compression works</title><link>https://am2.co/2016/02/22/data-compression-how-page-works/</link><pubDate>Mon, 22 Feb 2016 10:00:59 -0500</pubDate><guid>https://am2.co/2016/02/22/data-compression-how-page-works/</guid><description>&lt;p&gt;SQL Server supports two kinds of data compression on rowstore data. Columnstore compression is for a different day. You can compress heaps, clustered indexes (on both tables and views), and nonclustered indexes (on both tables and views).&lt;/p&gt;&#10;&lt;h3 id="compression-requirements"&gt;Compression requirements&lt;/h3&gt;&#10;&lt;p&gt;Data compression is available in SQL Server 2008 &amp;amp; newer. It was introduced as an Enterprise Edition feature&amp;ndash;if you were using Standard Edition or Express, then you were out of luck. Starting with SQL Server 2016 SP1 (thus all currently-supported versions), data compression is available across all Editions. There are &lt;a href="https://am2.co/2015/12/29/data-compression-costs-benefits/"&gt;benefits &amp;amp; costs to using data compression&lt;/a&gt;&amp;ndash;as with anything, make sure you understand it before you implement it.&lt;/p&gt;</description></item><item><title>Data Compression: How row compression works</title><link>https://am2.co/2016/02/15/data-compression-how-row-works/</link><pubDate>Mon, 15 Feb 2016 10:07:29 -0500</pubDate><guid>https://am2.co/2016/02/15/data-compression-how-row-works/</guid><description>&lt;p&gt;SQL Server supports two kinds of data compression on rowstore data. Columnstore compression is for a different day. You can compress heaps, clustered indexes (on both tables and views), and nonclustered indexes (on both tables and views).&lt;/p&gt;&#10;&lt;h3 id="compression-requirements"&gt;Compression requirements&lt;/h3&gt;&#10;&lt;p&gt;Data compression is available in SQL Server 2008 &amp;amp; newer. It is an Enterprise Edition feature&amp;ndash;if you&amp;rsquo;re using Standard Edition or Express, then you&amp;rsquo;re out of luck. There are &lt;a href="https://am2.co/2015/12/29/data-compression-costs-benefits/"&gt;benefits &amp;amp; costs to using data compression&lt;/a&gt;&amp;ndash;as with anything, make sure you understand it before you implement it.&lt;/p&gt;</description></item><item><title>Data Compression: Costs &amp; benefits</title><link>https://am2.co/2015/12/29/data-compression-costs-benefits/</link><pubDate>Tue, 29 Dec 2015 15:00:56 -0500</pubDate><guid>https://am2.co/2015/12/29/data-compression-costs-benefits/</guid><description>&lt;p&gt;SQL Server supports two kinds of data compression on rowstore data. Columnstore compression is for a different day. You can compress heaps, clustered indexes (on both tables and views), and nonclustered indexes (on both tables and views).&lt;/p&gt;&#10;&lt;h3 id="compression-requirements"&gt;Compression requirements&lt;/h3&gt;&#10;&lt;p&gt;Data compression is available in SQL Server 2008 &amp;amp; newer. It is an Enterprise Edition feature&amp;ndash;if you&amp;rsquo;re using Standard Edition or Express, then you&amp;rsquo;re out of luck.&lt;/p&gt;</description></item><item><title>sp_get_basetable_list</title><link>https://am2.co/2014/05/22/sp_get_basetable_list/</link><pubDate>Thu, 22 May 2014 15:18:00 -0400</pubDate><guid>https://am2.co/2014/05/22/sp_get_basetable_list/</guid><description>&lt;p&gt;At work, we make extensive use of views &amp;amp; synonyms. The reasons are complex (and fodder for another post), but here&amp;rsquo;s a simplified example:&lt;/p&gt;&#10;&lt;blockquote&gt;Pricing data is updated multiple times per day, and we want to keep multiple generations of the pricing table online. By pointing the synonym to the latest pricing table, we can redirect users to the current/correct data. If there's a problem, we can "roll back" the latest pricing updates by simply pointing the synonym back to the prior generation of pricing data.&lt;/blockquote&gt;&#10;&lt;p&gt;Obviously, this can create some confusion when you do need to find the actual table (eg, to see indexes, or to update data). What pricing table is the real pricing table?&#10;Sure&amp;ndash; you can query system views to find out the real table(s) referenced by the synonym or view.&#10;When you do this hundreds (or thousands) of times, &lt;a href="http://xkcd.com/1205/"&gt;it can really add up.&lt;/a&gt; Time to automate.&lt;/p&gt;</description></item></channel></rss>