文档首页
MySQL 8.4 参考手册
8.4 中文镜像

MySQL 8.4 参考手册 · 中文镜像

正文为中文,英文原文默认隐藏。点击任意中文段落即可展开 / 收起对应英文原文。

打开官方英文原文 ↗

译文由机器翻译生成,仅供理解参考;有疑问请以官方英文原文为准。

MySQL 8.4 参考手册 / 17 InnoDB 存储引擎 / 17.8 InnoDB 配置 / 17.8.10 配置 InnoDB 优化器统计信息
中文点击中文段落可显示 / 隐藏英文原文本页译文覆盖 100%

17.8.10 配置 InnoDB 的优化器统计信息17.8.10 Configuring Optimizer Statistics for InnoDB

本节描述了如何为 InnoDB 表配置持久化和非持久化优化器统计信息。This section describes how to configure persistent and non-persistent optimizer statistics for InnoDB tables.

持久化优化器统计信息在服务器重启后仍然保留,从而实现更高的 计划稳定性 和更一致的查询性能。持久化优化器统计信息还提供控制和灵活性,并具有以下额外好处:Persistent optimizer statistics are persisted across server restarts, allowing for greater plan stability and more consistent query performance. Persistent optimizer statistics also provide control and flexibility with these additional benefits:

  • 您可以使用 innodb_stats_auto_recalc 配置选项来控制在表发生重大更改后是否自动更新统计信息。You can use the innodb_stats_auto_recalc configuration option to control whether statistics are updated automatically after substantial changes to a table.

  • 您可以在 CREATE TABLE 和 ALTER TABLE 语句中使用 STATS_PERSISTENT、STATS_AUTO_RECALC 和 STATS_SAMPLE_PAGES 子句来为单个表配置优化器统计信息。You can use the STATS_PERSISTENT, STATS_AUTO_RECALC, and STATS_SAMPLE_PAGES clauses with CREATE TABLE and ALTER TABLE statements to configure optimizer statistics for individual tables.

  • 您可以查询 mysql.innodb_table_stats 和 mysql.innodb_index_stats 表中的优化器统计数据。You can query optimizer statistics data in the mysql.innodb_table_stats and mysql.innodb_index_stats tables.

  • 您可以查看 mysql.innodb_table_stats 和 mysql.innodb_index_stats 表的 last_update 列,以了解统计信息的最后更新时间。You can view the last_update column of the mysql.innodb_table_stats and mysql.innodb_index_stats tables to see when statistics were last updated.

  • 您可以手动修改 mysql.innodb_table_stats 和 mysql.innodb_index_stats 表,以强制使用特定的查询优化方案或在不修改数据库的情况下测试替代方案。You can manually modify the mysql.innodb_table_stats and mysql.innodb_index_stats tables to force a specific query optimization plan or to test alternative plans without modifying the database.

持久优化器统计信息功能默认启用 (innodb_stats_persistent=ON)。The persistent optimizer statistics feature is enabled by default (innodb_stats_persistent=ON).

非持久化优化器统计信息在每次服务器重启以及某些其他操作后会被清除,并在下一次表访问时重新计算。因此,在重新计算统计信息时可能会产生不同的估计值,从而导致执行计划的选择不同,并引起查询性能的变化。Non-persistent optimizer statistics are cleared on each server restart and after some other operations, and recomputed on the next table access. As a result, different estimates could be produced when recomputing statistics, leading to different choices in execution plans and variations in query performance.

本节还提供了估算ANALYZE TABLE复杂性的信息,这在尝试在准确统计信息与ANALYZE TABLE执行时间之间取得平衡时可能有所帮助。This section also provides information about estimating ANALYZE TABLE complexity, which may be useful when attempting to achieve a balance between accurate statistics and ANALYZE TABLE execution time.