diff --git a/mysql-test/main/vector,myisam.rdiff b/mysql-test/main/vector,myisam.rdiff index 1a14c837bb3..619acdb1d95 100644 --- a/mysql-test/main/vector,myisam.rdiff +++ b/mysql-test/main/vector,myisam.rdiff @@ -73,3 +73,220 @@ -t1.ibd drop database test1; db.opt +@@ -387,9 +387,11 @@ + # ADD/DROP COLUMN, ALGORITHM=COPY + alter table t1 add column a int, algorithm=copy; + db.opt +-t1#i#01.ibd ++t1#i#01.MYD ++t1#i#01.MYI ++t1.MYD ++t1.MYI + t1.frm +-t1.ibd + show create table t1; + Table Create Table + t1 CREATE TABLE `t1` ( +@@ -398,12 +400,14 @@ + `a` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + VECTOR KEY `v` (`v`) +-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci ++) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci + alter table t1 drop column a, algorithm=copy; + db.opt +-t1#i#01.ibd ++t1#i#01.MYD ++t1#i#01.MYI ++t1.MYD ++t1.MYI + t1.frm +-t1.ibd + show create table t1; + Table Create Table + t1 CREATE TABLE `t1` ( +@@ -415,13 +415,15 @@ + `v` blob NOT NULL, + PRIMARY KEY (`id`), + VECTOR KEY `v` (`v`) +-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci ++) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci + # ADD/DROP INDEX, ALGORITHM=COPY (non-vector) + alter table t1 add index a(id), algorithm=copy; + db.opt +-t1#i#02.ibd ++t1#i#02.MYD ++t1#i#02.MYI ++t1.MYD ++t1.MYI + t1.frm +-t1.ibd + show create table t1; + Table Create Table + t1 CREATE TABLE `t1` ( +@@ -432,12 +432,14 @@ + PRIMARY KEY (`id`), + KEY `a` (`id`), + VECTOR KEY `v` (`v`) +-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci ++) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci + alter table t1 drop index a, algorithm=copy; + db.opt +-t1#i#01.ibd ++t1#i#01.MYD ++t1#i#01.MYI ++t1.MYD ++t1.MYI + t1.frm +-t1.ibd + show create table t1; + Table Create Table + t1 CREATE TABLE `t1` ( +@@ -445,13 +447,15 @@ + `v` blob NOT NULL, + PRIMARY KEY (`id`), + VECTOR KEY `v` (`v`) +-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci ++) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci + # CREATE/DROP INDEX, ALGORITHM=COPY (non-vector) + create index a on t1(id) algorithm=copy; + db.opt +-t1#i#02.ibd ++t1#i#02.MYD ++t1#i#02.MYI ++t1.MYD ++t1.MYI + t1.frm +-t1.ibd + show create table t1; + Table Create Table + t1 CREATE TABLE `t1` ( +@@ -460,12 +464,14 @@ + PRIMARY KEY (`id`), + KEY `a` (`id`), + VECTOR KEY `v` (`v`) +-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +-alter table t1 drop index a, algorithm=copy; ++) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci ++drop index a on t1; + db.opt +-t1#i#01.ibd ++t1#i#01.MYD ++t1#i#01.MYI ++t1.MYD ++t1.MYI + t1.frm +-t1.ibd + show create table t1; + Table Create Table + t1 CREATE TABLE `t1` ( +@@ -479,13 +479,15 @@ + `v` blob NOT NULL, + PRIMARY KEY (`id`), + VECTOR KEY `v` (`v`) +-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci ++) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci + # ADD/DROP COLUMN IF [NOT] EXISTS, ALGORITHM=COPY (non-vector) + alter table t1 add column if not exists a int, algorithm=copy; + db.opt +-t1#i#01.ibd ++t1#i#01.MYD ++t1#i#01.MYI ++t1.MYD ++t1.MYI + t1.frm +-t1.ibd + show create table t1; + Table Create Table + t1 CREATE TABLE `t1` ( +@@ -494,12 +496,14 @@ + `a` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + VECTOR KEY `v` (`v`) +-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci ++) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci + alter table t1 drop column if exists a, algorithm=copy; + db.opt +-t1#i#01.ibd ++t1#i#01.MYD ++t1#i#01.MYI ++t1.MYD ++t1.MYI + t1.frm +-t1.ibd + show create table t1; + Table Create Table + t1 CREATE TABLE `t1` ( +@@ -509,24 +511,27 @@ + `v` blob NOT NULL, + PRIMARY KEY (`id`), + VECTOR KEY `v` (`v`) +-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci ++) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci + # ADD/DROP INDEX, ALGORITHM=COPY (vector) + alter table t1 drop index v, algorithm=copy; + db.opt ++t1.MYD ++t1.MYI + t1.frm +-t1.ibd + show create table t1; + Table Create Table + t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `v` blob NOT NULL, + PRIMARY KEY (`id`) +-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci ++) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci + alter table t1 add vector index v(v), algorithm=copy; + db.opt +-t1#i#01.ibd ++t1#i#01.MYD ++t1#i#01.MYI ++t1.MYD ++t1.MYI + t1.frm +-t1.ibd + show create table t1; + Table Create Table + t1 CREATE TABLE `t1` ( +@@ -534,24 +539,27 @@ + `v` blob NOT NULL, + PRIMARY KEY (`id`), + VECTOR KEY `v` (`v`) +-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci ++) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci + # CREATE/DROP INDEX, ALGORITHM=COPY (vector) + alter table t1 drop index v, algorithm=copy; + db.opt ++t1.MYD ++t1.MYI + t1.frm +-t1.ibd + show create table t1; + Table Create Table + t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `v` blob NOT NULL, + PRIMARY KEY (`id`) +-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci ++) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci + create vector index v on t1(v) algorithm=copy; + db.opt +-t1#i#01.ibd ++t1#i#01.MYD ++t1#i#01.MYI ++t1.MYD ++t1.MYI + t1.frm +-t1.ibd + show create table t1; + Table Create Table + t1 CREATE TABLE `t1` ( +@@ -565,5 +567,5 @@ + `v` blob NOT NULL, + PRIMARY KEY (`id`), + VECTOR KEY `v` (`v`) +-) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci ++) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci + drop table t1; diff --git a/mysql-test/main/vector.result b/mysql-test/main/vector.result index 834caff13c4..1d55f45e7ea 100644 --- a/mysql-test/main/vector.result +++ b/mysql-test/main/vector.result @@ -470,3 +470,178 @@ set @a=vec_fromtext('[94.542572,8.735560,60.050098,74.043800,90.068710,28.212160 select vec_distance_cosine(@a, @a), vec_distance_euclidean(@a, @a); vec_distance_cosine(@a, @a) vec_distance_euclidean(@a, @a) 0 0 +# Test ALTER TABLE, CREATE/DROP INDEX +create table t1 (id int auto_increment primary key, v blob not null, vector index (v)); +insert t1 (v) values (x'e360d63ebe554f3fcdbc523f4522193f5236083d'), +(x'f511303f72224a3fdd05fe3eb22a133ffae86a3f'), +(x'f09baa3ea172763f123def3e0c7fe53e288bf33e'), +(x'b97a523f2a193e3eb4f62e3f2d23583e9dd60d3f'), +(x'f7c5df3e984b2b3e65e59d3d7376db3eac63773e'), +(x'de01453ffa486d3f10aa4d3fdd66813c71cb163f'), +(x'76edfc3e4b57243f10f8423fb158713f020bda3e'), +(x'56926c3fdf098d3e2c8c5e3d1ad4953daa9d0b3e'), +(x'7b713f3e5258323f80d1113d673b2b3f66e3583f'), +(x'6ca1d43e9df91b3fe580da3e1c247d3f147cf33e'); +# ADD/DROP COLUMN, ALGORITHM=COPY +alter table t1 add column a int, algorithm=copy; +db.opt +t1#i#01.ibd +t1.frm +t1.ibd +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `v` blob NOT NULL, + `a` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + VECTOR KEY `v` (`v`) +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +alter table t1 drop column a, algorithm=copy; +db.opt +t1#i#01.ibd +t1.frm +t1.ibd +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `v` blob NOT NULL, + PRIMARY KEY (`id`), + VECTOR KEY `v` (`v`) +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +# ADD/DROP INDEX, ALGORITHM=COPY (non-vector) +alter table t1 add index a(id), algorithm=copy; +db.opt +t1#i#02.ibd +t1.frm +t1.ibd +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `v` blob NOT NULL, + PRIMARY KEY (`id`), + KEY `a` (`id`), + VECTOR KEY `v` (`v`) +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +alter table t1 drop index a, algorithm=copy; +db.opt +t1#i#01.ibd +t1.frm +t1.ibd +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `v` blob NOT NULL, + PRIMARY KEY (`id`), + VECTOR KEY `v` (`v`) +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +# CREATE/DROP INDEX, ALGORITHM=COPY (non-vector) +create index a on t1(id) algorithm=copy; +db.opt +t1#i#02.ibd +t1.frm +t1.ibd +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `v` blob NOT NULL, + PRIMARY KEY (`id`), + KEY `a` (`id`), + VECTOR KEY `v` (`v`) +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +alter table t1 drop index a, algorithm=copy; +db.opt +t1#i#01.ibd +t1.frm +t1.ibd +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `v` blob NOT NULL, + PRIMARY KEY (`id`), + VECTOR KEY `v` (`v`) +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +# ADD/DROP COLUMN IF [NOT] EXISTS, ALGORITHM=COPY (non-vector) +alter table t1 add column if not exists a int, algorithm=copy; +db.opt +t1#i#01.ibd +t1.frm +t1.ibd +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `v` blob NOT NULL, + `a` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + VECTOR KEY `v` (`v`) +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +alter table t1 drop column if exists a, algorithm=copy; +db.opt +t1#i#01.ibd +t1.frm +t1.ibd +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `v` blob NOT NULL, + PRIMARY KEY (`id`), + VECTOR KEY `v` (`v`) +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +# ADD/DROP INDEX, ALGORITHM=COPY (vector) +alter table t1 drop index v, algorithm=copy; +db.opt +t1.frm +t1.ibd +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `v` blob NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +alter table t1 add vector index v(v), algorithm=copy; +db.opt +t1#i#01.ibd +t1.frm +t1.ibd +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `v` blob NOT NULL, + PRIMARY KEY (`id`), + VECTOR KEY `v` (`v`) +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +# CREATE/DROP INDEX, ALGORITHM=COPY (vector) +alter table t1 drop index v, algorithm=copy; +db.opt +t1.frm +t1.ibd +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `v` blob NOT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +create vector index v on t1(v) algorithm=copy; +db.opt +t1#i#01.ibd +t1.frm +t1.ibd +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `v` blob NOT NULL, + PRIMARY KEY (`id`), + VECTOR KEY `v` (`v`) +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +drop table t1; diff --git a/mysql-test/main/vector.test b/mysql-test/main/vector.test index 12ae093c1bf..ff73811d334 100644 --- a/mysql-test/main/vector.test +++ b/mysql-test/main/vector.test @@ -217,3 +217,78 @@ drop table t1; # distance to itself set @a=vec_fromtext('[94.542572,8.735560,60.050098,74.043800,90.068710,28.212160,70.854660,69.636841,35.620232,69.190628]'); select vec_distance_cosine(@a, @a), vec_distance_euclidean(@a, @a); + +--echo # Test ALTER TABLE, CREATE/DROP INDEX +create table t1 (id int auto_increment primary key, v blob not null, vector index (v)); +insert t1 (v) values (x'e360d63ebe554f3fcdbc523f4522193f5236083d'), + (x'f511303f72224a3fdd05fe3eb22a133ffae86a3f'), + (x'f09baa3ea172763f123def3e0c7fe53e288bf33e'), + (x'b97a523f2a193e3eb4f62e3f2d23583e9dd60d3f'), + (x'f7c5df3e984b2b3e65e59d3d7376db3eac63773e'), + (x'de01453ffa486d3f10aa4d3fdd66813c71cb163f'), + (x'76edfc3e4b57243f10f8423fb158713f020bda3e'), + (x'56926c3fdf098d3e2c8c5e3d1ad4953daa9d0b3e'), + (x'7b713f3e5258323f80d1113d673b2b3f66e3583f'), + (x'6ca1d43e9df91b3fe580da3e1c247d3f147cf33e'); + +--echo # ADD/DROP COLUMN, ALGORITHM=COPY +alter table t1 add column a int, algorithm=copy; +list_files $datadir/test; +show create table t1; +alter table t1 drop column a, algorithm=copy; +list_files $datadir/test; +show create table t1; + +--echo # ADD/DROP INDEX, ALGORITHM=COPY (non-vector) +alter table t1 add index a(id), algorithm=copy; +list_files $datadir/test; +show create table t1; +alter table t1 drop index a, algorithm=copy; +list_files $datadir/test; +show create table t1; + +--echo # CREATE/DROP INDEX, ALGORITHM=COPY (non-vector) +create index a on t1(id) algorithm=copy; +list_files $datadir/test; +show create table t1; +if ($MTR_COMBINATION_MYISAM) { +drop index a on t1; +} +if ($MTR_COMBINATION_INNODB) { +alter table t1 drop index a, algorithm=copy; +} +list_files $datadir/test; +show create table t1; + +--echo # ADD/DROP COLUMN IF [NOT] EXISTS, ALGORITHM=COPY (non-vector) +alter table t1 add column if not exists a int, algorithm=copy; +list_files $datadir/test; +show create table t1; +alter table t1 drop column if exists a, algorithm=copy; +list_files $datadir/test; +show create table t1; + +--echo # ADD/DROP INDEX, ALGORITHM=COPY (vector) +alter table t1 drop index v, algorithm=copy; +list_files $datadir/test; +show create table t1; + +alter table t1 add vector index v(v), algorithm=copy; +list_files $datadir/test; +show create table t1; + +--echo # CREATE/DROP INDEX, ALGORITHM=COPY (vector) +if ($MTR_COMBINATION_MYISAM) { +# To be fixed to: drop index v on t1; +alter table t1 drop index v, algorithm=copy; +} +if ($MTR_COMBINATION_INNODB) { +alter table t1 drop index v, algorithm=copy; +} +list_files $datadir/test; +show create table t1; +create vector index v on t1(v) algorithm=copy; +list_files $datadir/test; +show create table t1; + +drop table t1; diff --git a/sql/sql_base.cc b/sql/sql_base.cc index c0070eaf7f6..127574aec17 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -9845,10 +9845,12 @@ int TABLE::hlindex_open(uint nr) DBUG_ASSERT(nr == s->keys); if (!hlindex) { - mysql_mutex_lock(&s->LOCK_share); + if (s->tmp_table == NO_TMP_TABLE) + mysql_mutex_lock(&s->LOCK_share); if (!s->hlindex) { - mysql_mutex_unlock(&s->LOCK_share); + if (s->tmp_table == NO_TMP_TABLE) + mysql_mutex_unlock(&s->LOCK_share); TABLE_SHARE *share; char *path= NULL; size_t path_len= s->normalized_path.length + HLINDEX_BUF_LEN; @@ -9872,20 +9874,26 @@ int TABLE::hlindex_open(uint nr) return 1; } - mysql_mutex_lock(&s->LOCK_share); + if (s->tmp_table == NO_TMP_TABLE) + mysql_mutex_lock(&s->LOCK_share); if (!s->hlindex) { s->hlindex= share; - mysql_mutex_unlock(&s->LOCK_share); + if (s->tmp_table == NO_TMP_TABLE) + mysql_mutex_unlock(&s->LOCK_share); } else { - mysql_mutex_unlock(&s->LOCK_share); + if (s->tmp_table == NO_TMP_TABLE) + mysql_mutex_unlock(&s->LOCK_share); free_table_share(share); } } else - mysql_mutex_unlock(&s->LOCK_share); + { + if (s->tmp_table == NO_TMP_TABLE) + mysql_mutex_unlock(&s->LOCK_share); + } TABLE *table= (TABLE*)alloc_root(&mem_root, sizeof(*table)); if (!table || open_table_from_share(in_use, s->hlindex, &empty_clex_str, db_stat, EXTRA_RECORD, in_use->open_options, table, 0)) diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 8729883cc04..a49ea46e28a 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2082,6 +2082,26 @@ bool log_drop_table(THD *thd, const LEX_CSTRING *db_name, } +static int get_hlindex_keys(THD *thd, const LEX_CSTRING *db, + const LEX_CSTRING *table_name, const char *path, + uint *keys, uint *total_keys) +{ + TABLE_SHARE share; + int error; + DBUG_ENTER("get_hlindex_keys"); + + init_tmp_table_share(thd, &share, db->str, 0, table_name->str, path, 1); + error= open_table_def(thd, &share, GTS_TABLE | GTS_USE_DISCOVERY); + if (!error) + { + *keys= share.keys; + *total_keys= share.total_keys; + } + free_table_share(&share); + DBUG_RETURN(error); +} + + /** Quickly remove a table, without any logging @@ -2116,7 +2136,25 @@ bool quick_rm_table(THD *thd, handlerton *base, const LEX_CSTRING *db, delete file; } if (!(flags & (FRM_ONLY|NO_HA_TABLE))) + { + uint keys, total_keys; + int hlindex_error= get_hlindex_keys(thd, db, table_name, path, &keys, + &total_keys); error|= ha_delete_table(thd, base, path, db, table_name, 0) > 0; + if (!hlindex_error) + { + char idx_path[FN_REFLEN + 1]; + char *idx_path_end= strmov(idx_path, path); + for (uint i= keys; i < total_keys; i++) + { + my_snprintf(idx_path_end, HLINDEX_BUF_LEN, HLINDEX_TEMPLATE, i); + if (ha_delete_table(thd, base, idx_path, db, table_name, 0)) + error= 1; + } + } + else + error= 1; + } if (!(flags & NO_FRM_RENAME)) { @@ -5400,18 +5438,17 @@ mysql_rename_table(handlerton *base, const LEX_CSTRING *old_db, 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; + uint keys, total_keys; - 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)) + if (!get_hlindex_keys(thd, new_db, new_name, to, &keys, &total_keys)) { - for (uint i= share.keys; i < share.total_keys; i++) + for (uint i= keys; i < 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--) + for (; i >= keys; i--) { my_snprintf(idx_from_end, HLINDEX_BUF_LEN, HLINDEX_TEMPLATE, i); my_snprintf(idx_to_end, HLINDEX_BUF_LEN, HLINDEX_TEMPLATE, i); @@ -5429,7 +5466,6 @@ mysql_rename_table(handlerton *base, const LEX_CSTRING *old_db, 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))) @@ -12274,7 +12310,7 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to, from->file->info(HA_STATUS_VARIABLE); to->file->extra(HA_EXTRA_PREPARE_FOR_ALTER_TABLE); - if (!to->s->long_unique_table) + if (!to->s->long_unique_table && !to->s->hlindexes()) { to->file->ha_start_bulk_insert(from->file->stats.records, ignore ? 0 : HA_CREATE_UNIQUE_INDEX_BY_SORT); @@ -12401,7 +12437,8 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to, thd->progress.max_counter= from->file->records(); time_to_report_progress= MY_HOW_OFTEN_TO_WRITE/10; - if (!ignore) /* for now, InnoDB needs the undo log for ALTER IGNORE */ + /* for now, InnoDB needs the undo log for ALTER IGNORE */ + if (!ignore && !to->s->hlindexes()) to->file->extra(HA_EXTRA_BEGIN_ALTER_COPY); if (!(error= info.read_record())) @@ -12578,7 +12615,7 @@ copy_data_between_tables(THD *thd, TABLE *from, TABLE *to, } bulk_insert_started= 0; - if (!ignore && error <= 0) + if (!ignore && !to->s->hlindexes() && error <= 0) { int alt_error= to->file->extra(HA_EXTRA_END_ALTER_COPY); if (alt_error > 0) diff --git a/sql/vector_mhnsw.cc b/sql/vector_mhnsw.cc index 1f3f31a2d4d..fa6bd4113d1 100644 --- a/sql/vector_mhnsw.cc +++ b/sql/vector_mhnsw.cc @@ -603,7 +603,8 @@ MHNSW_Trx *MHNSW_Trx::get_from_thd(TABLE *table, bool for_update) MHNSW_Context *MHNSW_Context::get_from_share(TABLE_SHARE *share, TABLE *table) { - mysql_mutex_lock(&share->LOCK_share); + if (share->tmp_table == NO_TMP_TABLE) + mysql_mutex_lock(&share->LOCK_share); auto ctx= static_cast(share->hlindex->hlindex_data); if (!ctx && table) { @@ -614,7 +615,8 @@ MHNSW_Context *MHNSW_Context::get_from_share(TABLE_SHARE *share, TABLE *table) } if (ctx) ctx->refcnt++; - mysql_mutex_unlock(&share->LOCK_share); + if (share->tmp_table == NO_TMP_TABLE) + mysql_mutex_unlock(&share->LOCK_share); return ctx; }