200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > MySQL 5.6为什么关闭元数据统计信息自动更新统计信息收集源代码探索

MySQL 5.6为什么关闭元数据统计信息自动更新统计信息收集源代码探索

时间:2021-11-30 06:11:38

相关推荐

MySQL 5.6为什么关闭元数据统计信息自动更新统计信息收集源代码探索

数据库|mysql教程

MySQL 5.6,MySQL 5.6为什么关闭元数据统计信

数据库-mysql教程

社交娱乐源码,vscode保存自动缩进,ubuntu时间显示,tomcat线上重启,sqlite随机数方法,a5担保系统插件,前端不会框架也能找工作吗,爬虫网盘高途课堂,php http 正则,seo营销代理运营,仙女屋最新网站,jsp设计有道词典网页界面,微信专题页模板lzw

MySQL 5.6为什么关闭元数据统计信息自动更新统计信息收集源代码探索

流量卡查询源码,ubuntu 无法识别磁盘,养爬虫的好处,php 调用hprose,揭阳seo计费lzw

淘宝 装修 源码,vscode怎么添加快捷模块,ubuntu安装什么,tomcat默认并发参数,chrome网络爬虫,php获取目录下文件名,seo新手培训教程手游推广lzw

问题描述:

MySQL 5.5.15 原sql如下:

select constraint_schema,table_name,constraint_name,constraint_type from information_schema.table_constraints where table_schema not in (‘information_schema’, ‘mysql’, ‘test’,‘performance_schema’);

不只是上面提到的table_constraints,information_schema库下的一下几个表,访问时候都会触发这个“顺手”操作。

information_schema.TABLES

information_schema.STATISTICS

information_schema.PARTITIONS

information_schema.KEY_COLUMN_USAGE

information_schema.TABLE_CONSTRAINTS

information_schema.REFERENTIAL_CONSTRAINTS

show table status . .

show index from …

当innodb_stats_on_metadata=on 都会触发自动更新统计信息。

问题:

5.6 开始默认innodb_stats_on_metadata=off,why??? 答:为了防止自动更新统计信息在DB高峰时导致BP的swap;查询性能大幅度抖动。

没有定期更新统计信息了么??答:有啊,而且可以是持久化的。

我看到的MySQL 5.5.15 这个版本还是条件是====>

counter > 2000000000 || ((ib_int64_t)counter > 16 + table->stat_n_rows / 16)

下面做了对MySQL 收集统计信息做了扩展:

一.下面我们来看下对MySQL 5.5.36 的源代码的分析:

—————————————————————————

#通过更新统计信息stat_modified_counter,每个表都有这个表里来维护:

./storage/innobase/row/row0mysql.c

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

/*********************************************************************//**

Updates the table modification counter and calculates new estimates

for table and index statistics if necessary. */

UNIV_INLINE

void

row_update_statistics_if_needed(

/*============================*/

dict_table_t* table) /*!< in: table */

{

ulint counter;

counter = table->stat_modified_counter;

table->stat_modified_counter = counter + 1;

if (DICT_TABLE_CHANGED_TOO_MUCH(table)) {

dict_update_statistics(

table,

FALSE, /* update even if stats are initialized */

TRUE /* only update if stats changed too much */);

}

}

/*********************************************************************/

规则:每一次DML操作导致1 行更新,stat_modified_counter加1,直到满足更新统计信息的条件,stat_modified_counter的值自动重置为0。

* 这样有个性能问题,若有多个线程同时检测到阈值,也即是并发调用会多次,,会导致dict_update_statistics函数多次的调用,浪费了系统资源。

解决方法:在dict_update_statistics{}函数对stat_modified_counter加锁,避免并发执行。

#统计新跟更新函数:dict_update_statistics

./storage/innobase/dict/dict0dict.c

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

/*********************************************************************//**

Calculates new estimates for table and index statistics. The statistics

are used in query optimization. */

UNIV_INTERN

void

dict_update_statistics(

/*===================*/

dict_table_t* table,/*!< in/out: table */

ibool only_calc_if_missing_stats,/*!< in: only

update/recalc the stats if they have

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。