<?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/tag/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/tag/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>AG secondary is out of sync for hours after index maintenance</title><link>https://am2.co/2023/02/21/ag-secondary-is-out-of-sync-for-hours-after-index-maintenance/</link><pubDate>Tue, 21 Feb 2023 13:17:04 -0500</pubDate><guid>https://am2.co/2023/02/21/ag-secondary-is-out-of-sync-for-hours-after-index-maintenance/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/323858/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;We have a 3TB OLTP database running Siemens Opcenter MES software at one of our manufacturing plants in China. This is setup in an Always-On Availability group with one secondary node. As this is a manufacturing plant, we are only provided 11 1/2 hours every two weeks to run index maintenance when the plant is not running production. We use Hallengren scripts to run this index maintenance.&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/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&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>Partitioning and existing Indexes</title><link>https://am2.co/2021/09/12/partitioning-and-existing-indexes/</link><pubDate>Sun, 12 Sep 2021 11:11:25 -0400</pubDate><guid>https://am2.co/2021/09/12/partitioning-and-existing-indexes/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/299454/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I have a table that consumes almost 1.2 TB of space and has lots of historical data which are mostly irrelevant. Since performing bulk DELETE is going to cause a lot of heavy-lifting, I'm trying to use the concept of horizontal partitioning to create multiple partitions, each containing early data (for eg: 2017,2018... 2021) so that I can simply truncate those partitions which is less than an year, so that I can only retain the relevant operational data.&lt;/p&gt;</description></item><item><title>Tech Community Equality Index</title><link>https://am2.co/2020/06/24/tech-community-equality-index/</link><pubDate>Wed, 24 Jun 2020 05:00:19 -0400</pubDate><guid>https://am2.co/2020/06/24/tech-community-equality-index/</guid><description>&lt;style&gt;&#10; table {&#10; border-collapse: collapse;&#10; width: 100%;&#10; caption-side: bottom !important;&#10; }&#10; tr:nth-child(even) {background-color: #F2F7DF;}&#10;&lt;/style&gt;&#10;&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=nCS7Rus4_-Y" rel="noopener noreferrer" target="_blank"&gt;&lt;img src="https://am2.co/wp-content/uploads/photo-of-a-person-wearing-printed-crew-neck-t-shirt-2769325-1024x576.jpg" alt="" width="512" height="288" class="alignright size-large wp-image-3659" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;p&gt;Over the last weeks &amp;amp; months, I&amp;rsquo;ve had an increasing number of conversations with folks on the topics of diversity, inclusion, equality, and justice. These discussions we have with coworkers, members of the data community, family and friends are all valuable, and help us look at life in a different, more inclusive way.&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>How Large Table before Using Clustered Columnstore Index</title><link>https://am2.co/2018/09/27/how-large-table-before-using-clustered-columnstore-index/</link><pubDate>Thu, 27 Sep 2018 16:43:03 -0400</pubDate><guid>https://am2.co/2018/09/27/how-large-table-before-using-clustered-columnstore-index/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/218751/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;At what size should we consider applying Columnstore Index on a table? Is there a SQL Server storage or design guidance? &lt;/p&gt;&#10;&lt;p&gt;Our Data Warehouse is 5TB total. Additionally, we have tables which are 100GB to 1TB which compose the database. Just curious if SQL Server has guidance on how large should table before a columnstore index is applied? &lt;/p&gt;</description></item><item><title>Rebuild Very Large Primary Key Index</title><link>https://am2.co/2017/09/02/rebuild-very-large-primary-key-index/</link><pubDate>Sat, 02 Sep 2017 22:40:43 -0400</pubDate><guid>https://am2.co/2017/09/02/rebuild-very-large-primary-key-index/</guid><description>&lt;p&gt;&lt;a href="https://dba.stackexchange.com/q/184973/52344"&gt;&lt;img src="https://am2.co/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&gt;&lt;/a&gt;&lt;/p&gt;&#10;&lt;h2 id="question"&gt;Question&lt;/h2&gt;&#10;&lt;p&gt;I have a SQL database that is hosted on Azure. The problem is that the size is getting out of control, I can see up to 99% fragmentation in the Primary Key clustered indexes.&lt;/p&gt;&#10;&lt;p&gt;I'm able to rebuild all other indexes with &lt;code&gt;online=on&lt;/code&gt; option and it won't affect performance. The size of one of the PK Clustered indexes is greater than 200GB, and for this one a &lt;code&gt;REBUILD...WITH (ONLINE=ON)&lt;/code&gt; causes locking.&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/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&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/images/stack-exchange-question-mark.svg" alt="Question on Stack Exchange" width="96" height="96" class="stack-exchange-question-icon" /&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>