(Look in the Misconceptions blog category for the rest of the month’s posts and check out the 60-page PDF with all the myths and misconceptions blog posts collected together when you join our Insider list, plus my online Myths and Misconceptions training course on Pluralsight.)
I’m all mythed-out from yesterday, so today’s is a quick post addressing some myths around fill factor – which I made sure to stomp on back in SQL Server 2005 in Books Online.
Tomorrow I have a very cool one coming up…
Myth #25: various myths around fill factor.
All are FALSE
25a) fill factor is adhered to at all times
No. From Books Online:
The fill-factor setting applies only when the index is created, or rebuilt. The SQL Server Database Engine does not dynamically keep the specified percentage of empty space in the pages. Trying to maintain the extra space on the data pages would defeat the purpose of fill factor because the Database Engine would have to perform page splits to maintain the percentage of free space specified by the fill factor on each page as data is entered.
25b) fill factor of 0 is different from fill factor of 100
No: From Books Online:
Fill-factor values 0 and 100 are the same in all respects.
25c) fill factor of 0 leaves some space in the upper levels of the index
No. This one isn’t in Books Online and I don’t know where this myth came from, but it’s completely untrue. You can easily convince yourself of this using a script like the one below:
CREATE DATABASE foo; GO USE foo; GO CREATE TABLE t1 (c1 INT IDENTITY, c2 CHAR (1000) DEFAULT 'a'); CREATE CLUSTERED INDEX t1c1 ON t1 (c1); GO SET NOCOUNT ON; GO INSERT INTO t1 DEFAULT VALUES; GO 10000
Now check the fill factor is 0 and perform an index rebuild.
SELECT [fill_factor] FROM sys.indexes WHERE NAME = 't1c1' AND [object_id] = OBJECT_ID ('t1'); GO ALTER INDEX t1c1 ON t1 REBUILD WITH (FILLFACTOR = 100); GO
Then figure out the index pages above the leaf level and look at the m_freeCnt value in the page header, the amount of free space on the page:
EXEC sp_allocationMetadata 't1'; GO DBCC TRACEON (3604); -- the root page, from the SP output DBCC PAGE (foo, 1, 164, 3); GO -- the page ID in the DBCC PAGE output above DBCC PAGE (foo, 1, 162, 1); GO
I see a value of 10 bytes – clearly no space was left on the page. It’s a myth. Btw – you can get the sp_allocationMetadata script from this blog post.