From 6fc75e086874b97e23a0c631d5b272cf94e1258f Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 3 Feb 2025 12:08:10 +0100 Subject: [PATCH] MDEV-35922 Server crashes in mhnsw_read_first upon using vector key with views --- mysql-test/main/vector_innodb.result | 12 ++++++++++++ mysql-test/main/vector_innodb.test | 11 +++++++++++ sql/item_vectorfunc.h | 4 ++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/mysql-test/main/vector_innodb.result b/mysql-test/main/vector_innodb.result index 673c047eed1..f308b8a93dd 100644 --- a/mysql-test/main/vector_innodb.result +++ b/mysql-test/main/vector_innodb.result @@ -273,4 +273,16 @@ drop table t; create table t (v vector (1) not null,vector index (v)) engine=innodb; ERROR 42000: This table type requires a primary key set global innodb_force_primary_key=0; +# +# MDEV-35922 Server crashes in mhnsw_read_first upon using vector key with views +# +create table t (pk int primary key, v vector(1) not null, vector(v)) engine=innodb; +insert into t values (1,0x31313131),(2,0x32323232); +create view v as select * from t; +select pk from v order by vec_distance_euclidean(v, 0x30303030) limit 2; +pk +1 +2 +drop view v; +drop table t; # End of 11.7 tests diff --git a/mysql-test/main/vector_innodb.test b/mysql-test/main/vector_innodb.test index 90ae83f2cf5..60e1f8ac7d6 100644 --- a/mysql-test/main/vector_innodb.test +++ b/mysql-test/main/vector_innodb.test @@ -274,4 +274,15 @@ drop table t; --error ER_REQUIRES_PRIMARY_KEY create table t (v vector (1) not null,vector index (v)) engine=innodb; set global innodb_force_primary_key=0; + +--echo # +--echo # MDEV-35922 Server crashes in mhnsw_read_first upon using vector key with views +--echo # +create table t (pk int primary key, v vector(1) not null, vector(v)) engine=innodb; +insert into t values (1,0x31313131),(2,0x32323232); +create view v as select * from t; +select pk from v order by vec_distance_euclidean(v, 0x30303030) limit 2; +drop view v; +drop table t; + --echo # End of 11.7 tests diff --git a/sql/item_vectorfunc.h b/sql/item_vectorfunc.h index e6da1b77441..d2094e28e4b 100644 --- a/sql/item_vectorfunc.h +++ b/sql/item_vectorfunc.h @@ -49,9 +49,9 @@ public: double val_real() override; Item *get_const_arg() const { - if (args[0]->type() == Item::FIELD_ITEM && args[1]->const_item()) + if (args[0]->real_item()->type() == Item::FIELD_ITEM && args[1]->const_item()) return args[1]; - if (args[1]->type() == Item::FIELD_ITEM && args[0]->const_item()) + if (args[1]->real_item()->type() == Item::FIELD_ITEM && args[0]->const_item()) return args[0]; return NULL; }