mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
Before MySQL 4.0.18, user-specified constraint names were ignored. Starting with MySQL 4.0.18, the specified constraint name was prepended with the schema name and '/'. Now we are transforming into a format where the constraint name is prepended with the dict_table_t::name and the impossible UTF-8 sequence 0xff. Generated constraint names will be ASCII decimal numbers. On upgrade, old FOREIGN KEY constraint names will be displayed without any schema name prefix. They will be updated to the new format on DDL operations. dict_foreign_t::sql_id(): Return the SQL constraint name without any schemaname/tablename\377 or schemaname/ prefix. row_rename_table_for_mysql(), dict_table_rename_in_cache(): Simplify the logic: Just rename constraints to the new format. dict_table_get_foreign_id(): Replaces dict_table_get_highest_foreign_id(). innobase_get_foreign_key_info(): Let my_error() refer to erroneous anonymous constraints as "(null)". row_delete_constraint(): Try to drop all 3 constraint name variants. Reviewed by: Thirunarayanan Balathandayuthapani Tested by: Matthias Leich
291 lines
8.1 KiB
Plaintext
291 lines
8.1 KiB
Plaintext
#
|
|
# Bug #18451287 REDUNDANT DELETE MARKING AFTER DB_LOCK_WAIT
|
|
#
|
|
create table t1 (f1 int primary key, f2 blob) engine=innodb;
|
|
create table t2 (f1 int primary key, f2 int,
|
|
foreign key (f2) references t1(f1) on update cascade) engine=innodb;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`f1` int(11) NOT NULL,
|
|
`f2` blob DEFAULT NULL,
|
|
PRIMARY KEY (`f1`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
|
show create table t2;
|
|
Table Create Table
|
|
t2 CREATE TABLE `t2` (
|
|
`f1` int(11) NOT NULL,
|
|
`f2` int(11) DEFAULT NULL,
|
|
PRIMARY KEY (`f1`),
|
|
KEY `f2` (`f2`),
|
|
CONSTRAINT `1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f1`) ON UPDATE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
|
insert into t1 values (1, repeat('+', 20000));
|
|
insert into t1 values (2, repeat('-', 20000));
|
|
insert into t1 values (3, repeat('=', 20000));
|
|
insert into t2 values (1, 2);
|
|
select f1, right(f2, 20) as p2 from t1;
|
|
f1 p2
|
|
1 ++++++++++++++++++++
|
|
2 --------------------
|
|
3 ====================
|
|
select f1, f2 from t2;
|
|
f1 f2
|
|
1 2
|
|
connect con1,localhost,root,,test;
|
|
start transaction;
|
|
select f1, f2 from t2 for update;
|
|
f1 f2
|
|
1 2
|
|
connection default;
|
|
set debug_sync='lock_wait_start SIGNAL upd_waiting WAIT_FOR go_upd';
|
|
update t1 set f1 = 10 where f1 = 2;
|
|
connection con1;
|
|
set debug_sync='now WAIT_FOR upd_waiting';
|
|
rollback;
|
|
set debug_sync='now SIGNAL go_upd';
|
|
connection default;
|
|
# reap: update t1 set f1 = 10 where f1 = 2;
|
|
select f1, right(f2, 20) as p2 from t1;
|
|
f1 p2
|
|
1 ++++++++++++++++++++
|
|
3 ====================
|
|
10 --------------------
|
|
select f1, f2 from t2;
|
|
f1 f2
|
|
1 10
|
|
drop table t2, t1;
|
|
set debug_sync = reset;
|
|
#
|
|
# Test Scenario: Two tables t1 -> t2 are involved in update cascade.
|
|
# If DB_LOCK_WAIT happens when t1 is being updated and FK constraints
|
|
# are being checked in t2, then retry must happen on t1. The update
|
|
# cascade happens in secondary index. For secondary index testing,
|
|
# blobs are not needed.
|
|
#
|
|
create table t1 (f1 int primary key, f2 int, key k1(f2)) engine=innodb;
|
|
create table t2 (f1 int primary key, f2 int,
|
|
foreign key (f2) references t1(f2) on update cascade) engine=innodb;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`f1` int(11) NOT NULL,
|
|
`f2` int(11) DEFAULT NULL,
|
|
PRIMARY KEY (`f1`),
|
|
KEY `k1` (`f2`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
|
show create table t2;
|
|
Table Create Table
|
|
t2 CREATE TABLE `t2` (
|
|
`f1` int(11) NOT NULL,
|
|
`f2` int(11) DEFAULT NULL,
|
|
PRIMARY KEY (`f1`),
|
|
KEY `f2` (`f2`),
|
|
CONSTRAINT `1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f2`) ON UPDATE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
|
insert into t1 values (1, 91);
|
|
insert into t2 values (1, 91);
|
|
select f1, f2 from t1;
|
|
f1 f2
|
|
1 91
|
|
select f1, f2 from t2;
|
|
f1 f2
|
|
1 91
|
|
connection con1;
|
|
start transaction;
|
|
select f1, f2 from t2 for update;
|
|
f1 f2
|
|
1 91
|
|
connection default;
|
|
set debug_sync='lock_wait_start SIGNAL upd_waiting WAIT_FOR go_upd';
|
|
update t1 set f2 = 28 where f2 = 91;
|
|
connection con1;
|
|
set debug_sync='now WAIT_FOR upd_waiting';
|
|
rollback;
|
|
set debug_sync='now SIGNAL go_upd';
|
|
connection default;
|
|
# reap: update t1 set f1 = 10 where f1 = 2;
|
|
select f1, f2 from t1;
|
|
f1 f2
|
|
1 28
|
|
select f1, f2 from t2;
|
|
f1 f2
|
|
1 28
|
|
drop table t2, t1;
|
|
set debug_sync = reset;
|
|
#
|
|
# Test Scenario: Three tables t1 -> t2 -> t3 are involved in update cascade.
|
|
# If DB_LOCK_WAIT happens when t2 is being updated, then retry must happen
|
|
# on t2.
|
|
#
|
|
create table t1 (f1 int primary key, f2 blob) engine=innodb;
|
|
create table t2 (f1 int primary key, f2 blob,
|
|
foreign key (f1) references t1(f1) on update cascade) engine=innodb;
|
|
create table t3 (f1 int primary key, f2 blob,
|
|
foreign key (f1) references t2(f1) on update cascade) engine=innodb;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`f1` int(11) NOT NULL,
|
|
`f2` blob DEFAULT NULL,
|
|
PRIMARY KEY (`f1`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
|
show create table t2;
|
|
Table Create Table
|
|
t2 CREATE TABLE `t2` (
|
|
`f1` int(11) NOT NULL,
|
|
`f2` blob DEFAULT NULL,
|
|
PRIMARY KEY (`f1`),
|
|
CONSTRAINT `1` FOREIGN KEY (`f1`) REFERENCES `t1` (`f1`) ON UPDATE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
|
show create table t3;
|
|
Table Create Table
|
|
t3 CREATE TABLE `t3` (
|
|
`f1` int(11) NOT NULL,
|
|
`f2` blob DEFAULT NULL,
|
|
PRIMARY KEY (`f1`),
|
|
CONSTRAINT `1` FOREIGN KEY (`f1`) REFERENCES `t2` (`f1`) ON UPDATE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
|
insert into t1 values (2, repeat('-', 20000));
|
|
insert into t2 values (2, repeat('%', 20000));
|
|
insert into t3 values (2, repeat('+', 20000));
|
|
select f1, right(f2, 20) as p2 from t1;
|
|
f1 p2
|
|
2 --------------------
|
|
select f1, right(f2, 20) as p2 from t2;
|
|
f1 p2
|
|
2 %%%%%%%%%%%%%%%%%%%%
|
|
select f1, right(f2, 20) as p2 from t3;
|
|
f1 p2
|
|
2 ++++++++++++++++++++
|
|
connection con1;
|
|
start transaction;
|
|
select f1 from t3 for update;
|
|
f1
|
|
2
|
|
connection default;
|
|
set debug_sync='lock_wait_start SIGNAL upd_waiting WAIT_FOR go_upd';
|
|
update t1 set f1 = 10 where f1 = 2;
|
|
connection con1;
|
|
set debug_sync='now WAIT_FOR upd_waiting';
|
|
rollback;
|
|
# The table t1 is updated.
|
|
# In t2 delete-mark happened. Retry will happen on t2.
|
|
# In t3 yet to be updated.
|
|
set session transaction isolation level read uncommitted;
|
|
start transaction;
|
|
select f1, right(f2, 20) as p2 from t1;
|
|
f1 p2
|
|
select f1, right(f2, 20) as p2 from t2;
|
|
f1 p2
|
|
select f1, right(f2, 20) as p2 from t3;
|
|
f1 p2
|
|
2 ++++++++++++++++++++
|
|
commit;
|
|
set debug_sync='now SIGNAL go_upd';
|
|
connection default;
|
|
# reap: update t1 set f1 = 10 where f1 = 2;
|
|
start transaction;
|
|
select f1, right(f2, 20) as p2 from t1;
|
|
f1 p2
|
|
10 --------------------
|
|
select f1, right(f2, 20) as p2 from t2;
|
|
f1 p2
|
|
10 %%%%%%%%%%%%%%%%%%%%
|
|
select f1, right(f2, 20) as p2 from t3;
|
|
f1 p2
|
|
10 ++++++++++++++++++++
|
|
commit;
|
|
drop table t3, t2, t1;
|
|
set debug_sync = reset;
|
|
#
|
|
# Test Scenario: Three tables t1 -> t2 -> t3 are involved in update
|
|
# cascade. If DB_LOCK_WAIT happens when t2 is being updated, then
|
|
# retry must happen on t2. The update cascade is happening via
|
|
# secondary index (hence blobs are not needed).
|
|
#
|
|
create table t1 (f1 int primary key, f2 int, key k1(f2)) engine=innodb;
|
|
create table t2 (f1 int primary key, f2 int,
|
|
foreign key (f2) references t1(f2) on update cascade) engine=innodb;
|
|
create table t3 (f1 int primary key, f2 int,
|
|
foreign key (f2) references t2(f2) on update cascade) engine=innodb;
|
|
show create table t1;
|
|
Table Create Table
|
|
t1 CREATE TABLE `t1` (
|
|
`f1` int(11) NOT NULL,
|
|
`f2` int(11) DEFAULT NULL,
|
|
PRIMARY KEY (`f1`),
|
|
KEY `k1` (`f2`)
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
|
show create table t2;
|
|
Table Create Table
|
|
t2 CREATE TABLE `t2` (
|
|
`f1` int(11) NOT NULL,
|
|
`f2` int(11) DEFAULT NULL,
|
|
PRIMARY KEY (`f1`),
|
|
KEY `f2` (`f2`),
|
|
CONSTRAINT `1` FOREIGN KEY (`f2`) REFERENCES `t1` (`f2`) ON UPDATE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
|
show create table t3;
|
|
Table Create Table
|
|
t3 CREATE TABLE `t3` (
|
|
`f1` int(11) NOT NULL,
|
|
`f2` int(11) DEFAULT NULL,
|
|
PRIMARY KEY (`f1`),
|
|
KEY `f2` (`f2`),
|
|
CONSTRAINT `1` FOREIGN KEY (`f2`) REFERENCES `t2` (`f2`) ON UPDATE CASCADE
|
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
|
|
insert into t1 values (2, 91);
|
|
insert into t2 values (2, 91);
|
|
insert into t3 values (2, 91);
|
|
select f1, f2 from t1;
|
|
f1 f2
|
|
2 91
|
|
select f1, f2 from t2;
|
|
f1 f2
|
|
2 91
|
|
select f1, f2 from t3;
|
|
f1 f2
|
|
2 91
|
|
connection con1;
|
|
start transaction;
|
|
select f1 from t3 for update;
|
|
f1
|
|
2
|
|
connection default;
|
|
set debug_sync='lock_wait_start SIGNAL upd_waiting WAIT_FOR go_upd';
|
|
update t1 set f2 = 28 where f2 = 91;
|
|
connection con1;
|
|
set debug_sync='now WAIT_FOR upd_waiting';
|
|
rollback;
|
|
# The table t1 is updated.
|
|
# In t2 delete-mark happened. Retry will happen on t2.
|
|
# In t3 yet to be updated.
|
|
set session transaction isolation level read uncommitted;
|
|
start transaction;
|
|
select f1, f2 from t1;
|
|
f1 f2
|
|
select f1, f2 from t2;
|
|
f1 f2
|
|
select f1, f2 from t3;
|
|
f1 f2
|
|
2 91
|
|
commit;
|
|
set debug_sync='now SIGNAL go_upd';
|
|
disconnect con1;
|
|
connection default;
|
|
# reap: update t1 set f2 = 28 where f2 = 91;
|
|
start transaction;
|
|
select f1, f2 from t1;
|
|
f1 f2
|
|
2 28
|
|
select f1, f2 from t2;
|
|
f1 f2
|
|
2 28
|
|
select f1, f2 from t3;
|
|
f1 f2
|
|
2 28
|
|
commit;
|
|
drop table t3, t2, t1;
|
|
set debug_sync = reset;
|