From 29823f3b967179be71b14af37ca91d18a823778d Mon Sep 17 00:00:00 2001 From: Sergey Vojtovich Date: Fri, 7 Feb 2025 15:12:20 +0400 Subject: [PATCH] MDEV-35152 DATA/INDEX DIRECTORY options are ignored for vector index Let high-level indexes honor INDEX DIRECTORY table option --- mysql-test/main/vector_symlink.result | 60 +++++++++++++++++++++++++++ mysql-test/main/vector_symlink.test | 38 +++++++++++++++++ sql/handler.cc | 9 ++++ 3 files changed, 107 insertions(+) create mode 100644 mysql-test/main/vector_symlink.result create mode 100644 mysql-test/main/vector_symlink.test diff --git a/mysql-test/main/vector_symlink.result b/mysql-test/main/vector_symlink.result new file mode 100644 index 00000000000..10afc687485 --- /dev/null +++ b/mysql-test/main/vector_symlink.result @@ -0,0 +1,60 @@ +# +# MDEV-35152 - DATA/INDEX DIRECTORY options are ignored for vector index +# +create table t1id (a vector(1) not null, vector(a)) engine=InnoDB data directory '$MYSQL_TMP_DIR'; +create table t1ii (a vector(1) not null, vector(a)) engine=InnoDB index directory '$MYSQL_TMP_DIR'; +create table t1md (a vector(1) not null, vector(a)) engine=MyISAM data directory '$MYSQL_TMP_DIR'; +create table t1mi (a vector(1) not null, vector(a)) engine=MyISAM index directory '$MYSQL_TMP_DIR'; +show create table t1id; +Table Create Table +t1id CREATE TABLE `t1id` ( + `a` vector(1) NOT NULL, + VECTOR KEY `a` (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci DATA DIRECTORY='MYSQL_TMP_DIR/' +show create table t1ii; +Table Create Table +t1ii CREATE TABLE `t1ii` ( + `a` vector(1) NOT NULL, + VECTOR KEY `a` (`a`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci +show create table t1md; +Table Create Table +t1md CREATE TABLE `t1md` ( + `a` vector(1) NOT NULL, + VECTOR KEY `a` (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci DATA DIRECTORY='MYSQL_TMP_DIR/' +show create table t1mi; +Table Create Table +t1mi CREATE TABLE `t1mi` ( + `a` vector(1) NOT NULL, + VECTOR KEY `a` (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci INDEX DIRECTORY='MYSQL_TMP_DIR/' +######### MYSQL_TMP_DIR: +t1md.MYD +t1mi#i#00.MYD +t1mi#i#00.MYI +t1mi.MYI +######### MYSQL_TMP_DIR/test: +t1id.ibd +t1ii#i#00.ibd +######### datadir/test: +t1id#i#00.ibd +t1id.frm +t1id.isl +t1ii#i#00.isl +t1ii.frm +t1ii.ibd +t1md#i#00.MYD +t1md#i#00.MYI +t1md.MYD +t1md.MYI +t1md.frm +t1mi#i#00.MYD +t1mi#i#00.MYI +t1mi.MYD +t1mi.MYI +t1mi.frm +drop table t1id, t1ii, t1md, t1mi; +######### MYSQL_TMP_DIR: +######### MYSQL_TMP_DIR/test: +######### datadir/test: diff --git a/mysql-test/main/vector_symlink.test b/mysql-test/main/vector_symlink.test new file mode 100644 index 00000000000..728eb2b43f2 --- /dev/null +++ b/mysql-test/main/vector_symlink.test @@ -0,0 +1,38 @@ +--source include/have_symlink.inc +--source include/not_windows.inc +--source include/have_innodb.inc + + + --echo # + --echo # MDEV-35152 - DATA/INDEX DIRECTORY options are ignored for vector index + --echo # +--let $datadir= `select @@datadir` +evalp create table t1id (a vector(1) not null, vector(a)) engine=InnoDB data directory '$MYSQL_TMP_DIR'; +evalp create table t1ii (a vector(1) not null, vector(a)) engine=InnoDB index directory '$MYSQL_TMP_DIR'; +evalp create table t1md (a vector(1) not null, vector(a)) engine=MyISAM data directory '$MYSQL_TMP_DIR'; +evalp create table t1mi (a vector(1) not null, vector(a)) engine=MyISAM index directory '$MYSQL_TMP_DIR'; + +--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR +show create table t1id; +--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR +show create table t1ii; +--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR +show create table t1md; +--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR +show create table t1mi; + +--echo ######### MYSQL_TMP_DIR: +--list_files $MYSQL_TMP_DIR/ t1* +--echo ######### MYSQL_TMP_DIR/test: +--list_files $MYSQL_TMP_DIR/test/ t1* +--echo ######### datadir/test: +--list_files $datadir/test/ t1* + +drop table t1id, t1ii, t1md, t1mi; + +--echo ######### MYSQL_TMP_DIR: +--list_files $MYSQL_TMP_DIR/ t1* +--echo ######### MYSQL_TMP_DIR/test: +--list_files $MYSQL_TMP_DIR/test/ t1* +--echo ######### datadir/test: +--list_files $datadir/test/ t1* diff --git a/sql/handler.cc b/sql/handler.cc index 5effaf6b681..b404055da0a 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -6465,12 +6465,19 @@ int ha_create_table(THD *thd, const char *path, const char *db, DBUG_ASSERT(share.key_info[share.keys].algorithm == HA_KEY_ALG_VECTOR); TABLE_SHARE index_share; char file_name[FN_REFLEN+1]; + char index_file_name[FN_REFLEN+1], *index_file_name_end; Alter_info index_ainfo; 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 (create_info->index_file_name) + { + index_file_name_end= strmov(index_file_name, create_info->index_file_name); + index_cinfo.index_file_name= index_file_name; + index_cinfo.data_file_name= index_file_name; + } if ((error= share.path.length > sizeof(file_name) - HLINDEX_BUF_LEN)) goto err; @@ -6478,6 +6485,8 @@ int ha_create_table(THD *thd, const char *path, const char *db, for (uint i= share.keys; i < share.total_keys; i++) { my_snprintf(path_end, HLINDEX_BUF_LEN, HLINDEX_TEMPLATE, i); + if (create_info->index_file_name) + my_snprintf(index_file_name_end, HLINDEX_BUF_LEN, HLINDEX_TEMPLATE, i); init_tmp_table_share(thd, &index_share, db, 0, table_name, file_name, 1); index_share.db_plugin= share.db_plugin; LEX_CSTRING sql= mhnsw_hlindex_table_def(thd, ref_length);