Skip to content

Commit 16b87f9

Browse files
committed
Merge 10.5 into 10.6
2 parents e6a0611 + c104a01 commit 16b87f9

File tree

4 files changed

+56
-7
lines changed

4 files changed

+56
-7
lines changed

mysql-test/suite/innodb/r/foreign_key.result

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,29 @@ create or replace table t1 (a varchar(4096) unique) engine=innodb;
897897
create or replace table t2 (pk int primary key, a varchar(4096) unique, foreign key(a) references t1(a) on update cascade) engine=innodb;
898898
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
899899
drop table t1;
900+
#
901+
# MDEV-26824 Can't add foreign key with empty referenced columns list
902+
#
903+
create table t2(a int primary key) engine=innodb;
904+
create table t1(a int primary key, b int) engine=innodb;
905+
alter table t2 add foreign key(a) references t1(a, b);
906+
ERROR 42000: Incorrect foreign key definition for 'foreign key without name': Key reference and table reference don't match
907+
create or replace table t1(a tinyint primary key) engine innodb;
908+
alter table t2 add foreign key(a) references t1;
909+
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
910+
create or replace table t1(b int primary key) engine innodb;
911+
alter table t2 add foreign key(a) references t1;
912+
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
913+
create or replace table t1(a int primary key, b int) engine innodb;
914+
alter table t2 add foreign key(a) references t1;
915+
show create table t2;
916+
Table Create Table
917+
t2 CREATE TABLE `t2` (
918+
`a` int(11) NOT NULL,
919+
PRIMARY KEY (`a`),
920+
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)
921+
) ENGINE=InnoDB DEFAULT CHARSET=latin1
922+
drop tables t2, t1;
900923
# End of 10.5 tests
901924
#
902925
# MDEV-26554 Table-rebuilding DDL on parent table causes crash

mysql-test/suite/innodb/t/foreign_key.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,24 @@ create or replace table t2 (pk int primary key, a varchar(4096) unique, foreign
901901

902902
drop table t1;
903903

904+
--echo #
905+
--echo # MDEV-26824 Can't add foreign key with empty referenced columns list
906+
--echo #
907+
create table t2(a int primary key) engine=innodb;
908+
create table t1(a int primary key, b int) engine=innodb;
909+
--error ER_WRONG_FK_DEF
910+
alter table t2 add foreign key(a) references t1(a, b);
911+
create or replace table t1(a tinyint primary key) engine innodb;
912+
--error ER_CANT_CREATE_TABLE
913+
alter table t2 add foreign key(a) references t1;
914+
create or replace table t1(b int primary key) engine innodb;
915+
--error ER_CANT_CREATE_TABLE
916+
alter table t2 add foreign key(a) references t1;
917+
create or replace table t1(a int primary key, b int) engine innodb;
918+
alter table t2 add foreign key(a) references t1;
919+
show create table t2;
920+
drop tables t2, t1;
921+
904922
--echo # End of 10.5 tests
905923

906924
--echo #

sql/sql_table.cc

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2825,15 +2825,19 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
28252825
Foreign_key *fk_key= (Foreign_key*) key;
28262826
if (fk_key->validate(alter_info->create_list))
28272827
DBUG_RETURN(TRUE);
2828-
if (fk_key->ref_columns.elements &&
2829-
fk_key->ref_columns.elements != fk_key->columns.elements)
2828+
if (fk_key->ref_columns.elements)
28302829
{
2831-
my_error(ER_WRONG_FK_DEF, MYF(0),
2832-
(fk_key->name.str ? fk_key->name.str :
2833-
"foreign key without name"),
2834-
ER_THD(thd, ER_KEY_REF_DO_NOT_MATCH_TABLE_REF));
2835-
DBUG_RETURN(TRUE);
2830+
if (fk_key->ref_columns.elements != fk_key->columns.elements)
2831+
{
2832+
my_error(ER_WRONG_FK_DEF, MYF(0),
2833+
(fk_key->name.str ? fk_key->name.str :
2834+
"foreign key without name"),
2835+
ER_THD(thd, ER_KEY_REF_DO_NOT_MATCH_TABLE_REF));
2836+
DBUG_RETURN(TRUE);
2837+
}
28362838
}
2839+
else
2840+
fk_key->ref_columns.append(&fk_key->columns);
28372841
continue;
28382842
}
28392843
(*key_count)++;

storage/innobase/buf/buf0buf.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2238,6 +2238,10 @@ void buf_page_free(fil_space_t *space, uint32_t page, mtr_t *mtr)
22382238
}
22392239

22402240
block->page.lock.x_lock();
2241+
#ifdef BTR_CUR_HASH_ADAPT
2242+
if (block->index)
2243+
btr_search_drop_page_hash_index(block);
2244+
#endif /* BTR_CUR_HASH_ADAPT */
22412245
block->page.set_freed(block->page.state());
22422246
mtr->memo_push(block, MTR_MEMO_PAGE_X_FIX);
22432247
}

0 commit comments

Comments
 (0)