Skip to content
  • Home
  • About
  • No Access
  • Privacy Policy
Bits of .NET
Bits of .NET
  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • C#
  • Asp.Net Core
  • SQL
  • Windows
  • WordPress
  • AI
  • JavaScript
  • CSS
  • MORE
    • HTML
    • Ajax
    • Git
    • Docker
    • Kubernetes
    • Photoshop
    • Visual Studio
SQL

SQL Server: Fix an XML Index Rebuild Timing Out Nightly

- 01.12.26 - ErcanOPAK

🗄️ Fix an XML Index Rebuild Timing Out Nightly

A primary XML index has to be rebuilt in full whenever its underlying table undergoes significant change, since XML indexes don’t support the same incremental maintenance path as a standard rowstore index, and a nightly maintenance job that rebuilds it unconditionally — rather than checking whether it actually needs rebuilding — can simply outgrow its maintenance window as the table’s XML column grows, timing out partway through and leaving the index in a degraded, partially-rebuilt state until the next run.

🔎 The Problem

-- Nightly job, unconditional every run:
ALTER INDEX PXML_Documents_Content ON dbo.Documents REBUILD;
-- Table has grown from 200k to 1.4M rows over 6 months
-- Job's maintenance window (60 min) no longer covers full rebuild time
-- Job log: "Timeout expired" partway through, index left degraded

✅ Fix: Rebuild Only When It’s Actually Needed, With Room to Finish

  • Check fragmentation via sys.dm_db_xml_index_physical_stats before rebuilding, and skip the rebuild entirely on nights where fragmentation is already low, instead of paying the full cost unconditionally every single run.
  • If the table has genuinely outgrown the maintenance window, split the XML index rebuild into its own longer window separate from the rest of the nightly maintenance plan, rather than letting it compete for time with unrelated jobs.
  • Monitor rebuild duration over time as a trend, not just success/failure of the last run — a job that’s taking 10% longer each month gives you weeks of warning before it actually times out.

An index that worked fine at 200,000 rows doesn’t get a vote on how long it’s allowed to take at 1.4 million — the maintenance window does.

— Database Engineer

Related posts:

SQL Temporal Tables: Track Data Changes Over Time

SQL Temporal Tables: Track Data Changes Over Time

SQL: Use Triggers for Automated Actions

SQL: Use Triggers for Automated Actions

SQL Server JSON Support: NoSQL Flexibility with SQL Power

SQL Server JSON Support: NoSQL Flexibility with SQL Power

Views: 0
Found this useful? Share it
XLinkedInWhatsApp

Post navigation

WordPress: Fix Block Patterns Registering Twice After a Theme Switch
Windows 11: Fix Game Bar Overlay Blocking a Borderless App

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Most Read

  1. 01How to make theater mode the default for Youtube 1,079 views
  2. 02How to add default value for Entity Framework migrations for DateTime and Bool 997 views
  3. 03Get the User Name and Domain Name from an Email Address in SQL 996 views
  4. 04Get the First and Last Word from a String or Sentence in SQL 873 views
  5. 05How to select distinct rows in a datatable in C# 868 views
  6. 06How to enable, disable and check if Service Broker is enabled on a database in SQL Server 671 views
  7. 07Add Constraint to SQL Table to ensure email contains @ 631 views
  8. 08Average of all values in a column that are not zero in SQL 584 views
  9. 09How to use Map Mode for Vertical Scroll Mode in Visual Studio 561 views
Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
Back to top
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com