首页 > 解决方案 > MySQL 8.0 Alter Table Algorithm=INSTANT 未按预期工作(需要 40 秒)

问题描述

MySQL 8.0 - 如MySQL Official DocMySQL Server Team中所述,Algorithm=INSTANT 的 Alter table 立即添加列而无需任何锁定。

但是,结果不一样。

测试设置- 具有 40M 行的表。在表上读取和写入 (1000 TPS)。表模式非常简单。

field,type,null,key,default,extra
id,bigint(20),NO,PRI,,auto_increment
t_a,bigint(20),NO,MUL,,""
t_b,bigint(20),NO,MUL,,""
t_c,int(11),NO,"",1,""

基础设施: AWS RDS MySQL 8 - 引擎版本 - 8.0.17

测试用例: 向表中添加新列。

陈述:

alter table table_name add column_name int, algorithm=instant;

结果:

mysql> alter table test_table add test_column int, algorithm=instant;
Query OK, 0 rows affected (36.06 sec)
Records: 0  Duplicates: 0  Warnings: 0

它花了〜40秒。它在 40 秒内阻止读取和写入

这是预期的吗?有什么我想念的吗?

标签: mysqlamazon-rdsinnodbddlalter

解决方案


推荐阅读