I was checking the fragmentation in the index in one table of my DB with the following query
SELECT a.object_id, object_name(a.object_id) AS TableName,
a.index_id, name AS IndedxName, avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats
(DB_ID (N'prod-db')
, OBJECT_ID(N'[dbo].[Channel]')
, NULL
, NULL
, NULL) AS a
INNER JOIN sys.indexes AS b
ON a.object_id = b.object_id
AND a.index_id = b.index_id;
GO
And discovered that it listed PK_Channel
3 times,
TableName | index_id | IndedxName | object_id | avg_fragmentation_in_percent |
---|---|---|---|---|
Channel | 1 | PK_Channel | 1557580587 | 0,01 |
Channel | 1 | PK_Channel | 1557580587 | 0 |
Channel | 1 | PK_Channel | 1557580587 | 0 |
Channel | 3 | idx_Channel_RegisteredTime | 1557580587 | 0,0429737859905458 |
I have rebuilt the index 2 times, so it coincides with that. But is this a good thing? Or is this normal (aka expected behaviour)? Should I "fix" this? if so, how?
It is worth noting that the index idx_Channel_RegisteredTime
was rebuilt once and no duplication was found in sys.dm_db_index_physical_stats
. Can anyone shed light on this?
Also please notice that when I list the indexes in the Management Studio it only shows PK_Channel
once, which is what I would expect.
In case it makes any difference or any one is curious, I rebuilt the indexes using the following statement
ALTER INDEX PK_Channel ON [dbo].[Channel]
REBUILD
;
ALTER INDEX idx_Channel_RegisteredTime ON [dbo].[Channel]
REBUILD
;
Thanks
You only have one index, with multiple levels in the B-tree.
From the docs for sys.dm_db_index_physical_stats
:
For an index, one row is returned for each level of the B-tree in each partition.
This means that dm_db_index_physical_stats
will return a row for each level of the B-tree. You are joining that onto the single row from sys.indexes
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.