When the fill factor is set on an index, it is applied to the index when the index is built, rebuilt, or reorganized. Unfortunately, with this myth many people believe that fill factor is applied when records are inserted into a table. In this section, you’ll investigate this myth and see that it is not correct.
To begin pulling this myth apart, let’s look at what most people believe. In the myth, the thought is that if a fill factor has been specified when rows are added to a table, the fill factor is used during the inserts. To dispel this portion of the myth, execute the code in Listing 17. In this script, the table dbo.MythSeven is created with a clustered index with a 50 percent fill factor. That means that 50 percent of every page in the index should be left empty. With the table built, you’ll insert records into the table. Finally, you’ll check the average amount of space available on each page through the sys.dm_db_index_physical_stats DMV. Looking at the results of the script, included in Figure 8-14, the index is using 95 percent of every page versus the 50 percent that was specified in the creation of the clustered index.
Listing 17. Create and Populate MythSix Table
USE AdventureWorks2014 GO IF OBJECT_ID('dbo.MythSeven') IS NOT NULL DROP TABLE dbo.MythSeven; GO CREATE TABLE dbo.MythSeven ( RowID int NOT NULL ,Column1 varchar(500) ); GO ALTER TABLE dbo.MythSeven ADD CONSTRAINT PK_MythSeven PRIMARY KEY CLUSTERED (RowID) WITH(FILLFACTOR = 50); GO WITH L1(z) AS (SELECT 0 UNION ALL SELECT 0) , L2(z) AS (SELECT 0 FROM L1 a CROSS JOIN L1 b) , L3(z) AS (SELECT 0 FROM L2 a CROSS JOIN L2 b) , L4(z) AS (SELECT 0 FROM L3 a CROSS JOIN L3 b) , L5(z) AS (SELECT 0 FROM L4 a CROSS JOIN L4 b) , L6(z) AS (SELECT TOP 1000 0 FROM L5 a CROSS JOIN L5 b) INSERT INTO dbo.MythSeven SELECT ROW_NUMBER() OVER (ORDER BY z) AS RowID, REPLICATE('X', 500) FROM L6; GO SELECT object_id, index_id, avg_page_space_used_in_percent FROM sys.dm_db_index_physical_stats(DB_ID(),OBJECT_ID('dbo.MythSeven'),NULL,NULL,'DETAILED') WHERE index_level = 0;
When it comes to fill factor, there are a number of myths surrounding the index property. The key to understanding fill factor is to remember when and how it is applied. It isn’t a property enforced on an index as it is used. It is, instead, a property used to distribute data within an index when it is created or rebuilt.
For all your application development needs, visit www.verbat.com for a fiscally conscious proposal that meets your needs ( So I can keep this blog going as well!!!!)
Alternatively click through the link if you found this article interesting. (This will help the companies Search engine rankings)