暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

MySQL并行(在线DDL)来了!

原创 闫建 云和恩墨 2021-12-09
1342

从 MySQL 8.0.27 版本开始,引入了两个新参数:innodb_ddl_buffer_size  和 innodb_ddl_threads

innodb_ddl_buffer_size(默认1MB,最大4GB,可在线修改):Defines the maximum buffer size for DDL operations. The default setting is 1048576 bytes (approximately 1 MB). Applies to online DDL operations that create or rebuild secondary indexes.

innodb_ddl_threads(默认4,最大64,可在线修改):Defines the maximum number of parallel threads for the sort and build phases of index creation. Applies to online DDL operations that create or rebuild secondary indexes.

    如果我们资源充足:内存够用,CPU核数够用,磁盘都有足够的容量且速度很快,我们可以通过参数设置来加快我们创建索引或者重建索引的速度。

    MySQL 8.0.27缺省设置情况下:

mysql > alter table product add index idx_prod_pid_pcode_c_id (product_id, product_code, customer_id);
Query OK, 0 rows affected (8 min 0.5371 sec)
复制

    调整innodb_ddl_buffer_size:

mysql > SET innodb_ddl_buffer_size = 1048576000;mysql >  alter table product add index idx_prod_pid_pcode_c_id (product_id, product_code, customer_id);
Query OK, 0 rows affected (2 min 47.1231 sec)
复制

    执行时间大大减少,加速索引创建过程。

    具体详细情况请参考官方文档:

https://dev.mysql.com/doc/refman/8.0/en/online-ddl-memory-management.html

https://dev.mysql.com/doc/refman/8.0/en/online-ddl-parallel-thread-configuration.html

最后修改时间:2022-07-13 11:44:32
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论