非聚集索引被忽略

时间:2012-11-07 10:38:47

标签: sql-server azure-sql-database

我有archived_events表,其中包含以下索引。

    CREATE NONCLUSTERED INDEX [IX_archived_events_5] ON [dbo].[archived_events]
    (
        [account_id] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
    GO

ALTER TABLE [dbo].[archived_events] ADD  CONSTRAINT [PK_archived_events] PRIMARY KEY CLUSTERED 
(
    [event_type] DESC,
    [id] DESC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
GO

问题在于,当我执行以下查询时,我在执行计划中看到它在[PK_archived_events]上进行了群集索引扫描

SELECT *                                  
FROM   archived_events ae WITH(nolock) 
WHERE     ( 30 = ae.[account_id] ) 

忽略非聚集索引的原因是什么?

还注意到这是SQL Azure,不确定它是否重要。

1 个答案:

答案 0 :(得分:0)

该表具有干扰索引的nvarchar(max)列。我已将它们转换为nvarchar(n),索引现在可以正常工作。