Bug #61310 ALTER TABLE DROP FOREIGN KEY copies table before testing if the fk exists

Submitted: 26 May 2011 14:18 Modified: 27 May 2011 7:49
Reporter: Cyril SCETBON Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: DDL Severity:S3 (Non-critical)
Version:5.5.9 OS:Any
Assigned to: CPU Architecture:Any
Tags: foreign key

[26 May 2011 14:18] Cyril SCETBON
Description:
trying to drop foreign key that does not exist throw an exception after having copied the table. It can be very long on a big table

How to repeat:
create table f(id int primary key);
insert into f values(1),(2),(3);
create table c(id int,c varchar(40000),key (id), foreign key (id) references f(id) on update cascade);
insert into c values(1,repeat('C',39900));
insert into c select * from c;
insert into c select * from c;
insert into c select * from c;
insert into c select * from c;
insert into c select * from c;
insert into c select * from c;
insert into c select * from c;
insert into c select * from c;
insert into c select * from c;
insert into c select * from c;
insert into c select * from c;
insert into c select * from c;
insert into c select * from c;

ALTER TABLE c DROP FOREIGN KEY nothing;
ERROR 1025 (HY000): Error on rename of './jrep_data_tst/c' to './jrep_data_tst/#sql2-1ae8-d' (errno: 152)

if I do a show processlist during the ALTER TABLE I see

mysql> show processlist\G
*************************** 1. row ***************************
     Id: 13
   User: root
   Host: localhost
     db: jrep_data_tst
Command: Query
   Time: 25
  State: copy to tmp table
   Info: ALTER TABLE c DROP FOREIGN KEY nothing

Suggested fix:
check if the foreign key exists before copying the table
[26 May 2011 17:30] Valeriy Kravchuk
This is a duplicate of Bug #50384 (that ended up as a duplicate of bug #46281).
[27 May 2011 7:49] Cyril SCETBON
it comes from a DDL statement although it concerns only InnoDB

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.053 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.