mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
MDEV-29068 Cascade foreign key updates do not apply in online alter
This commit is contained in:
committed by
Sergei Golubchik
parent
84ed2e7ce6
commit
b08b78c5b9
@ -80,3 +80,43 @@ XA END 'xid';
|
|||||||
XA COMMIT 'xid' ONE PHASE;
|
XA COMMIT 'xid' ONE PHASE;
|
||||||
DROP TABLE t;
|
DROP TABLE t;
|
||||||
disconnect con1;
|
disconnect con1;
|
||||||
|
connection default;
|
||||||
|
#
|
||||||
|
# MDEV-29068 Cascade foreign key updates do not apply in online alter
|
||||||
|
#
|
||||||
|
create table t1 (a int primary key) engine=InnoDB;
|
||||||
|
insert into t1 values (1),(2),(3);
|
||||||
|
create table t2 (b int, foreign key (b)
|
||||||
|
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: COPY algorithm requires a lock. Try LOCK=SHARED
|
||||||
|
alter table t2 add c 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: COPY algorithm requires a lock. Try LOCK=SHARED
|
||||||
|
alter table t2 add c int, algorithm=inplace, lock=none;
|
||||||
|
create or replace table t2 (b int, foreign key (b)
|
||||||
|
references t1 (a)
|
||||||
|
on delete no action) engine=InnoDB;
|
||||||
|
insert into t2 values (1),(2),(3);
|
||||||
|
alter table t2 add c int, algorithm=copy, lock=none;
|
||||||
|
create or replace table t2 (b int, foreign key (b)
|
||||||
|
references t1 (a)
|
||||||
|
on update restrict) engine=InnoDB;
|
||||||
|
insert into t2 values (1),(2),(3);
|
||||||
|
alter table t2 add c int, algorithm=copy, lock=none;
|
||||||
|
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),
|
||||||
|
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: COPY algorithm requires a lock. Try LOCK=SHARED
|
||||||
|
alter table t2 add c int, algorithm=copy;
|
||||||
|
alter table t2 add d int, algorithm=inplace;
|
||||||
|
drop table t2, t1;
|
||||||
|
@ -64,3 +64,54 @@ XA COMMIT 'xid' ONE PHASE;
|
|||||||
|
|
||||||
DROP TABLE t;
|
DROP TABLE t;
|
||||||
--disconnect con1
|
--disconnect con1
|
||||||
|
--connection default
|
||||||
|
|
||||||
|
--echo #
|
||||||
|
--echo # MDEV-29068 Cascade foreign key updates do not apply in online alter
|
||||||
|
--echo #
|
||||||
|
create table t1 (a int primary key) engine=InnoDB;
|
||||||
|
insert into t1 values (1),(2),(3);
|
||||||
|
create table t2 (b int, foreign key (b)
|
||||||
|
references t1 (a)
|
||||||
|
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;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
create or replace table t2 (b int, foreign key (b)
|
||||||
|
references t1 (a)
|
||||||
|
on delete no action) engine=InnoDB;
|
||||||
|
|
||||||
|
insert into t2 values (1),(2),(3);
|
||||||
|
alter table t2 add c int, algorithm=copy, lock=none;
|
||||||
|
|
||||||
|
create or replace table t2 (b int, foreign key (b)
|
||||||
|
references t1 (a)
|
||||||
|
on update restrict) engine=InnoDB;
|
||||||
|
|
||||||
|
insert into t2 values (1),(2),(3);
|
||||||
|
alter table t2 add c int, algorithm=copy, lock=none;
|
||||||
|
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),
|
||||||
|
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 d int, algorithm=inplace;
|
||||||
|
# Cleanup
|
||||||
|
drop table t2, t1;
|
||||||
|
@ -10071,6 +10071,18 @@ bool mysql_alter_table(THD *thd, const LEX_CSTRING *new_db,
|
|||||||
|
|
||||||
online= online && !table->s->tmp_table;
|
online= online && !table->s->tmp_table;
|
||||||
|
|
||||||
|
List<FOREIGN_KEY_INFO> fk_list;
|
||||||
|
table->file->get_foreign_key_list(thd, &fk_list);
|
||||||
|
for (auto &fk: fk_list)
|
||||||
|
{
|
||||||
|
if (fk_modifies_child(fk.delete_method)
|
||||||
|
|| fk_modifies_child(fk.update_method))
|
||||||
|
{
|
||||||
|
online= false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef WITH_WSREP
|
#ifdef WITH_WSREP
|
||||||
if (WSREP(thd) &&
|
if (WSREP(thd) &&
|
||||||
(thd->lex->sql_command == SQLCOM_ALTER_TABLE ||
|
(thd->lex->sql_command == SQLCOM_ALTER_TABLE ||
|
||||||
|
Reference in New Issue
Block a user