From 2b17265ae279ac5cf007aa8d84265a4f96bba3db Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sun, 9 Feb 2025 17:10:05 +0100 Subject: [PATCH] MDEV-35186 IGNORED attribute has no effect on vector keys --- mysql-test/main/vector2.result | 12 ++++++++++++ mysql-test/main/vector2.test | 8 ++++++++ sql/item_vectorfunc.cc | 3 ++- sql/table.cc | 2 +- 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/mysql-test/main/vector2.result b/mysql-test/main/vector2.result index 71cf329ce54..1d3ccbea13d 100644 --- a/mysql-test/main/vector2.result +++ b/mysql-test/main/vector2.result @@ -423,4 +423,16 @@ show warnings; Level Code Message Warning 1292 Incorrect inet6 value: '' for column ``.``.`a` at row 0 Error 1067 Invalid default value for 'a' +# +# MDEV-35186 IGNORED attribute has no effect on vector keys +# +create table t (a vector(1) not null, vector(a) ignored); +show index in t; +Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment Ignored +t 1 a 1 a A NULL NULL NULL VECTOR YES +insert into t values (0x00000000),(0x00000000); +explain select vec_totext(a) from t order by vec_distance_euclidean(a,0x00000000) limit 1; +id select_type table type possible_keys key key_len ref rows Extra +1 SIMPLE t ALL NULL NULL NULL NULL 2 Using filesort +drop table t; # End of 11.7 tests diff --git a/mysql-test/main/vector2.test b/mysql-test/main/vector2.test index e0c570e5303..ca50dd5427e 100644 --- a/mysql-test/main/vector2.test +++ b/mysql-test/main/vector2.test @@ -309,4 +309,12 @@ show warnings; create table t (a inet6 not null default ''); show warnings; +--echo # +--echo # MDEV-35186 IGNORED attribute has no effect on vector keys +--echo # +create table t (a vector(1) not null, vector(a) ignored); +show index in t; +insert into t values (0x00000000),(0x00000000); +explain select vec_totext(a) from t order by vec_distance_euclidean(a,0x00000000) limit 1; +drop table t; --echo # End of 11.7 tests diff --git a/sql/item_vectorfunc.cc b/sql/item_vectorfunc.cc index 1179855ce80..2a3a7704b64 100644 --- a/sql/item_vectorfunc.cc +++ b/sql/item_vectorfunc.cc @@ -32,7 +32,8 @@ key_map Item_func_vec_distance_common::part_of_sortkey() const Field *f= item->field; KEY *keyinfo= f->table->s->key_info; for (uint i= f->table->s->keys; i < f->table->s->total_keys; i++) - if (keyinfo[i].algorithm == HA_KEY_ALG_VECTOR && f->key_start.is_set(i) + if (!keyinfo[i].is_ignored && keyinfo[i].algorithm == HA_KEY_ALG_VECTOR + && f->key_start.is_set(i) && mhnsw_uses_distance(f->table, keyinfo + i, this)) map.set_bit(i); } diff --git a/sql/table.cc b/sql/table.cc index 9fadee37cb6..2c81cadad8b 100644 --- a/sql/table.cc +++ b/sql/table.cc @@ -2214,7 +2214,7 @@ int TABLE_SHARE::init_from_binary_frm_image(THD *thd, bool write, if (extra2.index_flags.str) extra_index_flags_present= TRUE; - for (uint i= 0; i < share->keys; i++, keyinfo++) + for (uint i= 0; i < share->total_keys; i++, keyinfo++) { if (extra_index_flags_present) {