一個聚集索引已經在兩個dw_assesment_details
和dw_assesment_details_id
表爲什麼這是一個索引掃描而不是一個索引查找
/* 6 minutes */
CREATE CLUSTERED INDEX [Ix_DW_ASSESSMENT_DETAILS_qid_QNO_TmpverName]
ON [dbo].[DW_ASSESSMENT_DETAILS_QUESTION_ID]
(
[TEMPLATENAME] ASC,
[TEMPLATEVERSION] ASC,
[QUESTION_NO] 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
/* 9 minutes */
CREATE CLUSTERED INDEX [Ix_DW_ASSESSMENT_DETAILS_QNO_TmpverName]
ON [dbo].[DW_ASSESSMENT_DETAILS]
(
[TEMPLATENAME] ASC,
[TEMPLATEVERSION] ASC,
[QUESTION_NO] 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)
SELECT
[GETQUESTIONID],
dw.[TEMPLATENAME], dw.[TEMPLATEVERSION],
dw.[QUESTION_NO]
FROM
[QIS_DW].[dbo].[DW_ASSESSMENT_DETAILS] dw
INNER JOIN
[QIS_DW].[dbo].[DW_ASSESSMENT_DETAILS_QUESTION_ID] id ON dw.TEMPLATENAME = id.TEMPLATENAME
AND dw.TEMPLATEVERSION = id.TEMPLATEVERSION
AND dw.QUESTION_NO = id.QUESTION_NO
但上面的選擇查詢使用索引掃描生成 - 沒有索引查找。如何使用索引查找呢?
任何性能調整專家的建議?
您正在讀取所有數據,並且這兩個表具有以相同順序顯示數據的索引。你**不要**索引尋求 – Caleth
你可能想閱讀[RBarry Young對此問題的回答](https://stackoverflow.com/questions/6528906/why-is-this-an-index-scan - 和 - 不一個索引,搜索) –