14.6.12.2 Configuring Non-Persistent Optimizer Sta

This section describes how to configure non-persistent optimizer statistics. Optimizer statistics are not persisted to disk when innodb_stats_persistent=OFF or when individual tables are created or altered with STATS_PERSISTENT=0. Instead, statistics are stored in memory, and are lost when the server is shut down. Statistics are also updated periodically by certain operations and under certain conditions.
本節描述如何配置非持久性優化器統計信息。當innodb_stats_persistent=OFF或使用STATS_PERSISTENT=0創建或更改單個表時,優化器統計信息不會持久化到磁盤。相反,統計信息存儲在內存中,在服務器關閉時丟失。統計數字也由某些業務和在某些條件下定期更新。
As of MySQL 5.6.6, optimizer statistics are persisted to disk by default, enabled by the innodb_stats_persistent configuration option. For information about persistent optimizer statistics, see Section 14.6.12.1, “Configuring Persistent Optimizer Statistics Parameters”.
從MySQL 5.6.6開始,默認情況下優化器統計信息會持久保存到磁盤,並由innodb_stats_persistent配置選項啓用。有關持久優化器統計信息的信息。更多信息請看Section 14.6.12.1, “Configuring Persistent Optimizer Statistics Parameters”.

Optimizer Statistics Updates
優化器數據更新
Non-persistent optimizer statistics are updated when:
非持久優化器統計信息在以下情況下更新:

  • Running ANALYZE TABLE.
  • 執行ANALYZE TABLE.
  • Running SHOW TABLE STATUS, SHOW INDEX, or querying the INFORMATION_SCHEMA.TABLES orINFORMATION_SCHEMA.STATISTICS tables with the innodb_stats_on_metadata option enabled.
    The default setting for innodb_stats_on_metadata was changed to OFF when persistent optimizer statistics were enabled by default in MySQL 5.6.6. Enabling innodb_stats_on_metadata may reduce access speed for schemas that have a large number of tables or indexes, and reduce stability of execution plans for queries that involve InnoD tables. innodb_stats_on_metadata is configured globally using a SET statement.
  • 運行SHOW TABLE STATUS,SHOW INDEX或在啓用innodb_stats_on_metadata選項的情況下查詢INFORMATION_SCHEMA.TABLES 或者INFORMATION_SCHEMA.STATISTICS表。當MySQL 5.6.6中默認啓用持久性優化器統計信息時,innodb_stats_on_metadata的默認設置已更改爲OFF.啓用innodb_stats_on_metadata可能會降低具有大量表或索引的模式的訪問速度,並降低涉及InnoDBtables的查詢的執行計劃的穩定性.innodb_stats_on_metadata使用SET語句進行全局配置。
    SET GLOBAL innodb_stats_on_metadata=ON
    Note
    • innodb_stats_on_metadata only applies when optimizer statistics are configured to be non-persistent (wheninnodb_stats_persistent is disabled).
    • innodb_stats_on_metadata僅適用於將優化器統計信息配置爲非持久性(禁用innodb_stats_persistent時)。
  • Starting a mysql client with the --auto-rehash option enabled, which is the default. The auto-rehash option causes all InnoDB tables to be opened, and the open table operations cause statistics to be recalculated.
    To improve the start up time of the mysql client and to updating statistics, you can turn off auto-rehash using the --disable-auto-rehash option. The auto-rehash feature enables automatic name completion of database, table, and column names for interactive users.
  • 使用--auto-rehash選項啓用mysql客戶端.這是默認的。 auto-rehash選項會導致所有InnoDB表打開,並且打開的表操作會導致重新計算統計信息。
  • 爲了改善mysql客戶端的啓動時間和更新統計信息,可以使用--disable-auto-rehash選項關閉 auto-rehash 。auto-rehash特性允許交互式用戶自動完成數據庫、表和列的名稱。
  • A table is first opened.
  • 表第一次打開
  • InnoDB detects that 1 / 16 of table has been modified since the last time statistics were updated.
  • InnoDB檢測自上次更新統計數據以來,表的1/16已被修改。

Configuring the Number of Sampled Pages
配置採樣頁面的數量

The MySQL query optimizer uses estimated statistics about key distributions to choose the indexes for an execution plan, based on the relative selectivity of the index. When InnoDB updates optimizer statistics, it samples random pages from each index on a table to estimate the cardinality of the index. (This technique is known as random dives.)
MySQL查詢優化器根據索引的相對選擇性,使用關於鍵分佈的估計統計信息爲執行計劃選擇索引。當InnoDB更新優化器統計信息時,它會從表中的每個索引中抽取隨機頁面來估計索引的基數。 (這種技術被稱爲random dives.。)
To give you control over the quality of the statistics estimate (and thus better information for the query optimizer), you can change the number of sampled pages using the parameter innodb_stats_transient_sample_pages. The default number of sampled pages is 8, which could be insufficient to produce an accurate estimate, leading to poor index choices by the query optimizer. This technique is especially important for large tables and tables used in joins. Unnecessary full table scans for such tables can be a substantial performance issue. See Section 8.2.1.19, “Avoiding Full Table Scans” for tips on tuning such queries. innodb_stats_transient_sample_pages is a global parameter that can be set at runtime.
爲了使您能夠控制統計估計的質量(從而爲查詢優化器提供更好的信息),可以使用參數innodb_stats_transient_sample_pages更改抽樣頁面的數量。抽樣頁面的默認數量是8,這可能不足以生成準確的估計,從而導致查詢優化器的索引選擇不佳。這種技術對於連接中使用的大型表和表尤其重要。對此類表進行不必要的全表掃描可能是一個嚴重的性能問題。請參閱 Section 8.2.1.19, “Avoiding Full Table Scans” ,瞭解調優此類查詢的技巧。innodb_stats_transient_sample_pages是一個全局參數,可以在運行時設置。
The value of innodb_stats_transient_sample_pages affects the index sampling for all InnoDB tables and indexes wheninnodb_stats_persistent=0. Be aware of the following potentially significant impacts when you change the index sample size:
當innodb_stats_persistent = 0時,innodb_stats_transient_sample_pages的值影響所有InnoDB表和索引的索引採樣。 當您更改索引樣本大小時,請注意以下潛在的重大影響:

  • Small values like 1 or 2 can result in inaccurate estimates of cardinality.
  • 像1或2這樣的小值可能會導致不準確的基數估計值。
  • Increasing the innodb_stats_transient_sample_pages value might require more disk reads. Values much larger than 8 (say, 100), can cause a significant slowdown in the time it takes to open a table or execute SHOW TABLE STATUS.
  • 增加innodb_stats_transient_sample_pages值可能需要更多的磁盤讀取。 大於8的值(比如100)會導致打開表或執行SHOW TABLE STATUS所花費的時間顯着減慢。
  • The optimizer might choose very different query plans based on different estimates of index selectivity.
  • 優化器可能會根據索引選擇性的不同估計值選擇截然不同的查詢計劃。

Whatever value of innodb_stats_transient_sample_pages works best for a system, set the option and leave it at that value. Choose a value that results in reasonably accurate estimates for all tables in your database without requiring excessive I/O. Because the statistics are automatically recalculated at various times other than on execution of ANALYZE TABLE, it does not make sense to increase the index sample size, run ANALYZE TABLE, then decrease sample size again.
無論innodb_stats_transient_sample_pages的值如何最適合系統,請設置該選項並將其保留爲該值。 選擇一個值,可以對數據庫中的所有表進行合理準確的估計,而無需過多的I / O。因爲除了執行ANALYZE TABLE之外,統計信息會在不同時間自動重新計算,所以增加索引樣本大小,運行ANALYZE TABLE,然後再次減小樣本大小沒有意義。
Smaller tables generally require fewer index samples than larger tables. If your database has many large tables, consider using a higher value for innodb_stats_transient_sample_pages than if you have mostly smaller tables.
較小的表通常需要比大表更少的索引樣本。如果您的數據庫有很多大的表,那麼可以考慮爲innodb_stats_transient_sample_pages使用一個更高的值。

PREV: 14.6.12.1 Configuring Persistent Optimizer Statistics Parameters https://blog.51cto.com/itzhoujun/2359334
NEXT: 14.6.12.3 Estimating ANALYZE TABLE Complexity for InnoDB Tables https://blog.51cto.com/itzhoujun/2359337

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章