r/SQLServer • u/dfurmanms Microsoft Employee • Mar 18 '26
Community Share Introducing Automatic Index Compaction
We just released a MSSQL engine feature that might just make the whole index maintenance debate obsolete (or should at least make it less boring). Auto index compaction is now in public preview in Azure SQL and Fabric SQL.
Announcement blog: Stop defragmenting and start living: introducing auto index compaction.
Documentation (with an FAQ): Automatic Index Compaction | Microsoft Learn.
Would you use this instead of your own index maintenance? Tell us what you think.
55
Upvotes
11
u/cl0ckt0wer Mar 18 '26
Great, when will it come to on-prem MSSQL?
And a comparison to online reindexing would be great.
4
u/C0ntrol_Group Mar 18 '26
Will this feature be coming to on-prem SQL Server, and if so, will it be edition gated?
How well does it work if added to existing large (TB range) tables? How well does it work as a table scales from new to TB range?
How well does it keep up with high tx volume tables (hundreds to thousands tx/s)?
I would love to walk away from our overnight index jobs.
3
u/Lost_Term_8080 Mar 18 '26
Can this be made to be configurable at the table level instead of database-wide?
It seems that this would greatly increase page splits in tables that experience a lot of updates to columns that are expanding.
2
u/throwaway18000081 Mar 18 '26
This looks great! I’ll be testing this out in a NonProd environment next week to see if it has a positive impact. As of right now, it seems to replace index maintenance somewhat, so will keep statistics jobs in place.
Could you expand on why certain indexes should be rebuild for this to work correctly? In reference to “If the page density for an index is already low, consider running a one-time index reorganization or index rebuild to increase it, and then enable automatic compaction to keep indexes compact as future data modifications occur.”
Wouldn’t this process help with page density since it rids of empty pages? “As the cleaner visits each page with the recently inserted, updated, or deleted rows, it checks the free space on the current page and the used space in several of the following pages. If there's enough free space on the current page, the cleaner moves rows from the following pages to the current page if that action makes at least one of the following pages empty. Empty pages are deallocated. As a result, the total number of used pages in the database decreases, page density increases, and the consumption of storage space, disk I/O, CPU, and buffer pool memory is reduced.”
I’m confused how those two statements don’t contradict each other and need clarification.
13
u/BrentOzar Mar 18 '26
AWWWWWW YEAH, looks really cool and useful at first glance.
6
u/NewFactor9514 Mar 18 '26
I feel like I'm the guy in that coma who's living an entirely separate, fullfilled life with a wife and kids and a house in the burbs, and then he sits down one afternoon and notices the lamp by the bed looks slightly wrong, and then as he keeps looking at the lamp, he suddenly realizes that he has been in a coma for 15 years, and none of the wife and family are real, and he's surrounded by strangers saying 'oh my god, you woke up, you woke up', except that in my case, the lamp thing is Microsoft's announcement of auto index compaction, a feature that I've wanted since ~2005.
1
u/SonOfZork Mar 18 '26
How does this work with clustering guid keys given the high page split frequency?
1
u/Jero9871 May 18 '26
Does this also work for large tables after a Migration that adds a new column? We are having the problem that adding new columns makes queries pretty slow in Azure SQL DBs and a complete rebuild of the tables fixes that (however it takes around 30 minutes).
1
u/TridentDataSolutions Mar 18 '26
Very nice- looks hella useful. Thanks!
1
u/agiamba Mar 18 '26
This is really fantastic, thanks!
1
u/DavidKleeGeek Microsoft MVP Mar 18 '26
This is really exciting. I can't wait to start seeing this in action!
1
u/SQLBek 1 Mar 18 '26
Interesting! I'd love to dig deeper into how this works thanks to PVS.
Would be curious to get this into Jeff Moden's hands, to see how this impacts the GUID fragmentation behaviors he discusses in his Black Arts of Indexing session.
Thanks Dimitri!