From 70575defb705e066dd2ff898e2d131fbc2d06f1c Mon Sep 17 00:00:00 2001 From: Sergey Vojtovich Date: Sat, 6 Jul 2024 00:37:37 +0400 Subject: [PATCH] Fixed TRUNCATE TABLE against VECTOR indexes This patch fixes only TRUNCATE by recreate variant, there seem to be no reasonable engine that uses TRUNCATE by handler method for testing. Reset index_cinfo so that mi_create is not confused by garbage passed via index_file_name and sets MY_DELETE_OLD flag. Review question: can we add a test case to make sure VECTOR index is empty indeed? --- mysql-test/main/vector.result | 16 ++++++++++++++++ mysql-test/main/vector.test | 10 ++++++++++ sql/handler.cc | 1 + 3 files changed, 27 insertions(+) diff --git a/mysql-test/main/vector.result b/mysql-test/main/vector.result index 351ee953ad4..f80f56e523a 100644 --- a/mysql-test/main/vector.result +++ b/mysql-test/main/vector.result @@ -302,3 +302,19 @@ id hex(v) 20 6CA1D43E9DF91B3FE580DA3E1C247D3F147CF33E drop table t1, t2; db.opt +create table t1 (id int auto_increment primary key, v blob not null, vector index (v)); +truncate table t1; +insert t1 (v) values (x'e360d63ebe554f3fcdbc523f4522193f5236083d'); +truncate table t1; +select * from t1; +id v +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=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +drop table t1; +db.opt diff --git a/mysql-test/main/vector.test b/mysql-test/main/vector.test index c74f9717db2..f3d4c7ccfa8 100644 --- a/mysql-test/main/vector.test +++ b/mysql-test/main/vector.test @@ -101,3 +101,13 @@ insert into t1 select * from t2; select id, hex(v) from t1; drop table t1, t2; list_files $datadir/test; + +create table t1 (id int auto_increment primary key, v blob not null, vector index (v)); +truncate table t1; +insert t1 (v) values (x'e360d63ebe554f3fcdbc523f4522193f5236083d'); +truncate table t1; +select * from t1; +replace_result InnoDB MyISAM; +show create table t1; +drop table t1; +list_files $datadir/test; diff --git a/sql/handler.cc b/sql/handler.cc index b90472ad2bb..3c385e620a4 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -6424,6 +6424,7 @@ int ha_create_table(THD *thd, const char *path, const char *db, HA_CREATE_INFO index_cinfo; char *path_end= strmov(file_name, path); + bzero((char*) &index_cinfo, sizeof(index_cinfo)); index_cinfo.alter_info= &index_ainfo; if ((error= share.path.length > sizeof(file_name) - HLINDEX_BUF_LEN))