简体   繁体   中英

When to create statistics?

在SQL Server中,何时仅在表列而不是索引上创建统计信息,何时创建索引(也会自动创建统计信息)?

According to the documentation when the automatic create statistics option, AUTO_CREATE_STATISTICS is ON :

The query optimizer creates statistics on single columns in query predicates, as necessary, to improve query plans and query performance. These single-column statistics are created when the query optimizer compiles queries.

Hence you need to create statistics manually in the following cases at least:

  • AUTO_CREATE_STATISTICS is OFF
  • multi-column statistics is required
  • filtered statistics is required

Index and statistics are not comparable. In general, index is used to access data the more efficient way than a table scan. Statistics is required for optimizer to estimate the number of returned rows.

仅在向SQL引擎告知数据的分布/基数模式可以帮助其制定更好的执行计划时,统计信息才有用。在这种情况下,当告诉数据模式不足以及特殊的数据访问结构(即b树)时,特别需要使用索引需要减少数据扫描和滚动。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM