Description:
mysql first does the alter table, then throws the error about foreign key violations. some time could be saved for huge tables if the error occurred immediately, instead of after the data is copied.
in the 'how to repeat', if the parent table is many gigabytes in size, it would be great to see the error immediately, instead of after wasted minutes or hours.
How to repeat:
drop table if exists child,parent;
create table parent (id int not null,primary key (id)) engine=innodb;
set @a=1;
insert into parent values (0);
insert into parent select @a:=@a+1 from parent;
insert into parent select @a:=@a+1 from parent;
insert into parent select @a:=@a+1 from parent;
insert into parent select @a:=@a+1 from parent;
insert into parent select @a:=@a+1 from parent;
insert into parent select @a:=@a+1 from parent;
insert into parent select @a:=@a+1 from parent;
insert into parent select @a:=@a+1 from parent;
insert into parent select @a:=@a+1 from parent;
insert into parent select @a:=@a+1 from parent;
insert into parent select @a:=@a+1 from parent;
insert into parent select @a:=@a+1 from parent;
insert into parent select @a:=@a+1 from parent;
insert into parent select @a:=@a+1 from parent;
insert into parent select @a:=@a+1 from parent;
insert into parent select @a:=@a+1 from parent;
insert into parent select @a:=@a+1 from parent;
insert into parent select @a:=@a+1 from parent;
insert into parent select @a:=@a+1 from parent;
insert into parent select @a:=@a+1 from parent;
insert into parent select @a:=@a+1 from parent;
create table child (id int, parent_id int,index par_ind
(parent_id),foreign key (parent_id)
references parent(id) on delete cascade) engine=innodb;
alter table parent drop primary key;
#the feature request is the ALTER TABLE should give an error immediately.