我正在尝试调查每个索引的页数,并制定了以下查询:
SELECT
pyi.index_type_desc as [index type],
i.name as [index name],
sum(pyi.page_count) as [number of pages]
FROM
sys.dm_db_index_physical_stats(DB_ID('testdb'),OBJECT_ID('surrogatekeys'),NULL,NULL,'DETAILED') as pyi
INNER JOIN
sys.indexes as i ON pyi.object_id = i.object_id
GROUP BY
i.name, pyi.index_type_desc
当我运行此查询时,我得到以下结果:
CLUSTERED INDEX PK_TableWithSurrogateKeyAndUniqueContraints 14342
CLUSTERED INDEX UNIQUE_TableWithSurrogateKeyAndUniqueContraints 14342
NONCLUSTERED INDEX PK_TableWithSurrogateKeyAndUniqueContraints 707
NONCLUSTERED INDEX UNIQUE_TableWithSurrogateKeyAndUniqueContraints 707
该表的创建如下:
CREATE TABLE [dbo].[SurrogateKeys]
(
[Id] [int] IDENTITY(1,1) NOT NULL,
[TimeStamp] [datetime2](7) NOT NULL,
[Username] [nvarchar](20) NOT NULL,
[Message] [nvarchar](500) NULL,
CONSTRAINT [PK_TableWithSurrogateKeyAndUniqueContraints]
PRIMARY KEY CLUSTERED ([Id]),
CONSTRAINT [UNIQUE_TableWithSurrogateKeyAndUniqueContraints]
UNIQUE ([Username], [TimeStamp]),
) ON [PRIMARY]
GO
并填充了 100,000 行随机数据。
我希望看到两个条目:唯一约束的非聚集索引和主键列的聚集索引。
这些重复输入是什么意思?