Skip to content

Commit 6fc75e0

Browse files
committed
MDEV-35922 Server crashes in mhnsw_read_first upon using vector key with views
1 parent 69041af commit 6fc75e0

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

mysql-test/main/vector_innodb.result

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,4 +273,16 @@ drop table t;
273273
create table t (v vector (1) not null,vector index (v)) engine=innodb;
274274
ERROR 42000: This table type requires a primary key
275275
set global innodb_force_primary_key=0;
276+
#
277+
# MDEV-35922 Server crashes in mhnsw_read_first upon using vector key with views
278+
#
279+
create table t (pk int primary key, v vector(1) not null, vector(v)) engine=innodb;
280+
insert into t values (1,0x31313131),(2,0x32323232);
281+
create view v as select * from t;
282+
select pk from v order by vec_distance_euclidean(v, 0x30303030) limit 2;
283+
pk
284+
1
285+
2
286+
drop view v;
287+
drop table t;
276288
# End of 11.7 tests

mysql-test/main/vector_innodb.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,4 +274,15 @@ drop table t;
274274
--error ER_REQUIRES_PRIMARY_KEY
275275
create table t (v vector (1) not null,vector index (v)) engine=innodb;
276276
set global innodb_force_primary_key=0;
277+
278+
--echo #
279+
--echo # MDEV-35922 Server crashes in mhnsw_read_first upon using vector key with views
280+
--echo #
281+
create table t (pk int primary key, v vector(1) not null, vector(v)) engine=innodb;
282+
insert into t values (1,0x31313131),(2,0x32323232);
283+
create view v as select * from t;
284+
select pk from v order by vec_distance_euclidean(v, 0x30303030) limit 2;
285+
drop view v;
286+
drop table t;
287+
277288
--echo # End of 11.7 tests

sql/item_vectorfunc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ class Item_func_vec_distance_common: public Item_real_func
4949
double val_real() override;
5050
Item *get_const_arg() const
5151
{
52-
if (args[0]->type() == Item::FIELD_ITEM && args[1]->const_item())
52+
if (args[0]->real_item()->type() == Item::FIELD_ITEM && args[1]->const_item())
5353
return args[1];
54-
if (args[1]->type() == Item::FIELD_ITEM && args[0]->const_item())
54+
if (args[1]->real_item()->type() == Item::FIELD_ITEM && args[0]->const_item())
5555
return args[0];
5656
return NULL;
5757
}

0 commit comments

Comments
 (0)