-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathvector_bulk.test
More file actions
51 lines (41 loc) · 1.98 KB
/
Copy pathvector_bulk.test
File metadata and controls
51 lines (41 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
--echo #
--echo # Test memory budget fallback during MHNSW bulk insert
--echo #
--echo # 1. Normal bulk insert works when memory budget is large enough
create table t1 (id int auto_increment primary key, v vector(3) not null);
insert into t1 (v) values (x'000000000000000000000000'),
(x'0000803f0000000000000000'),
(x'000000000000803f00000000'),
(x'00000000000000000000803f');
alter table t1 add vector index (v);
show warnings;
--echo # Test search using the successfully bulk-built index
--replace_regex /(\.\d{5})\d+/\1/
select id, vec_distance_euclidean(v, x'0000803f0000000000000000') d from t1 order by d limit 2;
drop table t1;
--echo # 2. Bulk insert falls back to normal insert when mhnsw_max_cache_size is small
set @old_cache_size= @@global.mhnsw_max_cache_size;
set global mhnsw_max_cache_size= 1048576;
set max_recursive_iterations= 300;
create table t1 (id int auto_increment primary key, v vector(3000) not null);
# Insert 115 rows of 3000-dimensional vectors.
# Total size: 115 * ~9288 bytes/row (with M=200) = ~1.06 MB, exceeding 1MB.
insert into t1 (v)
with recursive cte as (
select 1 as n
union all
select n + 1 from cte where n < 115
)
select repeat(x'00', 12000) from cte;
# Insert a unique search target vector with fixed ID 999 to guarantee deterministic results across all engines
insert into t1 (id, v) values (999, concat(repeat(x'00', 11996), x'0000803f'));
--echo # Adding index with small cache size should trigger fallback and show a warning
--replace_regex /usage \(\d+\)/usage (estimated_mem)/
alter table t1 add vector index (v) m=200;
--replace_regex /usage \(\d+\)/usage (estimated_mem)/
show warnings;
--echo # Test search using the fallback-built index to ensure it is healthy and correct
--replace_regex /(\.\d{5})\d+/\1/
select id, vec_distance_euclidean(v, concat(repeat(x'00', 11996), x'0000803f')) d from t1 order by d limit 1;
drop table t1;
set global mhnsw_max_cache_size= @old_cache_size;