From 97e112fb82dd84cc4e48f56969555851a6e19172 Mon Sep 17 00:00:00 2001 From: Sergey Vojtovich Date: Mon, 15 Jul 2024 21:47:19 +0400 Subject: [PATCH] VECTOR indexes support for RENAME TABLE Rename high-level indexes along with a table. --- mysql-test/main/vector.result | 32 ++++++++++++++++++++ mysql-test/main/vector.test | 16 ++++++++++ mysql-test/suite/archive/discover.result | 2 ++ sql/sql_table.cc | 37 ++++++++++++++++++++++++ 4 files changed, 87 insertions(+) diff --git a/mysql-test/main/vector.result b/mysql-test/main/vector.result index 7a3b9c2f451..67f0f1090db 100644 --- a/mysql-test/main/vector.result +++ b/mysql-test/main/vector.result @@ -321,3 +321,35 @@ t1 CREATE TABLE `t1` ( ) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci drop table t1; db.opt +# Test RENAME TABLE with vector index +create table t1 (id int auto_increment primary key, v blob not null, vector index (v)) engine=MyISAM; +db.opt +t1#i#01.MYD +t1#i#01.MYI +t1.MYD +t1.MYI +t1.frm +rename table t1 to t2; +db.opt +t2#i#01.MYD +t2#i#01.MYI +t2.MYD +t2.MYI +t2.frm +create database test1; +rename table test.t2 to test1.t1; +db.opt +t1#i#01.MYD +t1#i#01.MYI +t1.MYD +t1.MYI +t1.frm +rename table test1.t2 to test1.t1; +ERROR 42S02: Table 'test1.t2' doesn't exist +db.opt +t1#i#01.MYI +t1.MYD +t1.MYI +t1.frm +drop database test1; +db.opt diff --git a/mysql-test/main/vector.test b/mysql-test/main/vector.test index d71e8dc19ce..f4e81940718 100644 --- a/mysql-test/main/vector.test +++ b/mysql-test/main/vector.test @@ -121,3 +121,19 @@ replace_result InnoDB MyISAM; show create table t1; drop table t1; list_files $datadir/test; + +--echo # Test RENAME TABLE with vector index +create table t1 (id int auto_increment primary key, v blob not null, vector index (v)) engine=MyISAM; +list_files $datadir/test; +rename table t1 to t2; +list_files $datadir/test; +create database test1; +rename table test.t2 to test1.t1; +list_files $datadir/test1; + +remove_file $datadir/test1/t1#i#01.MYD; +--error ER_NO_SUCH_TABLE +rename table test1.t2 to test1.t1; +list_files $datadir/test1; +drop database test1; +list_files $datadir/test; diff --git a/mysql-test/suite/archive/discover.result b/mysql-test/suite/archive/discover.result index c216a37e71e..d1bc1262542 100644 --- a/mysql-test/suite/archive/discover.result +++ b/mysql-test/suite/archive/discover.result @@ -65,6 +65,7 @@ flush tables; rename table t2 to t0; db.opt t0.ARZ +t0.frm t1.ARZ t1.frm # @@ -83,6 +84,7 @@ flush tables; drop table t1; db.opt t0.ARZ +t0.frm # # discover of table non-existence on drop # diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 5edcd9cc683..be0c76ffd3c 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -5389,6 +5389,43 @@ mysql_rename_table(handlerton *base, const LEX_CSTRING *old_db, } else log_query= true; + + /* Rename high-level indexes */ + if (file && !error) + { + char idx_from[FN_REFLEN + 1], idx_to[FN_REFLEN + 1]; + char *idx_from_end= strmov(idx_from, from_base); + char *idx_to_end= strmov(idx_to, to_base); + TABLE_SHARE share; + + init_tmp_table_share(thd, &share, new_db->str, 0, new_name->str, to, 1); + if (!open_table_def(thd, &share, GTS_TABLE | GTS_USE_DISCOVERY)) + { + for (uint i= share.keys; i < share.total_keys; i++) + { + my_snprintf(idx_from_end, HLINDEX_BUF_LEN, HLINDEX_TEMPLATE, i); + my_snprintf(idx_to_end, HLINDEX_BUF_LEN, HLINDEX_TEMPLATE, i); + if ((error= file->ha_rename_table(idx_from, idx_to))) + { + for (; i >= share.keys; i--) + { + my_snprintf(idx_from_end, HLINDEX_BUF_LEN, HLINDEX_TEMPLATE, i); + my_snprintf(idx_to_end, HLINDEX_BUF_LEN, HLINDEX_TEMPLATE, i); + file->ha_rename_table(idx_to, idx_from); + } + file->ha_rename_table(to_base, from_base); + rename_file_ext(to, from, reg_ext); + } + } + } + else + { + file->ha_rename_table(to_base, from_base); + rename_file_ext(to, from, reg_ext); + error= 1; + } + free_table_share(&share); + } } if (!error && log_query && !(flags & (FN_TO_IS_TMP | FN_FROM_IS_TMP))) {