summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarko Mäkelä <marko.makela@mariadb.com>2022-01-14 19:47:33 +0200
committerMarko Mäkelä <marko.makela@mariadb.com>2022-01-14 19:47:33 +0200
commit347f6d01e3b570dce49aa1ab42cb83021905a14d (patch)
tree2c723fb5bf75590b5ff8780ece1a2b546fc3eefb
parent4b14874c2809a8b0f2d04a969132e062fb22b145 (diff)
parentc669e764d86a5b575df41d287947816878e21697 (diff)
downloadmariadb-git-347f6d01e3b570dce49aa1ab42cb83021905a14d.tar.gz
Merge 10.7 into 10.8
-rw-r--r--mysql-test/suite/innodb/r/foreign_key.result23
-rw-r--r--mysql-test/suite/innodb/t/foreign_key.test18
-rw-r--r--sql/sql_table.cc18
-rw-r--r--storage/innobase/buf/buf0buf.cc18
4 files changed, 66 insertions, 11 deletions
diff --git a/mysql-test/suite/innodb/r/foreign_key.result b/mysql-test/suite/innodb/r/foreign_key.result
index 509f13715b8..2ccdfe20d0e 100644
--- a/mysql-test/suite/innodb/r/foreign_key.result
+++ b/mysql-test/suite/innodb/r/foreign_key.result
@@ -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
diff --git a/mysql-test/suite/innodb/t/foreign_key.test b/mysql-test/suite/innodb/t/foreign_key.test
index 363aa66237b..07601adffd9 100644
--- a/mysql-test/suite/innodb/t/foreign_key.test
+++ b/mysql-test/suite/innodb/t/foreign_key.test
@@ -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 #
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index a9ad8b7720d..7d9fd0c516d 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -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)++;
diff --git a/storage/innobase/buf/buf0buf.cc b/storage/innobase/buf/buf0buf.cc
index 37fbd4dd853..65e7ae50f9e 100644
--- a/storage/innobase/buf/buf0buf.cc
+++ b/storage/innobase/buf/buf0buf.cc
@@ -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
@@ -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);
}
@@ -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 &&
@@ -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
{