Course contentsShow
← Databases & SQL
Lesson 590 of 1,9536. Query Performance and IndexingFree lesson

Index Fill Factor Tuning

Reserve space in index nodes to prevent excessive page splits in frequently updated tables.

Index Fill Factor Tuning

In this lesson, you will learn how to balance storage efficiency and write performance by strategically leaving "breathing room" inside your B-tree index pages.

When you create an index, the database engine packs data rows into pages. By default, many systems try to fill every page to 100% capacity. This is perfect for read-only tables. However, in tables that experience frequent updates or insertions, a full page creates a significant problem: there is no physical space to insert new data. When a new row needs to fit into a full page, the engine must perform a page split. It allocates a new page, moves half of the existing data over, and updates the B-tree pointers. This is an expensive operation that increases I/O and creates physical fragmentation.

Controlling Density with Fill Factor

"Fill Factor" is a setting that tells the database engine to only fill a page to a specific percentage, leaving the remaining space as free area for future inserts.

If you set a Fill Factor of 80%, the database leaves 20% of each leaf node empty during index creation or rebuilds. While this makes the index larger (using more storage and potentially increasing the B-tree depth), it drastically reduces page splits because incoming rows can simply be placed into the pre-reserved empty space.

Consider this conceptual example for a table with heavy daily updates:

-- Create an index with an 80% Fill Factor
CREATE INDEX IX_Orders_Status 
ON Orders (OrderStatus) 
WITH (FILLFACTOR = 80);

When to Tune

  • 100% Fill Factor (or default): Ideal for static, read-only lookup tables where performance is measured solely by how many rows fit in memory at once.
  • Lower Fill Factor (e.g., 70-90%): Essential for highly volatile tables where rows are inserted or updated frequently. You are effectively trading off some disk space and potential read efficiency for a massive reduction in the overhead of rebalancing the tree.

By carefully tuning this value, you prevent the "shuffling" of pages, keeping your B-tree balanced and your write performance smooth.

Key Takeaway: A lower Fill Factor reserves empty space in index pages to accommodate future updates, preventing costly page splits and maintaining long-term index performance.