我应该在索引中包含 select 中的所有列吗?

Should I include all of my columns from the select in my index?

我有一个查询需要一点时间 运行 它看起来像这样。

Select a.ColumnA,a.ColumnB,a.ColumnC,a.CoulmnD,a.columnE,...b.ColumnH
from Table A a
  inner join Table B b
       on a.columnB = b.ColumnB
  Where a.columnA = @VariableA

现在它在 Table A 上有一个像这样的聚集索引

Clustered Index on ColumnA

它在 Table A 上也有一个像这样的非聚集索引

NonClustered Index on (ColumnA,ColumnB) include (ColumnC,ColumnD)

我是否也应该将 ColumnsE-G 添加到索引中?

Verify the data type of compared columns and parameters are the same when you see an index scan instead of the expected seek in the execution plan.

当数据类型不同时,SQL 服务器必须首先将优先级较低的操作数转换为优先级较高的数据类型(例如 varcharnvarchar)。当必须转换的是列值时,转换会阻止列上的索引得到有效使用,因为必须先转换每一行的列值才能进行比较。这被称为 non-sargable 表达式并且 阻止更有效的索引搜索 .