我有一个 SQL Server 没有使用的筛选的非聚集索引。我很确定优化器正在做正确的选择,但我想强制它使用该索引运行,以便我可以比较计划并了解为什么它更昂贵。
我已经从查询中删除了所有内容,我只是选择了正在过滤的列。
索引定义:
CREATE INDEX idx_all
ON tbl_test (CommentDateTime, name)
INCLUDE (comment, CommentByType)
WHERE CommentByType='INT';
Run Code Online (Sandbox Code Playgroud)
我试图运行的查询是:
SELECT CommentByType
FROM tbl_test WITH (INDEX (idx_all))
WHERE CommentByType='INT';
Run Code Online (Sandbox Code Playgroud)
并且 SQL Server 返回以下错误:
Query processor could not produce a query plan because of the hints defined in this query.
Resubmit the query without specifying any hints and without using SET FORCEPLAN.
Run Code Online (Sandbox Code Playgroud)
我已经阅读了很多关于被过滤的列被包含在键中或作为包含列的信息,但没有任何帮助。