Hi,
Today when i check my Azure SQL DB
You are using the tag sql-server-general
, which mean SQL Server on premises usually, and speak about Azure SQL DB
. You better use the tag azure-sql-database
Density
To be 100% sure we speak about the same term Density
let's clarify that I mean the amount of data in the data page (each page size is 8kb so the amount of the space which is used)
The following query can help you to determine average page density for indexes (including the CLUSTERED index which is the table itself)
SELECT OBJECT_SCHEMA_NAME(ips.object_id) AS schema_name,
OBJECT_NAME(ips.object_id) AS object_name,
i.name AS index_name,
i.type_desc AS index_type,
ips.avg_page_space_used_in_percent,
ips.avg_fragmentation_in_percent,
ips.page_count,
ips.alloc_unit_type_desc,
ips.ghost_record_count
FROM sys.dm_db_index_physical_stats(DB_ID(), default, default, default, 'SAMPLED') AS ips
INNER JOIN sys.indexes AS i
ON ips.object_id = i.object_id
AND
ips.index_id = i.index_id
ORDER BY page_count DESC;
GO
Note: The FILLFACTOR of the index is the percentage value to fill data in the data page, so this directly related to the Page density.
Is hi Page density is good or bad?
Depend.
High page density means you read lass pages to get all the data, but at the same time it might result for example with page split when you INSERT/UPDATE data. So if your data in the table does not change, then why do you need free space but if you change the data a lot then you might prefer lower density.
shrink will complete faster if page density is high for example (lass pages to move), so many times before shrink we will prefer to increase page density before shrinking data files. SELECT will be faster for High page density but UPDATE/INSERT might be slower.
You need to balance according to your way of using the data.
More fragameted index (>50%) the avg_page_space_used_in_percent is from 50%-60% But Less fragmentationed index (less than 30%) the avg_page_space_used_in_percent is from 95%-60%
Microsoft documentation recommends to have 60-70% or more and consider rebuilding or reorganizing if it is less.
Obviously it is a golden rule and not something you must follow. You should be familiar in the way you use the data and do your own decision accordingly.