MDEV-35221 Vector values do not survive mariadb-dump / restore

force --hex-dump for fields of GEOMETRY, BIT, and VECTOR types.

Until MDEV-35831 is fixed, vector type is detected by name.
This commit is contained in:
Sergei Golubchik 2025-02-03 15:19:30 +01:00
parent a2f0234c82
commit 40d39b1176
3 changed files with 78 additions and 63 deletions

View file

@ -103,6 +103,9 @@
#define DUMP_TABLE_TABLE 0
#define DUMP_TABLE_SEQUENCE 1
/* until MDEV-35831 is implemented, we'll have to detect VECTOR by name */
#define MYSQL_TYPE_VECTOR "V"
static my_bool ignore_table_data(const uchar *hash_key, size_t len);
static void add_load_option(DYNAMIC_STRING *str, const char *option,
const char *option_value);
@ -147,7 +150,7 @@ static my_bool insert_pat_inited= 0, debug_info_flag= 0, debug_check_flag= 0,
static ulong opt_max_allowed_packet, opt_net_buffer_length;
static double opt_max_statement_time= 0.0;
static MYSQL *mysql=0;
static DYNAMIC_STRING insert_pat, select_field_names,
static DYNAMIC_STRING insert_pat, select_field_names, field_flags,
select_field_names_for_header, insert_field_names;
static char *opt_password=0,*current_user=0,
*current_host=0,*path=0,*fields_terminated=0,
@ -2009,6 +2012,7 @@ static void free_resources()
dynstr_free(&dynamic_where);
dynstr_free(&insert_pat);
dynstr_free(&select_field_names);
dynstr_free(&field_flags);
dynstr_free(&select_field_names_for_header);
dynstr_free(&insert_field_names);
if (defaults_argv)
@ -3181,6 +3185,7 @@ static uint get_table_structure(const char *table, const char *db, char *table_t
{
select_field_names_inited= 1;
init_dynamic_string_checked(&select_field_names, "", 1024, 1024);
init_dynamic_string_checked(&field_flags, "", 1024, 1024);
init_dynamic_string_checked(&insert_field_names, "", 1024, 1024);
if (opt_header)
init_dynamic_string_checked(&select_field_names_for_header, "", 1024, 1024);
@ -3188,6 +3193,7 @@ static uint get_table_structure(const char *table, const char *db, char *table_t
else
{
dynstr_set_checked(&select_field_names, "");
dynstr_set_checked(&field_flags, "");
dynstr_set_checked(&insert_field_names, "");
if (opt_header)
dynstr_set_checked(&select_field_names_for_header, "");
@ -3489,6 +3495,11 @@ static uint get_table_structure(const char *table, const char *db, char *table_t
if (opt_header)
dynstr_append_checked(&select_field_names_for_header,
quote_for_equal(row[0], name_buff));
/* VECTOR doesn't have a type code yet, must be detected by name */
if (row[3] && strcmp(row[3], "vector") == 0)
dynstr_append_checked(&field_flags, MYSQL_TYPE_VECTOR);
else
dynstr_append_checked(&field_flags, " ");
}
if (vers_hidden)
@ -3502,6 +3513,7 @@ static uint get_table_structure(const char *table, const char *db, char *table_t
"row_end" :
"row_end");
dynstr_append_checked(&insert_field_names, ", row_start, row_end");
dynstr_append_checked(&field_flags, " ");
}
/*
@ -3608,6 +3620,11 @@ static uint get_table_structure(const char *table, const char *db, char *table_t
while ((row= mysql_fetch_row(result)))
{
ulong *lengths= mysql_fetch_lengths(result);
/* VECTOR doesn't have a type code yet, must be detected by name */
if (strncmp(row[SHOW_TYPE], STRING_WITH_LEN("vector(")) == 0)
dynstr_append_checked(&field_flags, MYSQL_TYPE_VECTOR);
else
dynstr_append_checked(&field_flags, " ");
if (init)
{
if (!opt_xml && !opt_no_create_info)
@ -4491,21 +4508,23 @@ static void dump_table(const char *table, const char *db, const uchar *hash_key,
"Not enough fields from table %s! Aborting.\n",
result_table);
DBUG_ASSERT(field_flags.length > i);
/*
63 is my_charset_bin. If charsetnr is not 63,
we have not a BLOB but a TEXT column.
we'll dump in hex only BLOB columns.
*/
is_blob= (opt_hex_blob && field->charsetnr == 63 &&
(field->type == MYSQL_TYPE_BIT ||
field->type == MYSQL_TYPE_STRING ||
field->type == MYSQL_TYPE_VAR_STRING ||
field->type == MYSQL_TYPE_VARCHAR ||
field->type == MYSQL_TYPE_BLOB ||
field->type == MYSQL_TYPE_LONG_BLOB ||
field->type == MYSQL_TYPE_MEDIUM_BLOB ||
field->type == MYSQL_TYPE_TINY_BLOB ||
field->type == MYSQL_TYPE_GEOMETRY)) ? 1 : 0;
is_blob= field->type == MYSQL_TYPE_GEOMETRY ||
field->type == MYSQL_TYPE_BIT ||
field_flags.str[i] == MYSQL_TYPE_VECTOR[0] ||
(opt_hex_blob && field->charsetnr == 63 &&
(field->type == MYSQL_TYPE_STRING ||
field->type == MYSQL_TYPE_VAR_STRING ||
field->type == MYSQL_TYPE_VARCHAR ||
field->type == MYSQL_TYPE_BLOB ||
field->type == MYSQL_TYPE_LONG_BLOB ||
field->type == MYSQL_TYPE_MEDIUM_BLOB ||
field->type == MYSQL_TYPE_TINY_BLOB));
if (extended_insert && !opt_xml)
{
if (i == 0)
@ -4528,7 +4547,7 @@ static void dump_table(const char *table, const char *db, const uchar *hash_key,
Also we need to reserve 1 byte for terminating '\0'.
*/
dynstr_realloc_checked(&extended_row,length * 2 + 2 + 1);
if (opt_hex_blob && is_blob)
if (is_blob)
{
dynstr_append_checked(&extended_row, "0x");
extended_row.length+= mysql_hex_string(extended_row.str +
@ -4589,7 +4608,7 @@ static void dump_table(const char *table, const char *db, const uchar *hash_key,
{
if (opt_xml)
{
if (opt_hex_blob && is_blob && length)
if (is_blob && length)
{
/* Define xsi:type="xs:hexBinary" for hex encoded data */
print_xml_tag(md_result_file, "\t\t", "", "field", "name=",
@ -4604,7 +4623,7 @@ static void dump_table(const char *table, const char *db, const uchar *hash_key,
}
fputs("</field>\n", md_result_file);
}
else if (opt_hex_blob && is_blob && length)
else if (is_blob && length)
{
fputs("0x", md_result_file);
print_blob_as_hex(md_result_file, row[i], length);

View file

@ -1,68 +1,70 @@
#
# mysqldump
#
create table t1 (id int auto_increment primary key, v vector(5) not null, vector index (v));
create table t1 (id int auto_increment primary key, v vector(5) not null);
insert t1 (v) values (Vec_Fromtext('[0.418,0.809,0.823,0.598,0.033]')),
(Vec_Fromtext('[0.687,0.789,0.496,0.574,0.917]')),
(Vec_Fromtext('[0.333,0.962,0.467,0.448,0.475]')),
(Vec_Fromtext('[0.822,0.185,0.683,0.211,0.554]')),
(Vec_Fromtext('[0.437,0.167,0.077,0.428,0.241]')),
(Vec_Fromtext('[0.769,0.926,0.803,0.015,0.589]')),
(Vec_Fromtext('[0.493,0.641,0.761,0.942,0.425]')),
(Vec_Fromtext('[0.924,0.275,0.054,0.073,0.136]')),
(Vec_Fromtext('[0.186,0.696,0.035,0.668,0.847]')),
(Vec_Fromtext('[0.415,0.609,0.426,0.988,0.475]'));
select id from t1 order by vec_distance_euclidean(v, Vec_FromText('[1,0,0,0,0]')) limit 3;
id
8
5
4
1
3
2
/*M!999999\- enable the sandbox mode */
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
INSERT INTO `t1` VALUES
(1,0x1904D63EA01A4F3F21B0523F8716193F022B073D),
(2,0x3BDF2F3FE7FB493FB6F3FD3EAAF1123F83C06A3F),
(3,0xFA7EAA3EA245763FA01AEF3E4260E53E3333F33E),
(4,0x986E523FA4703D3E17D92E3F6210583EF2D20D3F),
(5,0x77BEDF3E0C022B3E2DB29D3DD122DB3EB4C8763E),
(6,0x2FDD443F560E6D3F68914D3F8FC2753CB4C8163F),
(7,0x7F6AFC3E9318243FE5D0423FE926713F9A99D93E),
(8,0x448B6C3FCDCC8C3E1B2F5D3D0681953D96430B3E),
(9,0xC9763E3E0E2D323F295C0F3D0C022B3FFED4583F),
(10,0xE17AD43E6DE71B3FAC1CDA3E91ED7C3F3333F33E);
(2,0xC9763E3E0E2D323F295C0F3D0C022B3FFED4583F),
(3,0xE17AD43E6DE71B3FAC1CDA3E91ED7C3F3333F33E);
<?xml version="1.0"?>
<mysqldump xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<database name="test">
<table_structure name="t1">
<field Field="id" Type="int(11)" Null="NO" Key="PRI" Extra="auto_increment" Comment="" />
<field Field="v" Type="vector(5)" Null="NO" Key="" Extra="" Comment="" />
<key Table="t1" Non_unique="0" Key_name="PRIMARY" Seq_in_index="1" Column_name="id" Collation="A" Cardinality="3" Null="" Index_type="BTREE" Comment="" Index_comment="" Ignored="NO" />
<options Name="t1" Engine="MyISAM" Version="10" Row_format="Dynamic" Rows="3" Avg_row_length="32" Data_length="96" Max_data_length="281474976710655" Index_length="2048" Data_free="0" Auto_increment="4" Create_time="YYYY-MM-DD hh:mm:ss" Update_time="YYYY-MM-DD hh:mm:ss" Collation="utf8mb4_uca1400_ai_ci" Create_options="" Comment="" Max_index_length="288230376151710720" Temporary="N" />
</table_structure>
<table_data name="t1">
<row>
<field name="id">1</field>
<field name="v" xsi:type="xs:hexBinary">1904D63EA01A4F3F21B0523F8716193F022B073D</field>
</row>
<row>
<field name="id">2</field>
<field name="v" xsi:type="xs:hexBinary">C9763E3E0E2D323F295C0F3D0C022B3FFED4583F</field>
</row>
<row>
<field name="id">3</field>
<field name="v" xsi:type="xs:hexBinary">E17AD43E6DE71B3FAC1CDA3E91ED7C3F3333F33E</field>
</row>
</table_data>
</database>
</mysqldump>
show create table t1;
Table Create Table
t1 CREATE TABLE `t1` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`v` vector(5) NOT NULL,
PRIMARY KEY (`id`),
VECTOR KEY `v` (`v`)
) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
select id, Vec_ToText(v) from t1;
id Vec_ToText(v)
1 [0.418,0.809,0.823,0.598,0.033]
2 [0.687,0.789,0.496,0.574,0.917]
3 [0.333,0.962,0.467,0.448,0.475]
4 [0.822,0.185,0.683,0.211,0.554]
5 [0.437,0.167,0.077,0.428,0.241]
6 [0.769,0.926,0.803,0.015,0.589]
7 [0.493,0.641,0.761,0.942,0.425]
8 [0.924,0.275,0.054,0.073,0.136]
9 [0.186,0.696,0.035,0.668,0.847]
10 [0.415,0.609,0.426,0.988,0.475]
2 [0.186,0.696,0.035,0.668,0.847]
3 [0.415,0.609,0.426,0.988,0.475]
select id from t1 order by vec_distance_euclidean(v, Vec_FromText('[1,0,0,0,0]')) limit 3;
id
8
5
4
1
3
2
drop table t1;
#
# MDEV-35044 ALTER on a table with vector index attempts to bypass unsupported locking limitation, server crashes in THD::free_tmp_table_share

View file

@ -5,21 +5,15 @@
--echo #
--echo # mysqldump
--echo #
create table t1 (id int auto_increment primary key, v vector(5) not null, vector index (v));
create table t1 (id int auto_increment primary key, v vector(5) not null);
insert t1 (v) values (Vec_Fromtext('[0.418,0.809,0.823,0.598,0.033]')),
(Vec_Fromtext('[0.687,0.789,0.496,0.574,0.917]')),
(Vec_Fromtext('[0.333,0.962,0.467,0.448,0.475]')),
(Vec_Fromtext('[0.822,0.185,0.683,0.211,0.554]')),
(Vec_Fromtext('[0.437,0.167,0.077,0.428,0.241]')),
(Vec_Fromtext('[0.769,0.926,0.803,0.015,0.589]')),
(Vec_Fromtext('[0.493,0.641,0.761,0.942,0.425]')),
(Vec_Fromtext('[0.924,0.275,0.054,0.073,0.136]')),
(Vec_Fromtext('[0.186,0.696,0.035,0.668,0.847]')),
(Vec_Fromtext('[0.415,0.609,0.426,0.988,0.475]'));
select id from t1 order by vec_distance_euclidean(v, Vec_FromText('[1,0,0,0,0]')) limit 3;
replace_result InnoDB MyISAM;
exec $MYSQL_DUMP --compact --hex-blob test t1;
exec $MYSQL_DUMP --hex-blob test t1 > $MYSQL_TMP_DIR/vector.sql;
exec $MYSQL_DUMP --compact test t1;
replace_regex /\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d/YYYY-MM-DD hh:mm:ss/;
exec $MYSQL_DUMP --compact --xml test t1;
exec $MYSQL_DUMP test t1 > $MYSQL_TMP_DIR/vector.sql;
exec $MYSQL test < $MYSQL_TMP_DIR/vector.sql;
remove_file $MYSQL_TMP_DIR/vector.sql;
show create table t1;