[i]Clustered indexes also have some disadvantages compared to heaps. When you insert a new row into a full page, SQL Server has to split the page into two pages and move half of the rows to the second page. This happens because SQL Server needs to maintain the logical order of the rows. This way, you get some internal fragmentation, which you cannot get in a heap. In addition, the new page (or new uniform extent for a large table) can be reserved anywhere in a data file.[/i]It says "When you insert a new row into a full page, SQL Server has to split the page into two pages and move half of the rows to the second page" Adding a new extent/page is correct when the given space is completely full or does not accomodate the new data to be added but what does it mean when it says "SQL Server has to split the page into two pages and move half of the rows to the second page" 1.TRUNCATE TABLE dbo.TestStructure;2.CREATE CLUSTERED INDEX idx_cl_id ON dbo.TestStructure(id);3.DECLARE @i AS int = 0;WHILE @i < 18630BEGINSET @i = @i + 1;INSERT INTO dbo.TestStructure(id, filler1, filler2)VALUES(@i, 'a', 'b');END;4.SELECT index_type_desc, index_depth, index_level, page_count, record_count, avg_page_space_used_in_percentFROM sys.dm_db_index_physical_stats (DB_ID(N'tempdb'), OBJECT_ID(N'dbo.TestStructure', N'U'), NULL, NULL , 'DETAILED');The result : index_type_desc index_depth index_level page_count record_count avg_pg_spc_used_in_pct--------------- ----------- ----------- ---------- ------------ ----------------------CLUSTERED INDEX 2 0 621 18630 98.1961947121324CLUSTERED INDEX 2 1 1 621 99.71583889300725.INSERT INTO dbo.TestStructure(id, filler1, filler2)VALUES(18631, 'a', 'b');6.Run code in step 4:result is:index_type_desc index_depth index_level page_count record_count avg_pg_spc_used_in_pct--------------- ----------- ----------- ---------- ------------ ----------------------CLUSTERED INDEX 3 0 622 18631 98.0435507783543CLUSTERED INDEX 3 1 2 622 49.9258710155671CLUSTERED INDEX 3 2 1 2 0.296515937731653And the explanation says:Now the index has three levels. Because a new page was allocated on the leaf level, the original root page could not reference all leaf pages anymore. SQL Server added an intermediate level with two pages pointing to 622 leaf pages, and a new root page pointing to the two intermediate-level pages.Why was a new page allocated here ?I have not understood the concept entirely.can some please explain this.
↧