2012-11-07 118 views
0

我有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 

的問題是,當我執行下面的查詢,我認爲它確實Clusterd索引掃描[PK_archived_events]

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

執行計劃見的原因是什麼,非聚集索引被忽略?

另外一個注意,這是SQL Azure,不知道它是否重要。

+0

表中有多少行?多少匹配'30 = ae。[account_id]'? –

+0

@MartinSmith 400萬行... – user1662812

+0

@MartinSmith 717536匹配30 = ae。[account_id] – user1662812

回答

0

表中有nvarchar(max)列會干擾索引。我已經將它們轉換爲nvarchar(n),並且索引現在可以工作。