Skip to content

Commit

Permalink
Merge 10.7 into 10.8
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-m committed Jan 14, 2022
2 parents 4b14874 + c669e76 commit 347f6d0
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 11 deletions.
23 changes: 23 additions & 0 deletions mysql-test/suite/innodb/r/foreign_key.result
Original file line number Diff line number Diff line change
Expand Up @@ -897,6 +897,29 @@ create or replace table t1 (a varchar(4096) unique) engine=innodb;
create or replace table t2 (pk int primary key, a varchar(4096) unique, foreign key(a) references t1(a) on update cascade) engine=innodb;
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
drop table t1;
#
# MDEV-26824 Can't add foreign key with empty referenced columns list
#
create table t2(a int primary key) engine=innodb;
create table t1(a int primary key, b int) engine=innodb;
alter table t2 add foreign key(a) references t1(a, b);
ERROR 42000: Incorrect foreign key definition for 'foreign key without name': Key reference and table reference don't match
create or replace table t1(a tinyint primary key) engine innodb;
alter table t2 add foreign key(a) references t1;
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
create or replace table t1(b int primary key) engine innodb;
alter table t2 add foreign key(a) references t1;
ERROR HY000: Can't create table `test`.`t2` (errno: 150 "Foreign key constraint is incorrectly formed")
create or replace table t1(a int primary key, b int) engine innodb;
alter table t2 add foreign key(a) references t1;
show create table t2;
Table Create Table
t2 CREATE TABLE `t2` (
`a` int(11) NOT NULL,
PRIMARY KEY (`a`),
CONSTRAINT `t2_ibfk_1` FOREIGN KEY (`a`) REFERENCES `t1` (`a`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
drop tables t2, t1;
# End of 10.5 tests
#
# MDEV-26554 Table-rebuilding DDL on parent table causes crash
Expand Down
18 changes: 18 additions & 0 deletions mysql-test/suite/innodb/t/foreign_key.test
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,24 @@ create or replace table t2 (pk int primary key, a varchar(4096) unique, foreign

drop table t1;

--echo #
--echo # MDEV-26824 Can't add foreign key with empty referenced columns list
--echo #
create table t2(a int primary key) engine=innodb;
create table t1(a int primary key, b int) engine=innodb;
--error ER_WRONG_FK_DEF
alter table t2 add foreign key(a) references t1(a, b);
create or replace table t1(a tinyint primary key) engine innodb;
--error ER_CANT_CREATE_TABLE
alter table t2 add foreign key(a) references t1;
create or replace table t1(b int primary key) engine innodb;
--error ER_CANT_CREATE_TABLE
alter table t2 add foreign key(a) references t1;
create or replace table t1(a int primary key, b int) engine innodb;
alter table t2 add foreign key(a) references t1;
show create table t2;
drop tables t2, t1;

--echo # End of 10.5 tests

--echo #
Expand Down
18 changes: 11 additions & 7 deletions sql/sql_table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2926,15 +2926,19 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info,
Foreign_key *fk_key= (Foreign_key*) key;
if (fk_key->validate(alter_info->create_list))
DBUG_RETURN(TRUE);
if (fk_key->ref_columns.elements &&
fk_key->ref_columns.elements != fk_key->columns.elements)
if (fk_key->ref_columns.elements)
{
my_error(ER_WRONG_FK_DEF, MYF(0),
(fk_key->name.str ? fk_key->name.str :
"foreign key without name"),
ER_THD(thd, ER_KEY_REF_DO_NOT_MATCH_TABLE_REF));
DBUG_RETURN(TRUE);
if (fk_key->ref_columns.elements != fk_key->columns.elements)
{
my_error(ER_WRONG_FK_DEF, MYF(0),
(fk_key->name.str ? fk_key->name.str :
"foreign key without name"),
ER_THD(thd, ER_KEY_REF_DO_NOT_MATCH_TABLE_REF));
DBUG_RETURN(TRUE);
}
}
else
fk_key->ref_columns.append(&fk_key->columns);
continue;
}
(*key_count)++;
Expand Down
18 changes: 14 additions & 4 deletions storage/innobase/buf/buf0buf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Copyright (c) 1995, 2018, Oracle and/or its affiliates. All Rights Reserved.
Copyright (c) 2008, Google Inc.
Copyright (c) 2013, 2021, MariaDB Corporation.
Copyright (c) 2013, 2022, MariaDB Corporation.
Portions of this file contain modifications contributed and copyrighted by
Google, Inc. Those modifications are gratefully acknowledged and are described
Expand Down Expand Up @@ -2232,6 +2232,10 @@ void buf_page_free(fil_space_t *space, uint32_t page, mtr_t *mtr)
}

block->page.lock.x_lock();
#ifdef BTR_CUR_HASH_ADAPT
if (block->index)
btr_search_drop_page_hash_index(block);
#endif /* BTR_CUR_HASH_ADAPT */
block->page.set_freed(block->page.state());
mtr->memo_push(block, MTR_MEMO_PAGE_X_FIX);
}
Expand Down Expand Up @@ -2943,9 +2947,12 @@ buf_page_get_gen(
{
if (buf_block_t *block= recv_sys.recover(page_id))
{
ut_ad(!block->page.is_io_fixed());
/* Recovery is a special case; we fix() before acquiring lock. */
const auto s= block->page.fix();
auto s= block->page.fix();
ut_ad(s >= buf_page_t::FREED);
/* The block may be write-fixed at this point because we are not
holding a lock, but it must not be read-fixed. */
ut_ad(s < buf_page_t::READ_FIX || s >= buf_page_t::WRITE_FIX);
if (err)
*err= DB_SUCCESS;
const bool must_merge= allow_ibuf_merge &&
Expand All @@ -2957,7 +2964,10 @@ buf_page_get_gen(
page_is_leaf(block->page.frame))
{
block->page.lock.x_lock();
if (block->page.is_freed())
s= block->page.state();
ut_ad(s > buf_page_t::FREED);
ut_ad(s < buf_page_t::READ_FIX);
if (s < buf_page_t::UNFIXED)
ut_ad(mode == BUF_GET_POSSIBLY_FREED || mode == BUF_PEEK_IF_IN_POOL);
else
{
Expand Down

0 comments on commit 347f6d0

Please sign in to comment.