Bug #87170 altering tables with many partitions is slower than expected
Submitted: 23 Jul 2017 11:40
Reporter: Shane Bester (Platinum Quality Contributor) Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: Partitions Severity:S5 (Performance)
Version:5.6.37, 5.7.19 OS:Any
Assigned to: CPU Architecture:Any

[23 Jul 2017 11:40] Shane Bester
Description:
We're typically seeing a 3x - 5x slower DDL operation on table with many partitions. See testcase output on my 5.7.19 :

table t - 600 partitions
table r - 300 partitions
table s - not partitioned

mysql> alter table t add column c int, algorithm=inplace, lock=none;
Query OK, 0 rows affected (42.16 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> alter table r add column c int, algorithm=inplace, lock=none;
Query OK, 0 rows affected (37.01 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> alter table s add column c int, algorithm=inplace, lock=none;
Query OK, 0 rows affected (7.67 sec)
Records: 0  Duplicates: 0  Warnings: 0

How to repeat:
#Compare the last three statements timings.

-- --------

drop table if exists t,r,s;
create table t(a int not null auto_increment primary key, b int)engine=innodb partition by key(a) partitions 600;
create table r(a int not null auto_increment primary key, b int)engine=innodb partition by key(a) partitions 300;
create table s(a int not null auto_increment primary key, b int)engine=innodb ;

set @a:=1000000;
insert into t(b) values(floor(rand()*@a)),(floor(rand()*@a)),(floor(rand()*@a));
insert into t(b) values(floor(rand()*@a)),(floor(rand()*@a)),(floor(rand()*@a));
insert into t(b) select floor(rand()*@a) from t,t a,t b,t c,t d,t e,t f,t g;

insert into r(b) select b from t;
insert into s(b) select b from t;

analyze table t;
analyze table r;
analyze table s;

flush tables;
do sleep(10);

alter table t add column c int, algorithm=inplace, lock=none;
alter table r add column c int, algorithm=inplace, lock=none;
alter table s add column c int, algorithm=inplace, lock=none;

-- --------

Suggested fix:
Persistent stats and fsyncs incurred would attribute to some overhead.
So I do expect some overhead with many partitions, but not 400% !!
[23 Jul 2017 12:16] MySQL Verification Team
this is nothing specific to 5.7.  5.6 has same problems...
[8 Feb 2019 14:12] Jeremy Tinley
Looks like a duplicate of https://bugs.mysql.com/bug.php?id=83435.