Skip to content

Commit 0b9bc6c

Browse files
committed
MDEV-35246 Vector search skips a row in the table
stronger condition in select_neighbors() to reject exact matches too
1 parent d506631 commit 0b9bc6c

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

mysql-test/main/vector2.result

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,38 @@ t1 CREATE TABLE `t1` (
321321
`v` vector(2) DEFAULT x'4041424344454647'
322322
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
323323
drop table t1;
324+
#
325+
# MDEV-35246 Vector search skips a row in the table
326+
#
327+
set rand_seed1=1, rand_seed2=2;
328+
create or replace table t1 (a int, v vector(1) not null, vector(v) max_edges_per_node=6);
329+
insert into t1 select seq, vec_fromtext(concat('[',seq,']')) from seq_1_to_200;
330+
update t1 set v = vec_fromtext(concat('[33]')) where a <= 15;
331+
select a, vec_totext(v) from t1 order by vec_distance_euclidean(v,vec_fromtext('[33]')) limit 25;
332+
a vec_totext(v)
333+
1 [33]
334+
10 [33]
335+
11 [33]
336+
12 [33]
337+
13 [33]
338+
14 [33]
339+
15 [33]
340+
2 [33]
341+
28 [28]
342+
29 [29]
343+
3 [33]
344+
30 [30]
345+
31 [31]
346+
32 [32]
347+
33 [33]
348+
34 [34]
349+
35 [35]
350+
36 [36]
351+
37 [37]
352+
4 [33]
353+
5 [33]
354+
6 [33]
355+
7 [33]
356+
8 [33]
357+
9 [33]
358+
drop table t1;

mysql-test/main/vector2.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,14 @@ drop table t;
246246
create table t1 (f vector(1) default 0x30313233, v vector(2) default x'4041424344454647');
247247
show create table t1;
248248
drop table t1;
249+
250+
--echo #
251+
--echo # MDEV-35246 Vector search skips a row in the table
252+
--echo #
253+
set rand_seed1=1, rand_seed2=2;
254+
create or replace table t1 (a int, v vector(1) not null, vector(v) max_edges_per_node=6);
255+
insert into t1 select seq, vec_fromtext(concat('[',seq,']')) from seq_1_to_200;
256+
update t1 set v = vec_fromtext(concat('[33]')) where a <= 15;
257+
--sorted_result
258+
select a, vec_totext(v) from t1 order by vec_distance_euclidean(v,vec_fromtext('[33]')) limit 25;
259+
drop table t1;

sql/vector_mhnsw.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,7 @@ static int select_neighbors(MHNSW_Share *ctx, TABLE *graph, size_t layer,
906906
const float target_dista= vec->distance_to_target / alpha;
907907
bool discard= false;
908908
for (size_t i=0; i < neighbors.num; i++)
909-
if ((discard= node->distance_to(neighbors.links[i]->vec) < target_dista))
909+
if ((discard= node->distance_to(neighbors.links[i]->vec) <= target_dista))
910910
break;
911911
if (!discard)
912912
target.push_neighbor(layer, node);

0 commit comments

Comments
 (0)