Skip to content

Commit e8b9d8d

Browse files
committed
MDEV-25530 Error 1451 on slave: Cannot delete or update a parent row: a foreign key constraint fails
after dfb41fd tables that failed to drop are excluded from the binlogged DROP TABLE statement. It means that the slave should not expect any errors when executing DROP TABLE, and the binlog should report that no error has happened, even if it was. Do not write error code into the binlogged DROP TABLE, and remove all code that was needed to compute it.
1 parent 65e73b5 commit e8b9d8d

File tree

3 files changed

+36
-14
lines changed

3 files changed

+36
-14
lines changed

mysql-test/suite/rpl/r/rpl_foreign_key_innodb.result

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,21 @@ count(*)
5555
0
5656
connection master;
5757
drop table t2,t1;
58+
set foreign_key_checks=1;
59+
#
60+
# MDEV-25530 Error 1451 on slave: Cannot delete or update a parent row: a foreign key constraint fails
61+
#
62+
create table t1 (id int primary key)engine=innodb;
63+
create table t2 (id int not null primary key auto_increment,
64+
id2 int default null, key f1 (id2),
65+
constraint f1 foreign key (id2) references t1 (id) on delete cascade) engine=innodb;
66+
drop table t1,t2;
67+
ERROR 23000: Cannot delete or update a parent row: a foreign key constraint fails
68+
connection slave;
69+
show tables;
70+
Tables_in_test
71+
t1
72+
connection master;
73+
drop table t1;
74+
connection slave;
5875
include/rpl_end.inc

mysql-test/suite/rpl/t/rpl_foreign_key_innodb.test

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,22 @@ select count(*) from t1 /* must be zero */;
5757

5858
connection master;
5959
drop table t2,t1;
60+
set foreign_key_checks=1;
61+
62+
--echo #
63+
--echo # MDEV-25530 Error 1451 on slave: Cannot delete or update a parent row: a foreign key constraint fails
64+
--echo #
65+
66+
create table t1 (id int primary key)engine=innodb;
67+
create table t2 (id int not null primary key auto_increment,
68+
id2 int default null, key f1 (id2),
69+
constraint f1 foreign key (id2) references t1 (id) on delete cascade) engine=innodb;
70+
error ER_ROW_IS_REFERENCED_2;
71+
drop table t1,t2;
72+
sync_slave_with_master;
73+
show tables;
74+
connection master;
75+
drop table t1;
76+
sync_slave_with_master;
6077

6178
--source include/rpl_end.inc

sql/sql_table.cc

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,7 +2238,6 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
22382238
uint not_found_errors= 0;
22392239
int error= 0;
22402240
int non_temp_tables_count= 0;
2241-
bool non_tmp_error= 0;
22422241
bool trans_tmp_table_deleted= 0, non_trans_tmp_table_deleted= 0;
22432242
bool non_tmp_table_deleted= 0;
22442243
bool is_drop_tmp_if_exists_added= 0;
@@ -2304,7 +2303,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
23042303
{
23052304
bool is_trans= 0, temporary_table_was_dropped= 0;
23062305
bool table_creation_was_logged= 0;
2307-
bool local_non_tmp_error= 0, wrong_drop_sequence= 0;
2306+
bool wrong_drop_sequence= 0;
23082307
bool table_dropped= 0;
23092308
const LEX_CSTRING db= table->db;
23102309
const LEX_CSTRING table_name= table->table_name;
@@ -2469,7 +2468,6 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
24692468
*/
24702469
wrong_drop_sequence= drop_sequence && hton;
24712470
was_table|= wrong_drop_sequence;
2472-
local_non_tmp_error= 1;
24732471
error= table_type == TABLE_TYPE_UNKNOWN ? ENOENT : -1;
24742472
tdc_remove_table(thd, db.str, table_name.str);
24752473
}
@@ -2562,7 +2560,6 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
25622560
table_dropped= 1;
25632561
}
25642562
}
2565-
local_non_tmp_error|= MY_TEST(error);
25662563
}
25672564

25682565
/*
@@ -2580,8 +2577,6 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
25802577
ferror= ha_delete_table_force(thd, path, &db, &table_name);
25812578
if (!ferror)
25822579
{
2583-
/* Table existed and was deleted */
2584-
local_non_tmp_error= 0;
25852580
table_dropped= 1;
25862581
error= 0;
25872582
}
@@ -2655,12 +2650,7 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
26552650
didn't exists
26562651
*/
26572652
if (if_exists && non_existing_table_error(error))
2658-
{
26592653
error= 0;
2660-
local_non_tmp_error= 0;
2661-
}
2662-
2663-
non_tmp_error|= local_non_tmp_error;
26642654

26652655
if (!error && table_dropped)
26662656
{
@@ -2774,12 +2764,10 @@ int mysql_rm_table_no_locks(THD *thd, TABLE_LIST *tables, bool if_exists,
27742764
normal_tables.chop();
27752765
built_query.append(normal_tables.ptr(), normal_tables.length());
27762766
built_query.append(" /* generated by server */");
2777-
int error_code = non_tmp_error ? thd->get_stmt_da()->sql_errno() : 0;
27782767
error |= (thd->binlog_query(THD::STMT_QUERY_TYPE,
27792768
built_query.ptr(),
27802769
built_query.length(),
2781-
TRUE, FALSE, FALSE,
2782-
error_code) > 0);
2770+
TRUE, FALSE, FALSE, 0) > 0);
27832771
}
27842772
}
27852773
}

0 commit comments

Comments
 (0)