Skip to content

Commit 347f6d0

Browse files
committed
Merge 10.7 into 10.8
2 parents 4b14874 + c669e76 commit 347f6d0

File tree

4 files changed

+66
-11
lines changed

4 files changed

+66
-11
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
@@ -2926,15 +2926,19 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
29262926
Foreign_key *fk_key= (Foreign_key*) key;
29272927
if (fk_key->validate(alter_info->create_list))
29282928
DBUG_RETURN(TRUE);
2929-
if (fk_key->ref_columns.elements &&
2930-
fk_key->ref_columns.elements != fk_key->columns.elements)
2929+
if (fk_key->ref_columns.elements)
29312930
{
2932-
my_error(ER_WRONG_FK_DEF, MYF(0),
2933-
(fk_key->name.str ? fk_key->name.str :
2934-
"foreign key without name"),
2935-
ER_THD(thd, ER_KEY_REF_DO_NOT_MATCH_TABLE_REF));
2936-
DBUG_RETURN(TRUE);
2931+
if (fk_key->ref_columns.elements != fk_key->columns.elements)
2932+
{
2933+
my_error(ER_WRONG_FK_DEF, MYF(0),
2934+
(fk_key->name.str ? fk_key->name.str :
2935+
"foreign key without name"),
2936+
ER_THD(thd, ER_KEY_REF_DO_NOT_MATCH_TABLE_REF));
2937+
DBUG_RETURN(TRUE);
2938+
}
29372939
}
2940+
else
2941+
fk_key->ref_columns.append(&fk_key->columns);
29382942
continue;
29392943
}
29402944
(*key_count)++;

storage/innobase/buf/buf0buf.cc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
Copyright (c) 1995, 2018, Oracle and/or its affiliates. All Rights Reserved.
44
Copyright (c) 2008, Google Inc.
5-
Copyright (c) 2013, 2021, MariaDB Corporation.
5+
Copyright (c) 2013, 2022, MariaDB Corporation.
66
77
Portions of this file contain modifications contributed and copyrighted by
88
Google, Inc. Those modifications are gratefully acknowledged and are described
@@ -2232,6 +2232,10 @@ void buf_page_free(fil_space_t *space, uint32_t page, mtr_t *mtr)
22322232
}
22332233

22342234
block->page.lock.x_lock();
2235+
#ifdef BTR_CUR_HASH_ADAPT
2236+
if (block->index)
2237+
btr_search_drop_page_hash_index(block);
2238+
#endif /* BTR_CUR_HASH_ADAPT */
22352239
block->page.set_freed(block->page.state());
22362240
mtr->memo_push(block, MTR_MEMO_PAGE_X_FIX);
22372241
}
@@ -2943,9 +2947,12 @@ buf_page_get_gen(
29432947
{
29442948
if (buf_block_t *block= recv_sys.recover(page_id))
29452949
{
2946-
ut_ad(!block->page.is_io_fixed());
29472950
/* Recovery is a special case; we fix() before acquiring lock. */
2948-
const auto s= block->page.fix();
2951+
auto s= block->page.fix();
2952+
ut_ad(s >= buf_page_t::FREED);
2953+
/* The block may be write-fixed at this point because we are not
2954+
holding a lock, but it must not be read-fixed. */
2955+
ut_ad(s < buf_page_t::READ_FIX || s >= buf_page_t::WRITE_FIX);
29492956
if (err)
29502957
*err= DB_SUCCESS;
29512958
const bool must_merge= allow_ibuf_merge &&
@@ -2957,7 +2964,10 @@ buf_page_get_gen(
29572964
page_is_leaf(block->page.frame))
29582965
{
29592966
block->page.lock.x_lock();
2960-
if (block->page.is_freed())
2967+
s= block->page.state();
2968+
ut_ad(s > buf_page_t::FREED);
2969+
ut_ad(s < buf_page_t::READ_FIX);
2970+
if (s < buf_page_t::UNFIXED)
29612971
ut_ad(mode == BUF_GET_POSSIBLY_FREED || mode == BUF_PEEK_IF_IN_POOL);
29622972
else
29632973
{

0 commit comments

Comments
 (0)