当前位置: 首页 > news >正文

学习笔记:MySQL:Innodb统计信息参数

我们的文章会在微信公众号IT民工的龙马人生和博客网站( www.htz.pw )同步更新 ,欢迎关注收藏,也欢迎大家转载,但是请在文章开始地方标注文章出处,谢谢!
由于博客中有大量代码,通过页面浏览效果更佳。

本文转自朋友的真实案例分享。

MySQL学习笔记:Innodb统计信息参数

几乎所有的关系型数据库都是基于成本的优化器,其中成本的计算都依赖于统计信息。所以优化器能否选择正确的执行计划,统计信息至关重要。

在innodb里,统计信息的相关参数如下:

mysql> show variables like '%innodb_stat%';
+--------------------------------------+-------------+
| Variable_name                        | Value       |
+--------------------------------------+-------------+
| innodb_stats_auto_recalc             | ON          |
| innodb_stats_include_delete_marked   | OFF         |
| innodb_stats_method                  | nulls_equal |
| innodb_stats_on_metadata             | OFF         |
| innodb_stats_persistent              | ON          |
| innodb_stats_persistent_sample_pages | 20          |
| innodb_stats_transient_sample_pages  | 8           |
| innodb_status_output                 | OFF         |
| innodb_status_output_locks           | OFF         |
+--------------------------------------+-------------+

innodb_stats_persistent:控制统计信息是否持久化,默认为ON,持久化统计信息将记录在mysql.innodb_table_stats、mysql.innodb_index_stats中。
innodb_stats_auto_recalc:默认为ON,控制当持久化统计信息打开时,10%比例的数据变更,将自动触发统计信息的收集。也可以通过表属性STATS_AUTO_RECALC单独对表定制比例。如果设置为OFF将禁用该功能。

The innodb_stats_auto_recalc variable, which is enabled by default, controls whether statistics are calculated automatically when a table undergoes changes to more than 10% of its rows. You can also configure automatic statistics recalculation for individual tables by specifying the STATS_AUTO_RECALC clause when creating or altering a table.Because of the asynchronous nature of automatic statistics recalculation, which occurs in the background, statistics may not be recalculated instantly after running a DML operation that affects more than 10% of a table, even when innodb_stats_auto_recalc is enabled. Statistics recalculation can be delayed by few seconds in some cases. If up-to-date statistics are required immediately, run ANALYZE TABLE to initiate a synchronous (foreground) recalculation of statistics.If innodb_stats_auto_recalc is disabled, you can ensure the accuracy of optimizer statistics by executing the ANALYZE TABLE statement after making substantial changes to indexed columns. You might also consider adding ANALYZE TABLE to setup scripts that you run after loading data, and running ANALYZE TABLE on a schedule at times of low activity.When an index is added to an existing table, or when a column is added or dropped, index statistics are calculated and added to the innodb_index_stats table regardless of the value of innodb_stats_auto_recalc.

innodb_stats_method:控制在收集统计信息时,对于null之间的比较如何处理,默认为nulls_equal,含义是认为null之间相等。
innodb_stats_include_delete_marked:控制未提交事务的情况下,收集统计信息时,被删除的行是否计算在内。默认为OFF。
innodb_stats_persistent_sample_pages:控制收集持久统计信息时的默认采样page数。
innodb_stats_transient_sample_pages:控制收集非持久化统计信息时的默认采样page数。
innodb_stats_on_metadata:默认为OFF,当该参数启用时,SHOW TABLE STATUS, SHOW INDEX, 或者查询Information Schema TABLES or STATISTICS等表时,会触发非持久化统计信息收集。

------------------作者介绍-----------------------
姓名:黄廷忠
现就职:Oracle中国高级服务团队
曾就职:OceanBase、云和恩墨、东方龙马等
电话、微信、QQ:18081072613
个人博客: (http://www.htz.pw)
CSDN地址: (https://blog.csdn.net/wwwhtzpw)
博客园地址: (https://www.cnblogs.com/www-htz-pw)

http://www.vanclimg.com/news/425.html

相关文章:

  • 库卡气体保护焊机器人省气的方法
  • 物联网技术对于农业的运营都起到了哪些作用
  • [07.28学习笔记] Self-attetion Cross-attetion - Luna
  • 【LLM】Transformer各模块PyTorch简单实现Demo
  • 如何在FastAPI中玩转Schema版本管理和灰度发布?
  • C++ Qt开发QUdpSocket网络通信组件
  • fhq-treap学习笔记
  • 7/28
  • Bruce Momjian 深圳 meetup 回顾
  • 贪心
  • sqlite3 本地数据库可视化工具
  • [题解] P5743 【深基7.习8】猴子吃桃
  • gds 格式文档
  • 微服务学习-02-微服务技术栈整理
  • JUC线程池: ScheduledThreadPoolExecutor详解
  • [题解] P5735 【深基7.例1】距离函数
  • uv命令怎么安装并且让gitlab-runner用户可以执行
  • NRF54L15 TAMPC — Tamper controller 作用介绍
  • 线上故障的排查清单,运维小哥拿走不谢!
  • NRF54L15 AAR作用介绍
  • NRF54L15 CCM功能
  • 恭贺开源之夏 2025 IvorySQL 项目中选学生
  • 自用学习笔记:机器学习入门 速览【第三章】
  • 浅谈MCU的启动
  • KMU — Key management unit 作用
  • NRF54L15 GRTC 优点;
  • MS14-019漏洞修复:通过.cmd或.bat文件实现二进制劫持的解决方案
  • 浅谈北京市海淀区七年级下册期末数学试卷T16第二小问
  • 利用Amazon Bedrock生成AI增强设备维护建议
  • SAP为何将S/4HANA更名为SAP Cloud ERP?