diff --git a/include/maria.h b/include/maria.h index 7fdf95f7ac4..0fe5d76598f 100644 --- a/include/maria.h +++ b/include/maria.h @@ -134,7 +134,7 @@ typedef struct st_maria_create_info ulong s3_block_size; /* Size of null bitmap at start of row */ uint null_bytes; - uint old_options; + uint old_options, rec_reflength; uint compression_algorithm; enum data_file_type org_data_file_type; uint16 language; diff --git a/include/myisam.h b/include/myisam.h index 9d4e0ecab46..1136ace39a1 100644 --- a/include/myisam.h +++ b/include/myisam.h @@ -154,7 +154,7 @@ typedef struct st_mi_create_info ulonglong auto_increment; ulonglong data_file_length; ulonglong key_file_length; - uint old_options; + uint old_options, rec_reflength; uint16 language; my_bool with_auto_increment; } MI_CREATE_INFO; diff --git a/sql/handler.cc b/sql/handler.cc index f16feb5935b..0c7a6a829e5 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -6321,7 +6321,8 @@ int handler::calculate_checksum() ****************************************************************************/ static int ha_create_table_from_share(THD *thd, TABLE_SHARE *share, - HA_CREATE_INFO *create_info) + HA_CREATE_INFO *create_info, + uint *ref_length) { TABLE table; @@ -6342,6 +6343,7 @@ static int ha_create_table_from_share(THD *thd, TABLE_SHARE *share, share->table_name.str, error); table.file->print_error(error, MYF(ME_WARNING)); } + *ref_length= table.file->ref_length; // for hlindexes (void) closefrm(&table); return error; @@ -6368,6 +6370,7 @@ int ha_create_table(THD *thd, const char *path, const char *db, LEX_CUSTRING *frm, bool skip_frm_file) { int error= 1; + uint ref_length; TABLE_SHARE share; Abort_on_warning_instant_set old_abort_on_warning(thd, 0); bool is_tmp __attribute__((unused)) = @@ -6398,7 +6401,7 @@ int ha_create_table(THD *thd, const char *path, const char *db, } share.m_psi= PSI_CALL_get_table_share(is_tmp, &share); - if ((error= ha_create_table_from_share(thd, &share, create_info))) + if ((error= ha_create_table_from_share(thd, &share, create_info, &ref_length))) { PSI_CALL_drop_table_share(is_tmp, share.db.str, (uint)share.db.length, share.table_name.str, (uint)share.table_name.length); @@ -6424,11 +6427,14 @@ int ha_create_table(THD *thd, const char *path, const char *db, my_snprintf(path_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); if ((error= index_share.init_from_sql_statement_string(thd, false, - mhnsw_hlindex_table.str, mhnsw_hlindex_table.length))) + sql.str, sql.length))) break; - if ((error= ha_create_table_from_share(thd, &index_share, &index_cinfo))) + uint unused; + if ((error= ha_create_table_from_share(thd, &index_share, &index_cinfo, + &unused))) break; } free_table_share(&index_share); diff --git a/sql/sql_base.cc b/sql/sql_base.cc index 56b611fc816..c53e93d4a85 100644 --- a/sql/sql_base.cc +++ b/sql/sql_base.cc @@ -9860,8 +9860,9 @@ int TABLE::hlindex_open(uint nr) path, false); share->db_plugin= s->db_plugin; + LEX_CSTRING sql= mhnsw_hlindex_table_def(in_use, file->ref_length); if (share->init_from_sql_statement_string(in_use, false, - mhnsw_hlindex_table.str, mhnsw_hlindex_table.length)) + sql.str, sql.length)) { free_table_share(share); return 1; diff --git a/sql/vector_mhnsw.cc b/sql/vector_mhnsw.cc index 168b6e7ca7e..f5a30f31ab1 100644 --- a/sql/vector_mhnsw.cc +++ b/sql/vector_mhnsw.cc @@ -21,15 +21,6 @@ #include "key.h" #include -const LEX_CSTRING mhnsw_hlindex_table={STRING_WITH_LEN("\ - CREATE TABLE i ( \ - layer int not null, \ - src varbinary(255) not null, \ - neighbors blob not null, \ - index (layer, src)) \ -")}; - - class MHNSW_Context; class FVector: public Sql_alloc @@ -614,3 +605,17 @@ int mhnsw_read_next(TABLE *table) } return HA_ERR_END_OF_FILE; } + +const LEX_CSTRING mhnsw_hlindex_table_def(THD *thd, uint ref_length) +{ + const char templ[]="CREATE TABLE i ( " + " layer int not null, " + " src varbinary(%u) not null, " + " neighbors varbinary(%u) not null," + " index (layer, src)) "; + size_t len= sizeof(templ) + 32; + char *s= thd->alloc(len); + len= my_snprintf(s, len, templ, ref_length, 2 * ref_length * + thd->variables.hnsw_max_connection_per_layer); + return {s, len}; +} diff --git a/sql/vector_mhnsw.h b/sql/vector_mhnsw.h index 141512244b7..267303dc578 100644 --- a/sql/vector_mhnsw.h +++ b/sql/vector_mhnsw.h @@ -21,8 +21,7 @@ #include "structs.h" #include "table.h" -extern const LEX_CSTRING mhnsw_hlindex_table; - +const LEX_CSTRING mhnsw_hlindex_table_def(THD *thd, uint ref_length); int mhnsw_insert(TABLE *table, KEY *keyinfo); int mhnsw_read_first(TABLE *table, KEY *keyinfo, Item *dist, ulonglong limit); int mhnsw_read_next(TABLE *table); diff --git a/storage/maria/ha_maria.cc b/storage/maria/ha_maria.cc index c85f1450b0b..5412d15ed47 100644 --- a/storage/maria/ha_maria.cc +++ b/storage/maria/ha_maria.cc @@ -3411,6 +3411,7 @@ int ha_maria::create(const char *name, TABLE *table_arg, &create_info, create_flags); my_free(recinfo); + ref_length= create_info.rec_reflength; DBUG_RETURN(error); } diff --git a/storage/maria/ma_create.c b/storage/maria/ma_create.c index 16406934b99..8ff1abd09a0 100644 --- a/storage/maria/ma_create.c +++ b/storage/maria/ma_create.c @@ -745,7 +745,7 @@ int maria_create(const char *name, enum data_file_type datafile_type, share.state.sortkey= (ushort) ~0; share.state.auto_increment=ci->auto_increment; share.options=options; - share.base.rec_reflength=pointer; + share.base.rec_reflength= ci->rec_reflength= pointer; share.base.block_size= maria_block_size; share.base.language= (ci->language ? ci->language : default_charset_info->number); diff --git a/storage/myisam/ha_myisam.cc b/storage/myisam/ha_myisam.cc index 98d729cc9be..5ff7643ba22 100644 --- a/storage/myisam/ha_myisam.cc +++ b/storage/myisam/ha_myisam.cc @@ -2304,6 +2304,7 @@ int ha_myisam::create(const char *name, TABLE *table_arg, record_count, recinfo, 0, (MI_UNIQUEDEF*) 0, &create_info, create_flags); + ref_length= create_info.rec_reflength; my_free(recinfo); DBUG_RETURN(error); } diff --git a/storage/myisam/mi_create.c b/storage/myisam/mi_create.c index 48b794d1610..77f71f1cf97 100644 --- a/storage/myisam/mi_create.c +++ b/storage/myisam/mi_create.c @@ -528,7 +528,7 @@ int mi_create(const char *name,uint keys,MI_KEYDEF *keydefs, share.state.sortkey= (ushort) ~0; share.state.auto_increment=ci->auto_increment; share.options=options; - share.base.rec_reflength=pointer; + share.base.rec_reflength= ci->rec_reflength= pointer; /* Get estimate for index file length (this may be wrong for FT keys) */ tmp= (tot_length + max_key_block_length * keys * MI_INDEX_BLOCK_MARGIN) / MI_MIN_KEY_BLOCK_LENGTH;