Discussion Tell me your stories about FillFactor.
I just had an interview question on it. It’s something I know but never use. I thought it was one of those features folks stopped using because of solid state drives. The interviewer disagreed.
FillFactor a percentage setting on an index that tells rebuilds how full to make the pages. That way you can avoid expensive page splits.
6
Upvotes
4
u/SQLBek 17d ago
SQL Server - FILL FACTOR is still important because page DENSITY is still important. I am guessing that it is external fragmentation that you are thinking is no longer relevant.
And for the most part, it's fragmentation is not as impactful, but not because of SSDs. I cover this in my EightKB online deep dive presentation that you can find on YouTube, but in a nutshell, fragmentation is representative of the data pages logical placement within a data file. That's decoupled from how those data pages may wind up ultimately being written down to storage, whatever it may be - spinning rust, direct attached SSD, virtualized disks, or a SAN (for example).
1
u/SteveDBA 17d ago
I think you’re confusing fill factor with disk defragmentation. It’s not really about spinning disks versus SSDs.
I’ve seen environments where fill factor was set to 80% and index maintenance hadn’t been performed in nearly two years. Some indexes were over 100 GB. Just getting regular index rebuilds back in place made a significant difference in stored procedure performance, with CPU usage and disk I/O dropping considerably.
That said, I wouldn’t recommend 80% across the board. It really depends on the workload and insert/update patterns.
1
u/luigicanu 16d ago
Not my story, but this is a great presentation by Jeff Moden.
https://www.youtube.com/watch?v=JYYHalwjBwA
2
u/Thadrea Data Science Manager 17d ago
No particular stories, but it absolutely is not something that has gone away because of SSDs.
There is still going to be a performance impact from the order the rows are stored in on the disk. It may be smaller than it was with magnetic hard drives, but it's still there.
2
u/ResidentPomegranate6 17d ago
fillfactor only sticks on rebuild, reorg ignores it, and ascending keys insert right-edge anyway so 100 is fine there.
2
u/Significant_Tune9219 17d ago
The SSD argument covers the random I/O cost, but a page split still costs CPU, extra log records, and leaves two half-full pages, so the index gets bigger and scans read more pages regardless of the storage. Where it matters most is indexes on keys that insert into the middle, like GUIDs or natural keys, while an ever-increasing identity key mostly splits at the end and is fine at 100. Setting a lower value on everything just bloats indexes, so checking page splits and fragmentation per index before changing it is the usual approach.
1
u/raistlin49 17d ago
Here's a story about fill factor...join a new shop...they're complaining about chronic index fragmentation regardless of daily maintenance...tables have nonsequential UNIQUEIDENTIFIER PKs and a bunch of indexes with FILLFACTOR=100. Guess what happens when you put those together? Page split on literally every insert. As soon as you get some free space on all those half pages...boom...index maintenance...back to page splits lol
1
u/markwdb3 When in doubt, test it out. 17d ago edited 17d ago
Which DBMS software? How it works, and if it even exists for a given DBMS, varies.
0
u/The_Orracle 17d ago
Literally just used it tonight!
DECLARE u/ObjectID int = OBJECT_ID(N'dbo.Customer_D', N'U');
IF u/ObjectID IS NULL
THROW 50000, 'dbo.Customer_D was not found or is not visible.', 1;
SELECT
i.index_id,
i.name AS IndexName,
i.type_desc AS IndexType,
i.is_unique AS IsUnique,
i.is_disabled AS IsDisabled,
i.has_filter AS HasFilter,
i.filter_definition AS FilterDefinition,
i.fill_factor AS 'FillFactor',
SUM(p.row_count) AS ApproxRows,
CAST(SUM(p.used_page_count) / 128.0 AS decimal(18, 2)) AS UsedMiB,
CAST(SUM(p.reserved_page_count) / 128.0 AS decimal(18, 2)) AS ReservedMiB,
t.name AS AccountNumberType,
c.max_length AS AccountNumberMaxBytes,
c.is_nullable AS AccountNumberIsNullable
FROM sys.indexes AS i
JOIN sys.dm_db_partition_stats AS p
ON p.object_id = i.object_id
AND p.index_id = i.index_id
JOIN sys.columns AS c
ON c.object_id = i.object_id
AND c.name = N'CustomerAccountNumber'
JOIN sys.types AS t
ON t.user_type_id = c.user_type_id
WHERE i.object_id = u/ObjectID
GROUP BY
i.index_id, i.name, i.type_desc, i.is_unique, i.is_disabled,
i.has_filter, i.filter_definition, i.fill_factor,
t.name, c.max_length, c.is_nullable
ORDER BY i.index_id;
SELECT
i.name AS IndexName,
ic.key_ordinal AS KeyOrdinal,
c.name AS ColumnName,
t.name AS DataType,
c.max_length AS MaxBytes,
c.is_nullable AS IsNullable,
ic.is_included_column AS IsIncluded
FROM sys.indexes AS i
JOIN sys.index_columns AS ic
ON ic.object_id = i.object_id
AND ic.index_id = i.index_id
JOIN sys.columns AS c
ON c.object_id = ic.object_id
AND c.column_id = ic.column_id
JOIN sys.types AS t
ON t.user_type_id = c.user_type_id
WHERE i.object_id = u/ObjectID
AND i.type IN (1, 2)
AND (ic.key_ordinal > 0 OR ic.is_included_column = 1)
ORDER BY i.index_id, ic.is_included_column, ic.key_ordinal, ic.index_column_id;