diff --git a/mysql-test/main/vector2.result b/mysql-test/main/vector2.result index 8ff938b9e36..4e783808448 100644 --- a/mysql-test/main/vector2.result +++ b/mysql-test/main/vector2.result @@ -254,3 +254,19 @@ v UUUU VVVV drop table t; +# +# MDEV-35194 non-BNL join fails on assertion +# +create table t1 (pk int primary key, a vector(2) not null, vector(a)); +insert into t1 select seq, vec_fromtext(json_array(seq, -seq)) from seq_1_to_1000; +create table t2 (f int); +insert into t2 select seq from seq_1_to_1000; +set join_cache_level= 0; +select t2.f from t1 left join t2 on (t1.pk=t2.f) order by vec_distance_euclidean(t1.a,0x00000040) limit 5; +f +1 +2 +3 +4 +5 +drop table t1, t2; diff --git a/mysql-test/main/vector2.test b/mysql-test/main/vector2.test index bcf896e263b..410fc67a9d0 100644 --- a/mysql-test/main/vector2.test +++ b/mysql-test/main/vector2.test @@ -196,3 +196,14 @@ create table t (v vector(1)); insert into t values (0x55555555),(0x56565656); select distinct v from t; drop table t; + +--echo # +--echo # MDEV-35194 non-BNL join fails on assertion +--echo # +create table t1 (pk int primary key, a vector(2) not null, vector(a)); +insert into t1 select seq, vec_fromtext(json_array(seq, -seq)) from seq_1_to_1000; +create table t2 (f int); +insert into t2 select seq from seq_1_to_1000; +set join_cache_level= 0; +select t2.f from t1 left join t2 on (t1.pk=t2.f) order by vec_distance_euclidean(t1.a,0x00000040) limit 5; +drop table t1, t2; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 53a9cd486f8..84f6644c41e 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -25150,7 +25150,6 @@ join_read_first(JOIN_TAB *tab) DBUG_ASSERT(tab->sorted); DBUG_ASSERT(tab->join->order); DBUG_ASSERT(tab->join->order->next == NULL); - DBUG_ASSERT(tab->join->select_limit < HA_POS_ERROR); tab->read_record.read_record_func= join_hlindex_read_next; error= tab->table->hlindex_read_first(tab->index, *tab->join->order->item, tab->join->select_limit); diff --git a/sql/vector_mhnsw.cc b/sql/vector_mhnsw.cc index d7892ff9715..72b0591fc73 100644 --- a/sql/vector_mhnsw.cc +++ b/sql/vector_mhnsw.cc @@ -1242,6 +1242,8 @@ int mhnsw_read_first(TABLE *table, KEY *keyinfo, Item *dist, ulonglong limit) auto *fun= static_cast(dist->real_item()); DBUG_ASSERT(fun); + limit= std::min(limit, max_ef); + String buf, *res= fun->get_const_arg()->val_str(&buf); MHNSW_Share *ctx;