Hi Everybody,
We have a heap table 142 records in it. There are no non-clustered indexes on this heap. Oddly, I'm getting two rows returned from sys.dm_db_index_physical_stats, and each row reports the Index_type_desc as "HEAP". How can that be? Here's my query:
SELECT
object_name(IPS.[object_id]) AS [TableName]
, *
FROM sys.dm_db_index_physical_stats(
DB_ID(DB_NAME()) --database ID
, OBJECT_ID(@mytable) --table ID
, NULL --index ID
, NULL --partition number
, @Mode --mode
) IPS
JOIN sys.tables ST WITH (NOLOCK) ON IPS.[object_id] = ST.[object_id]
JOIN sys.indexes SI WITH (NOLOCK) ON IPS.[object_id] = SI.[object_id] AND IPS.index_id = SI.index_id
WHERE ST.is_ms_shipped = 0
ORDER BY
OBJECT_NAME(IPS.[object_id])
, SI.index_id
, ips.index_level
And here's my results:
- Row 1: HEAP, page_count = 3, fragment_count = 2, record_count = 142, avg_fragment_size_in_pages = 1.5, avg_fragmentation_in_percent = 50, avg_page_space_used = 52.153%
- Row 2: HEAP, page_count = 5, fragment_count = NULL, record_count = 284, avg_fragment_size_in_pages = NULL, avg_fragmentation_in_percent = 0, avg_page_space_used = 60.331%
I notice the similarity between record_count values (though I don't understand the significance): 142 doubled is 284.
I assume this issue can be remedied by creating a new table, inserting the 142 records from the table in question, dropping the table in question, then renaming the new table, but I'd really like to understand what's going on here, and I'd like to get an idea of how this happened for future reference. An internet search has turned up nothing.
Thanks,
Eric