Skip to content
/ server Public
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/handler_ername.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
{ "HA_ERR_ABORTED_BY_USER", HA_ERR_ABORTED_BY_USER, "" },
{ "HA_ERR_DISK_FULL", HA_ERR_DISK_FULL, "" },
{ "HA_ERR_INCOMPATIBLE_DEFINITION", HA_ERR_INCOMPATIBLE_DEFINITION, "" },
{ "HA_ERR_FK_DEPTH_EXCEEDED", HA_ERR_FK_DEPTH_EXCEEDED, "" },
{ "HA_ERR_COMMIT_ERROR", HA_ERR_COMMIT_ERROR, "" },
{ "HA_ERR_PARTITION_LIST", HA_ERR_PARTITION_LIST, ""},
{ "HA_ERR_NO_ENCRYPTION", HA_ERR_NO_ENCRYPTION, ""},
Expand Down
3 changes: 2 additions & 1 deletion include/my_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,8 @@ enum ha_base_keytype {
#define HA_ERR_ROLLBACK 200 /* Automatic rollback done */
#define HA_ERR_LOCAL_TMP_SPACE_FULL 201
#define HA_ERR_GLOBAL_TMP_SPACE_FULL 202
#define HA_ERR_LAST 202 /* Copy of last error nr * */
#define HA_ERR_CASCADE_SQL 203 /* Error happened in cascade sql action */
#define HA_ERR_LAST 203 /* Copy of last error nr * */

/* Number of different errors */
#define HA_ERR_ERRORS (HA_ERR_LAST - HA_ERR_FIRST + 1)
Expand Down
3 changes: 2 additions & 1 deletion include/my_handler_errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ static const char *handler_error_messages[]=
"Transaction was aborted",
/* HA_ERR_LOCAL_TMP_SPACE_FULL=201 */
"Local temporary space limit reached",
"Global temporary space limit reached"
"Global temporary space limit reached",
"Error in cascade SQL action",
};

#endif /* MYSYS_MY_HANDLER_ERRORS_INCLUDED */
9 changes: 3 additions & 6 deletions mysql-test/main/alter_table_online.result
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,12 @@ references t1 (a)
on update cascade) engine=InnoDB;
insert into t2 values (1),(2),(3);
alter table t2 add c int, algorithm=copy, lock=none;
ERROR 0A000: LOCK=NONE is not supported. Reason: ON UPDATE CASCADE. Try LOCK=SHARED
alter table t2 add c int, algorithm=inplace, lock=none;
alter table t2 add d int, algorithm=inplace, lock=none;
create or replace table t2 (b int, foreign key (b)
references t1 (a)
on delete set null) engine=InnoDB;
alter table t2 add c int, algorithm=copy, lock=none;
ERROR 0A000: LOCK=NONE is not supported. Reason: ON DELETE SET NULL. Try LOCK=SHARED
alter table t2 add c int, algorithm=inplace, lock=none;
alter table t2 add d int, algorithm=inplace, lock=none;
create or replace table t2 (b int, foreign key (b)
references t1 (a)
on delete no action) engine=InnoDB;
Expand All @@ -116,8 +114,7 @@ create table t2 (a int references t1 (a),
b int references t1 (b) on update cascade) engine=InnoDB;
insert into t2 values (1, 1),(2, 2);
alter table t2 add c int, algorithm=copy, lock=none;
ERROR 0A000: LOCK=NONE is not supported. Reason: ON UPDATE CASCADE. Try LOCK=SHARED
alter table t2 add c int, algorithm=copy;
alter table t2 add e int, algorithm=copy;
alter table t2 add d int, algorithm=inplace;
drop table t2, t1;
#
Expand Down
12 changes: 6 additions & 6 deletions mysql-test/main/alter_table_online.test
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ DROP TABLE t;

--echo #
--echo # MDEV-29068 Cascade foreign key updates do not apply in online alter
--echo # per MDEV-31942 Online alter: support cascade foreign keys
--echo # The limitation is lifted
--echo #
create table t1 (a int primary key) engine=InnoDB;
insert into t1 values (1),(2),(3);
Expand All @@ -78,17 +80,16 @@ create table t2 (b int, foreign key (b)
on update cascade) engine=InnoDB;
insert into t2 values (1),(2),(3);

--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON

alter table t2 add c int, algorithm=copy, lock=none;
alter table t2 add c int, algorithm=inplace, lock=none;
alter table t2 add d int, algorithm=inplace, lock=none;

create or replace table t2 (b int, foreign key (b)
references t1 (a)
on delete set null) engine=InnoDB;

--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
alter table t2 add c int, algorithm=copy, lock=none;
alter table t2 add c int, algorithm=inplace, lock=none;
alter table t2 add d int, algorithm=inplace, lock=none;

create or replace table t2 (b int, foreign key (b)
references t1 (a)
Expand All @@ -111,9 +112,8 @@ create table t2 (a int references t1 (a),
b int references t1 (b) on update cascade) engine=InnoDB;
insert into t2 values (1, 1),(2, 2);

--error ER_ALTER_OPERATION_NOT_SUPPORTED_REASON
alter table t2 add c int, algorithm=copy, lock=none;
alter table t2 add c int, algorithm=copy;
alter table t2 add e int, algorithm=copy;
alter table t2 add d int, algorithm=inplace;
# Cleanup
drop table t2, t1;
Expand Down
89 changes: 87 additions & 2 deletions mysql-test/main/alter_table_online_debug.result
Original file line number Diff line number Diff line change
Expand Up @@ -1830,8 +1830,93 @@ alter table t add index (a), algorithm=copy, lock=none;
connection default;
drop table t;
set global default_storage_engine= MyISAM;
disconnect con1;
disconnect con2;
#
# End of 11.2 tests
#
# MDEV-12302: Execute triggers for foreign key updates/deletes
# This unblocks online alter table for cascade FK
create table t1 (a int primary key) engine=InnoDB;
insert into t1 values (1),(2),(3);
create table t2 (b int unique references t1 (a) on delete cascade) engine=InnoDB;
insert into t2 values (1),(2),(3);
set debug_sync= 'alter_table_copy_end SIGNAL copy_end WAIT_FOR proceed';
alter table t2 add c int default (b+1), algorithm=copy, lock=none;
connection con1;
set debug_sync='now WAIT_FOR copy_end';
delete from t1 where a = 1;
set debug_sync='now SIGNAL proceed';
connection default;
select * from t2;
b c
2 3
3 4
create or replace table t2 (b int, foreign key (b)
references t1 (a)
on delete set null) engine=InnoDB;
insert into t2 values (2),(3);
set debug_sync= 'alter_table_copy_end SIGNAL copy_end WAIT_FOR proceed';
alter table t2 add c int default (b+1), algorithm=copy, lock=none;
connection con1;
set debug_sync='now WAIT_FOR copy_end';
delete from t1 where a = 2;
set debug_sync='now SIGNAL proceed';
connection default;
select * from t2;
b c
NULL NULL
3 4
select * from t1;
a
3
drop table t2, t1;
create table t1 (a int primary key, b int unique) engine=InnoDB;
insert into t1 values (1, 1),(2, 2),(3, 3);
create table t2 (a int references t1 (a) on update cascade,
b int references t1 (b) on update cascade) engine=InnoDB;
insert into t2 values (1, 1),(2, 2),(3, 3);
set debug_sync= 'alter_table_copy_end SIGNAL copy_end WAIT_FOR proceed';
alter table t2 add c int default (b+1), algorithm=copy, lock=none;
connection con1;
set debug_sync='now WAIT_FOR copy_end';
update t1 set a = 5, b = 6 where a = 2;
set debug_sync='now SIGNAL proceed';
connection default;
select * from t2;
a b c
1 1 2
5 6 7
3 3 4
select * from t1;
a b
1 1
3 3
5 6
drop table t2, t1;
create table t1 (a int primary key, b int unique) engine=InnoDB;
insert into t1 values (1, 1),(2, 2),(3, 3);
create table t2 (a int references t1 (a) on update cascade,
b int references t1 (b) on update set null) engine=InnoDB;
insert into t2 values (1, 1),(2, 2),(3, 3);
set debug_sync= 'alter_table_copy_end SIGNAL copy_end WAIT_FOR proceed';
alter table t2 add c int default (b+1), algorithm=copy, lock=none;
connection con1;
set debug_sync='now WAIT_FOR copy_end';
update t1 set a=5, b = 6 where a = 2;
set debug_sync='now SIGNAL proceed';
connection default;
select * from t2;
a b c
1 1 2
5 NULL NULL
3 3 4
select * from t1;
a b
1 1
3 3
5 6
drop table t2, t1;
#
# End of 11.3 tests
#
disconnect con1;
disconnect con2;
91 changes: 89 additions & 2 deletions mysql-test/main/alter_table_online_debug.test
Original file line number Diff line number Diff line change
Expand Up @@ -2103,8 +2103,95 @@ drop table t;

eval set global default_storage_engine= $default_storage_engine;

--disconnect con1
--disconnect con2

--echo #
--echo # End of 11.2 tests
--echo #


--echo # MDEV-31942 Online alter: support cascade foreign keys
create table t1 (a int primary key) engine=InnoDB;
insert into t1 values (1),(2),(3);

create table t2 (b int unique references t1 (a) on delete cascade) engine=InnoDB;
insert into t2 values (1),(2),(3);


set debug_sync= 'alter_table_copy_end SIGNAL copy_end WAIT_FOR proceed';
send alter table t2 add c int default (b+1), algorithm=copy, lock=none;
connection con1;

set debug_sync='now WAIT_FOR copy_end';
delete from t1 where a = 1;
set debug_sync='now SIGNAL proceed';
connection default;
reap;
select * from t2;

create or replace table t2 (b int, foreign key (b)
references t1 (a)
on delete set null) engine=InnoDB;
insert into t2 values (2),(3);

set debug_sync= 'alter_table_copy_end SIGNAL copy_end WAIT_FOR proceed';
send alter table t2 add c int default (b+1), algorithm=copy, lock=none;

connection con1;
set debug_sync='now WAIT_FOR copy_end';
delete from t1 where a = 2;
set debug_sync='now SIGNAL proceed';
connection default;
reap;
select * from t2;
select * from t1;

drop table t2, t1;

create table t1 (a int primary key, b int unique) engine=InnoDB;
insert into t1 values (1, 1),(2, 2),(3, 3);
create table t2 (a int references t1 (a) on update cascade,
b int references t1 (b) on update cascade) engine=InnoDB;
insert into t2 values (1, 1),(2, 2),(3, 3);

set debug_sync= 'alter_table_copy_end SIGNAL copy_end WAIT_FOR proceed';
send alter table t2 add c int default (b+1), algorithm=copy, lock=none;

connection con1;
set debug_sync='now WAIT_FOR copy_end';
update t1 set a = 5, b = 6 where a = 2;
set debug_sync='now SIGNAL proceed';
connection default;
reap;
select * from t2;
select * from t1;

drop table t2, t1;

create table t1 (a int primary key, b int unique) engine=InnoDB;
insert into t1 values (1, 1),(2, 2),(3, 3);
create table t2 (a int references t1 (a) on update cascade,
b int references t1 (b) on update set null) engine=InnoDB;
insert into t2 values (1, 1),(2, 2),(3, 3);

set debug_sync= 'alter_table_copy_end SIGNAL copy_end WAIT_FOR proceed';
send alter table t2 add c int default (b+1), algorithm=copy, lock=none;

connection con1;
set debug_sync='now WAIT_FOR copy_end';
update t1 set a=5, b = 6 where a = 2;
set debug_sync='now SIGNAL proceed';
connection default;
reap;
select * from t2;
select * from t1;

# Cleanup
drop table t2, t1;

--echo #
--echo # End of 11.3 tests
--echo #


--disconnect con1
--disconnect con2
8 changes: 4 additions & 4 deletions mysql-test/suite/innodb/r/foreign_key.result
Original file line number Diff line number Diff line change
Expand Up @@ -707,9 +707,9 @@ connection default;
DELETE IGNORE FROM t1 WHERE b = 1;
Warnings:
Warning 152 InnoDB: Cannot delete/update rows with cascading foreign key constraints that exceed max depth of 15. Please drop extra constraints and try again
Warning 1296 Got error 193 '`test`.`t1`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`b`) ON DELETE CASCADE' from InnoDB
Warning 1030 Got error 193 "Foreign key cascade delete/update exceeds max depth" from storage engine InnoDB
Warning 152 InnoDB: Cannot delete/update rows with cascading foreign key constraints that exceed max depth of 15. Please drop extra constraints and try again
Warning 1296 Got error 193 '`test`.`t1`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`b`) ON DELETE CASCADE' from InnoDB
Warning 1030 Got error 193 "Foreign key cascade delete/update exceeds max depth" from storage engine InnoDB
SELECT a FROM t1 FORCE INDEX(a);
a
0
Expand Down Expand Up @@ -872,11 +872,11 @@ INSERT INTO t1 (a,b) VALUES
(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),
(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,1),(1,0);
DELETE FROM t1 WHERE b = 1;
ERROR HY000: Got error 193 '`test`.`t1`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`b`) ON DELETE CASCADE' from InnoDB
ERROR HY000: Got error 193 "Foreign key cascade delete/update exceeds max depth" from storage engine InnoDB
SHOW WARNINGS;
Level Code Message
Warning 152 InnoDB: Cannot delete/update rows with cascading foreign key constraints that exceed max depth of 15. Please drop extra constraints and try again
Error 1296 Got error 193 '`test`.`t1`, CONSTRAINT `1` FOREIGN KEY (`a`) REFERENCES `t1` (`b`) ON DELETE CASCADE' from InnoDB
Error 1030 Got error 193 "Foreign key cascade delete/update exceeds max depth" from storage engine InnoDB
DROP TABLE t1;
FOUND 1 /InnoDB: Cannot delete/update rows with cascading foreign key constraints that exceed max depth of 15.*/ in mysqld.1.err
# End of 10.2 tests
Expand Down
Loading