Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MDEV-19191 Partial support of foreign keys in partitioned tables #3641

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
17 changes: 13 additions & 4 deletions cmake/dtrace.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,25 @@ FUNCTION(DTRACE_INSTRUMENT target)
WORKING_DIRECTORY ${objdir}
)
ELSEIF(CMAKE_SYSTEM_NAME MATCHES "Linux")
# dtrace on Linux runs gcc and uses flags from environment
SET(CFLAGS_SAVED $ENV{CFLAGS})
SET(ENV{CFLAGS} ${CMAKE_C_FLAGS})
IF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# dtrace on Linux runs gcc and uses flags from environment
SET(CFLAGS_SAVED $ENV{CFLAGS})
# We want to strip off all warning flags, including -Werror=xxx-xx,
# but keep flags like
# -Wp,-D_FORTIFY_SOURCE=2
STRING(REGEX REPLACE "-W[A-Za-z0-9][-A-Za-z0-9=]+" ""
C_FLAGS "${CMAKE_C_FLAGS}")
SET(ENV{CFLAGS} ${CMAKE_C_FLAGS})
ENDIF()
SET(outfile "${CMAKE_BINARY_DIR}/probes_mysql.o")
# Systemtap object
EXECUTE_PROCESS(
COMMAND ${DTRACE} -G -s ${CMAKE_SOURCE_DIR}/include/probes_mysql.d.base
-o ${outfile}
)
SET(ENV{CFLAGS} ${CFLAGS_SAVED})
IF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
SET(ENV{CFLAGS} ${CFLAGS_SAVED})
ENDIF()
ENDIF()

# Do not try to extend the library if we have not built the .o file
Expand Down
9 changes: 8 additions & 1 deletion mysql-test/main/partition.result
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,14 @@ drop table t1;
CREATE TABLE t1 (a INT, FOREIGN KEY (a) REFERENCES t0 (a))
ENGINE=MyISAM
PARTITION BY HASH (a);
ERROR HY000: Partitioned tables do not support FOREIGN KEY
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`a` int(11) DEFAULT NULL,
KEY `a` (`a`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
PARTITION BY HASH (`a`)
drop table t1;
CREATE TABLE t1 (
pk INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY (pk)
Expand Down
3 changes: 2 additions & 1 deletion mysql-test/main/partition.test
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,11 @@ drop table t1;
#
# Bug#36001: Partitions: spelling and using some error messages
#
--error ER_FEATURE_NOT_SUPPORTED_WITH_PARTITIONING
CREATE TABLE t1 (a INT, FOREIGN KEY (a) REFERENCES t0 (a))
ENGINE=MyISAM
PARTITION BY HASH (a);
show create table t1;
drop table t1;
Comment on lines -295 to +299
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not sufficient to demonstrate that the table can be created. Some functional testing is needed as well, to demonstrate that the foreign keys actually work.

Given that this test uses ENGINE=MyISAM and FOREIGN KEY constraints are currently implemented only in ENGINE=InnoDB, this test seem to demonstrate that things are changing for the worse. We’d allow a DDL operation that was previously rejected because it was known not to work. I don’t think that this change is acceptable.


#
# Bug#40954: Crash if range search and order by.
Expand Down
3 changes: 1 addition & 2 deletions mysql-test/main/partition_innodb.result
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,9 @@ KEY parent_id (parent_id)
) ENGINE=InnoDB;
ALTER TABLE t1 PARTITION BY HASH (id) PARTITIONS 1;
ALTER TABLE t1 ADD CONSTRAINT test_ibfk_1 FOREIGN KEY (parent_id) REFERENCES t2 (id);
ERROR HY000: Partitioned tables do not support FOREIGN KEY
ALTER TABLE t1 PARTITION BY HASH (id) PARTITIONS 2;
ALTER TABLE t1 ADD CONSTRAINT test_ibfk_1 FOREIGN KEY (parent_id) REFERENCES t2 (id);
ERROR HY000: Partitioned tables do not support FOREIGN KEY
ERROR HY000: Can't create table `test`.`t1` (errno: 150 "Foreign key constraint is incorrectly formed")
Comment on lines 247 to +250
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message looks incorrect here. Shouldn’t this fail because a duplicate constraint name test_ibfk_1? Would it work with a different constraint name?

DROP TABLE t1, t2;
create table t1 (a varchar(5), b int signed, c varchar(10), d datetime)
partition by range columns(b,c)
Expand Down
3 changes: 1 addition & 2 deletions mysql-test/main/partition_innodb.test
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,11 @@ CREATE TABLE t1 (

ALTER TABLE t1 PARTITION BY HASH (id) PARTITIONS 1;

--error ER_FEATURE_NOT_SUPPORTED_WITH_PARTITIONING
ALTER TABLE t1 ADD CONSTRAINT test_ibfk_1 FOREIGN KEY (parent_id) REFERENCES t2 (id);

ALTER TABLE t1 PARTITION BY HASH (id) PARTITIONS 2;

--error ER_FEATURE_NOT_SUPPORTED_WITH_PARTITIONING
--error ER_CANT_CREATE_TABLE
ALTER TABLE t1 ADD CONSTRAINT test_ibfk_1 FOREIGN KEY (parent_id) REFERENCES t2 (id);

DROP TABLE t1, t2;
Comment on lines -240 to 247
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some functional testing with DML statements is needed here to demonstrate that the FOREIGN KEY constraint works after each of these ALTER TABLE operation, including the rejected one.

Please also add a comment here that there are further tests about this in parts.foreign. Initially, I was going to ask for this to be extended to cover ON (UPDATE|DELETE) (CASCADE|SET NULL), but those are covered in that test.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ set binlog_alter_two_phase = ON;
create table t1 (f1 int primary key) engine=InnoDB;
create table t2 (f1 int primary key, constraint c1 foreign key (f1) references t1(f1)) engine=innodb;
alter table t2 add constraint c1 foreign key (f1) references t1(f1);
ERROR HY000: Can't create table `test`.`t2` (errno: 121 "Duplicate key on write or update")
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
drop table t2, t1;
select @@gtid_binlog_state;
@@gtid_binlog_state
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/innodb/r/add_constraint.result
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ create table t2(a int, b int, key(a),key(b))engine=innodb;
alter table t2 add constraint b foreign key (b) references t1(a);
alter table t1 add constraint b1 foreign key (b) references t2(a);
alter table t2 add constraint b1 foreign key (b) references t1(a);
ERROR HY000: Can't create table `test`.`t2` (errno: 121 "Duplicate key on write or update")
ERROR HY000: Duplicate constraint name
alter table t2 drop foreign key b;
alter table t1 drop foreign key b1;
drop table t2;
Expand Down
3 changes: 1 addition & 2 deletions mysql-test/suite/innodb/r/alter_copy_bulk.result
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ ALTER TABLE t1 ALGORITHM=COPY, FORCE;
affected rows: 2
info: Records: 2 Duplicates: 0 Warnings: 0
ALTER TABLE t2 ALGORITHM=COPY, FORCE;
affected rows: 1
info: Records: 1 Duplicates: 0 Warnings: 0
ERROR 23000: Cannot add or update a child row: a foreign key constraint fails (`test`.`#sql-alter`, CONSTRAINT `)
DROP TABLE t2, t1;
#
# MDEV-35237 Bulk insert fails to apply buffered
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/innodb/r/alter_partitioned.result
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ CREATE TABLE t2(a INT, FOREIGN KEY(a) REFERENCES t1(a))ENGINE=INNODB
PARTITION BY RANGE(a)
(PARTITION pa VALUES LESS THAN (2),
PARTITION pb VALUES LESS THAN (4));
ERROR HY000: Partitioned tables do not support FOREIGN KEY
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
DROP TABLE t1;
# End of 10.3 tests
#
Expand Down
4 changes: 2 additions & 2 deletions mysql-test/suite/innodb/r/foreign_key.result
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint
create table t2 (f1 int primary key,
constraint c1 foreign key (f1) references t1(f1)) engine=innodb;
alter table t2 add constraint c1 foreign key (f1) references t1(f1);
ERROR HY000: Can't create table `test`.`t2` (errno: 121 "Duplicate key on write or update")
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
set foreign_key_checks = 0;
alter table t2 add constraint c1 foreign key (f1) references t1(f1);
ERROR HY000: Duplicate FOREIGN KEY constraint name 'test/c1'
Expand Down Expand Up @@ -210,7 +210,7 @@ CONSTRAINT t2_ibfk_1 FOREIGN KEY (a) REFERENCES t1(a)) ENGINE=InnoDB;
CREATE TABLE best.t2 (a INT PRIMARY KEY, b TEXT, FULLTEXT INDEX(b),
FOREIGN KEY (a) REFERENCES test.t1(a)) ENGINE=InnoDB;
RENAME TABLE best.t2 TO test.t2;
ERROR 42S01: Table 't2' already exists
ERROR HY000: Duplicate constraint name
SHOW CREATE TABLE best.t2;
Table Create Table
t2 CREATE TABLE `t2` (
Expand Down
43 changes: 43 additions & 0 deletions mysql-test/suite/innodb/r/foreign_key_not_windows.result
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@ CREATE DATABASE `d255`;
CREATE TABLE `d255`.`d255`
(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB;
ERROR HY000: Long database name and identifier for object resulted in path length exceeding 512 characters. Path: './@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023/@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@
CREATE OR REPLACE TABLE `d255`.`d255`
(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB;
ERROR HY000: Long database name and identifier for object resulted in path length exceeding 512 characters. Path: './@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023/@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@
CREATE TABLE `d255`.`_##################################################`
(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB;
ERROR HY000: Long database name and identifier for object resulted in path length exceeding 512 characters. Path: './@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023/_@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023
CREATE OR REPLACE TABLE `d255`.`_##################################################`
(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB;
ERROR HY000: Long database name and identifier for object resulted in path length exceeding 512 characters. Path: './@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023/_@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023@0023
CREATE TABLE `d255`.`##################################################`
(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB;
CREATE OR REPLACE TABLE `d255`.`d245`
(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB;
DROP TABLE `d255`.`d245`;
#
# MDEV-29258 Failing assertion for name length on RENAME TABLE
#
Expand All @@ -29,3 +38,37 @@ RENAME TABLE `d255`.u TO u;
DROP TABLE u;
DROP DATABASE `d255`;
# End of 10.3 tests
#
# MDEV-28933 CREATE OR REPLACE fails to recreate same constraint name
#
set names utf8;
create database `❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎`;
use `❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎`;
create table t (a int primary key) engine=innodb;
create table u (
a int primary key,
constraint `❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎` foreign key d (a) references t (a)) engine=innodb;
select * from information_schema.innodb_sys_foreign;
ID FOR_NAME REF_NAME N_COLS TYPE
@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@27 @274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@27 @274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@27 1 0
select * from information_schema.innodb_sys_foreign_cols;
ID FOR_COL_NAME REF_COL_NAME POS
@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@27 a a 0
create or replace table u (
a int primary key,
constraint `❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎` foreign key d (a) references t (a)) engine=innodb;
select * from information_schema.innodb_sys_foreign;
ID FOR_NAME REF_NAME N_COLS TYPE
@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@27 @274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@27 @274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@27 1 0
select * from information_schema.innodb_sys_foreign_cols;
ID FOR_COL_NAME REF_COL_NAME POS
@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@274e@27 a a 0
show create table u;
Table Create Table
u CREATE TABLE `u` (
`a` int(11) NOT NULL,
PRIMARY KEY (`a`),
CONSTRAINT `❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎` FOREIGN KEY (`a`) REFERENCES `t` (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
use test;
drop database `❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎`;
4 changes: 2 additions & 2 deletions mysql-test/suite/innodb/r/foreign_null,COPY.rdiff
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--- foreign_null.result
+++ foreign_null,COPY.result
+++ foreign_null,COPY.reject
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this line changed?

@@ -139,6 +139,7 @@
ALTER TABLE `t#2` DROP INDEX f1;
SET FOREIGN_KEY_CHECKS=1;
Expand All @@ -12,7 +12,7 @@
ALTER TABLE `t#1` DROP INDEX f2;
SET FOREIGN_KEY_CHECKS=1;
ALTER TABLE `t#2` MODIFY COLUMN f1 INT NOT NULL;
+ERROR HY000: Error on rename of './test/#sql-alter' to './test/t@00232' (errno: 150 "Foreign key constraint is incorrectly formed")
+ERROR HY000: Can't create table `test`.`t#2` (errno: 150 "Foreign key constraint is incorrectly formed")
DROP TABLE `t#2`, `t#1`;
# Self referential modifying column
CREATE TABLE t1(f1 INT, f2 INT, index(f2), foreign key(f1) references t1(f2) ON UPDATE CASCADE)engine=innodb;
2 changes: 1 addition & 1 deletion mysql-test/suite/innodb/r/innodb-index.result
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ t4 CREATE TABLE `t4` (
CONSTRAINT `dc` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci
alter table t3 add constraint dc foreign key (a) references t1(a);
ERROR HY000: Can't create table `test`.`t3` (errno: 121 "Duplicate key on write or update")
ERROR HY000: Duplicate constraint name
Comment on lines 511 to +512
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message fails to include the duplicate constraint name dc.

SET FOREIGN_KEY_CHECKS=0;
alter table t3 add constraint dc foreign key (a) references t1(a);
ERROR HY000: Failed to add the foreign key constraint 'test/dc' to system tables
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/innodb/t/add_constraint.test
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ create table t2(a int, b int, key(a),key(b))engine=innodb;
alter table t2 add constraint b foreign key (b) references t1(a);
alter table t1 add constraint b1 foreign key (b) references t2(a);

--error ER_CANT_CREATE_TABLE
--error ER_DUP_CONSTRAINT_NAME_2
alter table t2 add constraint b1 foreign key (b) references t1(a);

alter table t2 drop foreign key b;
Expand Down
2 changes: 2 additions & 0 deletions mysql-test/suite/innodb/t/alter_copy_bulk.test
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ INSERT INTO t1 VALUES(3, 1);
SET STATEMENT foreign_key_checks=0 FOR
ALTER TABLE t2 ALGORITHM=COPY, ADD CONSTRAINT FOREIGN KEY(f2) REFERENCES t1(f1);
ALTER TABLE t1 ALGORITHM=COPY, FORCE;
--replace_regex /#sql-alter-[0-9a-f-]*/#sql-alter/
--error ER_NO_REFERENCED_ROW_2
ALTER TABLE t2 ALGORITHM=COPY, FORCE;
--disable_info
DROP TABLE t2, t1;
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/innodb/t/alter_partitioned.test
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ PARTITION BY RANGE(a)
(PARTITION pa VALUES LESS THAN (3),
PARTITION pb VALUES LESS THAN (5));

--error ER_FEATURE_NOT_SUPPORTED_WITH_PARTITIONING
--error ER_CANT_CREATE_TABLE
CREATE TABLE t2(a INT, FOREIGN KEY(a) REFERENCES t1(a))ENGINE=INNODB
PARTITION BY RANGE(a)
(PARTITION pa VALUES LESS THAN (2),
Expand Down
6 changes: 5 additions & 1 deletion mysql-test/suite/innodb/t/foreign_key.test
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ CONSTRAINT t2_ibfk_1 FOREIGN KEY (a) REFERENCES t1(a)) ENGINE=InnoDB;
CREATE TABLE best.t2 (a INT PRIMARY KEY, b TEXT, FULLTEXT INDEX(b),
FOREIGN KEY (a) REFERENCES test.t1(a)) ENGINE=InnoDB;
--replace_regex /Table '.*t2'/Table 't2'/
--error ER_TABLE_EXISTS_ERROR
--error ER_DUP_CONSTRAINT_NAME_2
RENAME TABLE best.t2 TO test.t2;
SHOW CREATE TABLE best.t2;
DROP DATABASE best;
Expand Down Expand Up @@ -805,6 +805,10 @@ CONSTRAINT `t2_ibfk_2` FOREIGN KEY (f1) REFERENCES t1(f1) ON DELETE CASCADE

SET FOREIGN_KEY_CHECKS=0;
ALTER TABLE t2 DROP PRIMARY KEY, ADD PRIMARY KEY(f3), ALGORITHM=INPLACE;
--disable_query_log
# This warning was missing and it appears due to ALTER creating and renaming FKs for backup/tmp tables
call mtr.add_suppression("InnoDB: In ALTER TABLE `test`.`t1` has or is referenced in foreign key.*");
--enable_query_log
ALTER TABLE t2 DROP INDEX `f2`, ALGORITHM=COPY;
SHOW CREATE TABLE t2;
--error ER_TABLE_EXISTS_ERROR
Expand Down
47 changes: 46 additions & 1 deletion mysql-test/suite/innodb/t/foreign_key_not_windows.test
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,43 @@ CREATE TABLE t (a INT PRIMARY KEY) ENGINE=InnoDB;
# corresponding to the 51 characters below: 5*51=255.
let $d255=###################################################;
let $d250=##################################################;
let $d245=#####################;
# FIXME: MDEV-29258
# let $d245=#################################################;
--replace_result $d255 d255
eval CREATE DATABASE `$d255`;

--replace_result $d255 d255
--error ER_IDENT_CAUSES_TOO_LONG_PATH
eval CREATE TABLE `$d255`.`$d255`
(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB;

--replace_result $d255 d255
--error ER_IDENT_CAUSES_TOO_LONG_PATH
eval CREATE OR REPLACE TABLE `$d255`.`$d255`
(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB;

--replace_result $d255 d255
--error ER_IDENT_CAUSES_TOO_LONG_PATH
eval CREATE TABLE `$d255`.`_$d250`
(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB;

--replace_result $d255 d255
--error ER_IDENT_CAUSES_TOO_LONG_PATH
eval CREATE OR REPLACE TABLE `$d255`.`_$d250`
(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB;

--replace_result $d255 d255
eval CREATE TABLE `$d255`.`$d250`
(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB;

--replace_result $d255 d255 $d245 d245
eval CREATE OR REPLACE TABLE `$d255`.`$d245`
(a INT PRIMARY KEY, FOREIGN KEY(a) REFERENCES test.t(a)) ENGINE=InnoDB;

--replace_result $d255 d255 $d245 d245
eval DROP TABLE `$d255`.`$d245`;

--echo #
--echo # MDEV-29258 Failing assertion for name length on RENAME TABLE
--echo #
Expand All @@ -53,7 +76,6 @@ eval DROP TABLE `$d255`.`$d250`;
eval RENAME TABLE `$d255`.`$d245` TO `$d255`.`$d250`;
--replace_result $d250 d250 $d255 d255
eval RENAME TABLE `$d255`.`$d250` TO a;
--replace_result $d255 d255
DROP TABLE a,t;

--echo #
Expand All @@ -75,3 +97,26 @@ DROP TABLE u;
eval DROP DATABASE `$d255`;

--echo # End of 10.3 tests

--echo #
--echo # MDEV-28933 CREATE OR REPLACE fails to recreate same constraint name
--echo #
set names utf8;
let $d= `select repeat('❎', 45)`;
let $t= `select repeat('❎', 64)`;
eval create database `$d`;
eval use `$d`;
create table t (a int primary key) engine=innodb;
eval create table u (
a int primary key,
constraint `$t` foreign key d (a) references t (a)) engine=innodb;
select * from information_schema.innodb_sys_foreign;
select * from information_schema.innodb_sys_foreign_cols;
eval create or replace table u (
a int primary key,
constraint `$t` foreign key d (a) references t (a)) engine=innodb;
select * from information_schema.innodb_sys_foreign;
select * from information_schema.innodb_sys_foreign_cols;
show create table u;
use test;
eval drop database `$d`;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing an --echo # End of 11.x tests marker.

4 changes: 3 additions & 1 deletion mysql-test/suite/innodb/t/foreign_null.test
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,11 @@ eval ALTER TABLE `t#2` DROP INDEX f1,ALGORITHM=$algorithm;
SET FOREIGN_KEY_CHECKS=1;

let $error_code=0;
let $error_code2=0;
if ($algorithm == "COPY")
{
let $error_code= ER_ERROR_ON_RENAME;
let $error_code2= ER_CANT_CREATE_TABLE;
}

--replace_regex /#sql-alter-[0-9a-f_\-]*/#sql-alter/
Expand All @@ -207,7 +209,7 @@ SET FOREIGN_KEY_CHECKS=1;

--replace_regex /#sql-alter-[0-9a-f_\-]*/#sql-alter/
replace_result ,ALGORITHM=COPY '' ,ALGORITHM=INPLACE '' $MYSQLD_DATADIR ./;
--error $error_code
--error $error_code2
eval ALTER TABLE `t#2` MODIFY COLUMN f1 INT NOT NULL,ALGORITHM=$algorithm;
DROP TABLE `t#2`, `t#1`;

Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/innodb/t/innodb-index.test
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ show create table t4;
# Embedded server doesn't chdir to data directory
--replace_result $MYSQLD_DATADIR ./ master-data/ ''
# a foreign key 'test/dc' already exists
--error ER_CANT_CREATE_TABLE
--error ER_DUP_CONSTRAINT_NAME_2
alter table t3 add constraint dc foreign key (a) references t1(a);
SET FOREIGN_KEY_CHECKS=0;
--error ER_FK_FAIL_ADD_SYSTEM
Expand Down
2 changes: 1 addition & 1 deletion mysql-test/suite/parts/r/alter_table.result
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ partition p1 values in (12, 13, 14),
partition p2 values in (52, 53, 54));
insert tp values (12), (2), (3), (4);
alter table tp exchange partition p0 with table t;
ERROR HY000: Table has no partition for value 0
ERROR HY000: Table has no partition for value 1
alter table tp exchange partition p0 with table t without validation;
FOUND 8 /Table `test`.`tp` was altered WITHOUT VALIDATION: the table might be corrupted/ in mysqld.1.err
select * from t;
Expand Down
Loading