MySQL 8.0 - 正如MySQL 官方文档和MySQL 服务器团队中所述,Alter table with Algorithm=INSTANT 会立即添加列,而不需要任何锁定。
但是,结果不同了。
测试设置- 具有 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,""
Run Code Online (Sandbox Code Playgroud)
基础设施: AWS RDS MySQL 8 - 引擎版本 - 8.0.17
测试用例: 向表中添加新列。
陈述:
alter table table_name add column_name int, algorithm=instant;
Run Code Online (Sandbox Code Playgroud)
结果:
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
Run Code Online (Sandbox Code Playgroud)
花了大约 40 秒。它在40 秒内阻止了读取和写入
这是预期的吗?我有什么遗漏的吗?