Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
f629c96c
Commit
f629c96c
authored
Jun 05, 2024
by
Sergei Golubchik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mhnsw: don't prefix blob ref array with its length
parent
bb60e5b1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
20 deletions
+5
-20
sql/vector_mhnsw.cc
sql/vector_mhnsw.cc
+5
-20
No files found.
sql/vector_mhnsw.cc
View file @
f629c96c
...
...
@@ -28,11 +28,6 @@
#include "sql_queue.h"
#include <scope.h>
#define HNSW_MAX_M 10000 // practically the number of neighbors should be ~100
#define HNSW_MAX_M_WIDTH 2
#define HNSW_MAX_M_store int2store
#define HNSW_MAX_M_read uint2korr
const
LEX_CSTRING
mhnsw_hlindex_table
=
{
STRING_WITH_LEN
(
"\
CREATE TABLE i ( \
layer int not null, \
...
...
@@ -158,18 +153,11 @@ int FVectorNode::instantiate_neighbors(size_t layer)
return
err
;
String
strbuf
,
*
str
=
graph
->
field
[
2
]
->
val_str
(
&
strbuf
);
const
char
*
neigh_arr_bytes
=
str
->
ptr
();
uint
number_of_neighbors
=
HNSW_MAX_M_read
(
neigh_arr_bytes
);
if
(
number_of_neighbors
*
ref_len
+
HNSW_MAX_M_WIDTH
!=
str
->
length
())
if
(
str
->
length
()
%
ref_len
)
return
HA_ERR_CRASHED
;
// should not happen, corrupted HNSW index
const
char
*
pos
=
neigh_arr_bytes
+
HNSW_MAX_M_WIDTH
;
for
(
uint
i
=
0
;
i
<
number_of_neighbors
;
i
++
)
{
FVectorNode
*
neigh
=
ctx
->
get_node
(
pos
);
neighbors
[
layer
].
push_back
(
neigh
,
&
ctx
->
root
);
pos
+=
ref_len
;
}
for
(
const
char
*
pos
=
str
->
ptr
();
pos
<
str
->
end
();
pos
+=
ref_len
)
neighbors
[
layer
].
push_back
(
ctx
->
get_node
(
pos
),
&
ctx
->
root
);
}
neighbors_read
[
layer
]
=
1
;
}
...
...
@@ -350,16 +338,13 @@ static int write_neighbors(MHNSW_Context *ctx, size_t layer,
int
err
;
TABLE
*
graph
=
ctx
->
table
->
hlindex
;
const
List
<
FVectorNode
>
&
new_neighbors
=
source_node
.
get_neighbors
(
layer
);
DBUG_ASSERT
(
new_neighbors
.
elements
<=
HNSW_MAX_M
);
size_t
total_size
=
HNSW_MAX_M_WIDTH
+
new_neighbors
.
elements
*
source_node
.
get_ref_len
();
size_t
total_size
=
new_neighbors
.
elements
*
source_node
.
get_ref_len
();
// Allocate memory for the struct and the flexible array member
char
*
neighbor_array_bytes
=
static_cast
<
char
*>
(
my_safe_alloca
(
total_size
));
// XXX why bother storing it?
HNSW_MAX_M_store
(
neighbor_array_bytes
,
new_neighbors
.
elements
);
char
*
pos
=
neighbor_array_bytes
+
HNSW_MAX_M_WIDTH
;
char
*
pos
=
neighbor_array_bytes
;
for
(
const
auto
&
node
:
new_neighbors
)
{
DBUG_ASSERT
(
node
.
get_ref_len
()
==
source_node
.
get_ref_len
());
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment