summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Malyavin <nikitamalyavin@gmail.com>2023-03-17 22:25:05 +0300
committerNikita Malyavin <nikitamalyavin@gmail.com>2023-03-17 22:25:05 +0300
commit8f8eb8a2cbeb42969af56945d5f722fa297862d1 (patch)
tree4abc7e8d730aff8f92b951e55e541d50fa2e3840
parentbd2249890383e5f0844b2247b8e145220277dc01 (diff)
downloadmariadb-git-bb-10.6-MDEV-29181.tar.gz
fix TBR-1731bb-10.6-MDEV-29181
-rw-r--r--mysql-test/suite/innodb/r/foreign-keys.result10
-rw-r--r--mysql-test/suite/innodb/t/foreign-keys.test12
-rw-r--r--storage/innobase/dict/dict0dict.cc8
-rw-r--r--storage/innobase/handler/handler0alter.cc2
-rw-r--r--storage/innobase/include/dict0dict.h8
5 files changed, 33 insertions, 7 deletions
diff --git a/mysql-test/suite/innodb/r/foreign-keys.result b/mysql-test/suite/innodb/r/foreign-keys.result
index 5b88067f2f2..ff87f4c096e 100644
--- a/mysql-test/suite/innodb/r/foreign-keys.result
+++ b/mysql-test/suite/innodb/r/foreign-keys.result
@@ -247,3 +247,13 @@ INSERT INTO parent (a) VALUES (1);
DELETE FROM parent;
DROP TABLE child;
DROP TABLE parent;
+# TBR-1731
+CREATE TABLE parentA (col1 INT PRIMARY KEY) ENGINE = InnoDB ;
+CREATE TABLE childA (col1 INT PRIMARY KEY, col2 INT,
+col1_g INT GENERATED ALWAYS AS (col1),
+FOREIGN KEY (col1) REFERENCES parentA (col1))
+ENGINE = InnoDB ;
+RENAME TABLE parentA TO test.parent, childA TO test.child;
+ALTER TABLE test.child CHANGE COLUMN col2 col2_other_name INT;
+DROP TABLE child;
+DROP TABLE parent;
diff --git a/mysql-test/suite/innodb/t/foreign-keys.test b/mysql-test/suite/innodb/t/foreign-keys.test
index 96653a112de..2700f9c7d6e 100644
--- a/mysql-test/suite/innodb/t/foreign-keys.test
+++ b/mysql-test/suite/innodb/t/foreign-keys.test
@@ -282,3 +282,15 @@ DELETE FROM parent;
DROP TABLE child;
DROP TABLE parent;
+
+--echo # TBR-1731
+CREATE TABLE parentA (col1 INT PRIMARY KEY) ENGINE = InnoDB ;
+CREATE TABLE childA (col1 INT PRIMARY KEY, col2 INT,
+ col1_g INT GENERATED ALWAYS AS (col1),
+ FOREIGN KEY (col1) REFERENCES parentA (col1))
+ ENGINE = InnoDB ;
+RENAME TABLE parentA TO test.parent, childA TO test.child;
+ALTER TABLE test.child CHANGE COLUMN col2 col2_other_name INT;
+DROP TABLE child;
+DROP TABLE parent;
+
diff --git a/storage/innobase/dict/dict0dict.cc b/storage/innobase/dict/dict0dict.cc
index 2b90c551270..9d71a6db1cd 100644
--- a/storage/innobase/dict/dict0dict.cc
+++ b/storage/innobase/dict/dict0dict.cc
@@ -1852,8 +1852,10 @@ dict_table_change_id_in_cache(
@param[in,out] table cached table definition to be evicted
@param[in] lru whether this is part of least-recently-used eviction
@param[in] keep whether to keep (not free) the object
-@tparam drop indicates whether the intention is to drop the table */
-template <bool drop>
+@tparam drop_foreigns
+ indicates whether dropping the foreign key metadata
+ is being forced, or not */
+template <bool drop_foreigns>
void dict_sys_t::remove(dict_table_t* table, bool lru, bool keep)
{
dict_index_t* index;
@@ -1865,7 +1867,7 @@ void dict_sys_t::remove(dict_table_t* table, bool lru, bool keep)
ut_ad(table->magic_n == DICT_TABLE_MAGIC_N);
/* Remove the foreign constraints from the cache */
- if (drop) {
+ if (drop_foreigns) {
std::for_each(table->foreign_set.begin(),
table->foreign_set.end(),
dict_foreign_remove_partial());
diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc
index 6a8986d76d2..017f9b1e7a4 100644
--- a/storage/innobase/handler/handler0alter.cc
+++ b/storage/innobase/handler/handler0alter.cc
@@ -10373,7 +10373,7 @@ static dict_table_t *innobase_reload_table(THD *thd, dict_table_t *table,
const table_id_t id= table->id;
table->release();
- dict_sys.remove(table);
+ dict_sys.remove<true>(table);
return dict_table_open_on_id(id, true, DICT_TABLE_OP_NORMAL);
}
diff --git a/storage/innobase/include/dict0dict.h b/storage/innobase/include/dict0dict.h
index fecbe1f0f22..7078047c9cc 100644
--- a/storage/innobase/include/dict0dict.h
+++ b/storage/innobase/include/dict0dict.h
@@ -1453,9 +1453,11 @@ public:
inline void add(dict_table_t* table);
/** Remove a table definition from the data dictionary cache.
@param[in,out] table cached table definition to be evicted
- @param[in] lru whether this is part of least-recently-used evictiono
- @param[in] keep whether to keep (not free) the object */
- template <bool drop=false>
+ @param[in] lru whether this is part of least-recently-used eviction
+ @param[in] keep whether to keep (not free) the object
+ @tparam drop_foreigns indicates whether dropping the foreign key metadata
+ is being forced, or not */
+ template <bool drop_foreigns=false>
void remove(dict_table_t* table, bool lru = false, bool keep = false);
#ifdef UNIV_DEBUG