这是使用include中的所有列创建索引的不良做法吗?

Jac*_*ack 2 sql t-sql sql-server indexing sql-server-2008

我有一个表,我在字段上创建非聚集索引,这些索引经常用于搜索where子句.我正在使用include子句创建索引并将所有字段放在其中.

例如:

Create NonClustered Index IX_DocumentDate on Documents
(
    DocumentDate     
)
Include(
    JurisdictionID,
    JudgementTypeID,
    IDate,
    EfileDate,
    UserID,
    RecordingDateTime,
    ApprovedBy,
    ACEfileBankAccountID,
    LastStatusChangedDateTime,
    ACEfileCreditCardID,
    EfiledByUserID,
    ITypeID,
    IGroupID,
    InstrumentID,
    OldInstrumentID,
    [CreatedByJurisdictionID],
    CreatedByAccountID,
    [DocumentStatusID]      
      ,[Remarks]
      ,[InternalNotes]
      ,[ParentDocumentID]
      ,[FilingNumber]
      ,[StampData]      
      ,[Receipt]
      ,[ReceiptNo]
      ,[IsReEfiled]      
      ,[ImportedFromInstrumentID]
)
Run Code Online (Sandbox Code Playgroud)

与仅创建索引相反.这些字段全部用于Select.只是想知道我做错了吗?当我这样做时,我获得了巨大的性能奖励.如果这没关系,那么为什么Microsoft不将它用作默认选项并包含表的所有字段include

小智 5

是.通常,在SQL中,拥有一个模式总是很糟糕 - LOT取决于使用情况,而且会有所不同.

在上述情况下,这可能是也可能不是明智的或需要的或有益的.不要忘记付出代价 - 光盘大小(= IO和更多RAM使用率)以及更新和插入速度(更慢).

通常,应谨慎使用INCLUDE.从没有开始,然后在有问题的地方使用它,它会有所帮助.