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
bb60e5b1
Commit
bb60e5b1
authored
Jun 05, 2024
by
Sergei Golubchik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
mhnsw: don't create many empty layers
parent
ab3de9d9
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
20 deletions
+18
-20
sql/vector_mhnsw.cc
sql/vector_mhnsw.cc
+18
-20
No files found.
sql/vector_mhnsw.cc
View file @
bb60e5b1
...
...
@@ -559,8 +559,6 @@ int mhnsw_insert(TABLE *table, KEY *keyinfo)
return
write_neighbors
(
&
ctx
,
0
,
target
);
}
longlong
max_layer
=
graph
->
field
[
0
]
->
val_int
();
List
<
FVectorNode
>
candidates
;
List
<
FVectorNode
>
start_nodes
;
String
ref_str
,
*
ref_ptr
;
...
...
@@ -585,36 +583,37 @@ int mhnsw_insert(TABLE *table, KEY *keyinfo)
double
new_num
=
my_rnd
(
&
thd
->
rand
);
double
log
=
-
std
::
log
(
new_num
)
*
NORMALIZATION_FACTOR
;
longlong
new_node_layer
=
static_cast
<
longlong
>
(
std
::
floor
(
log
));
longlong
max_layer
=
graph
->
field
[
0
]
->
val_int
();
// XXX what is that?
for
(
longlong
cur_layer
=
new_node_layer
;
cur_layer
>=
max_layer
+
1
;
cur_layer
--
)
if
(
new_node_layer
>
max_layer
)
{
if
(
int
err
=
write_neighbors
(
&
ctx
,
cur_layer
,
target
))
if
(
int
err
=
write_neighbors
(
&
ctx
,
max_layer
+
1
,
target
))
return
err
;
new_node_layer
=
max_layer
;
}
for
(
longlong
cur_layer
=
max_layer
;
cur_layer
>
new_node_layer
;
cur_layer
--
)
else
{
if
(
int
err
=
search_layer
(
&
ctx
,
start_nodes
,
thd
->
variables
.
hnsw_ef_constructor
,
cur_layer
,
&
candidates
))
return
err
;
start_nodes
.
empty
();
start_nodes
.
push_back
(
candidates
.
head
(),
&
ctx
.
root
);
// XXX ef=1
candidates
.
empty
();
for
(
longlong
cur_layer
=
max_layer
;
cur_layer
>
new_node_layer
;
cur_layer
--
)
{
if
(
int
err
=
search_layer
(
&
ctx
,
start_nodes
,
thd
->
variables
.
hnsw_ef_constructor
,
cur_layer
,
&
candidates
))
return
err
;
start_nodes
.
empty
();
start_nodes
.
push_back
(
candidates
.
head
(),
&
ctx
.
root
);
// XXX ef=1
candidates
.
empty
();
}
}
for
(
longlong
cur_layer
=
std
::
min
(
max_layer
,
new_node_layer
);
cur_layer
>=
0
;
cur_layer
--
)
for
(
longlong
cur_layer
=
new_node_layer
;
cur_layer
>=
0
;
cur_layer
--
)
{
if
(
int
err
=
search_layer
(
&
ctx
,
start_nodes
,
thd
->
variables
.
hnsw_ef_constructor
,
cur_layer
,
&
candidates
))
return
err
;
uint
max_neighbors
=
(
cur_layer
==
0
)
?
// heuristics from the paper
thd
->
variables
.
hnsw_max_connection_per_layer
*
2
uint
max_neighbors
=
(
cur_layer
==
0
)
// heuristics from the paper
?
thd
->
variables
.
hnsw_max_connection_per_layer
*
2
:
thd
->
variables
.
hnsw_max_connection_per_layer
;
if
(
int
err
=
select_neighbors
(
&
ctx
,
cur_layer
,
target
,
candidates
,
...
...
@@ -624,7 +623,6 @@ int mhnsw_insert(TABLE *table, KEY *keyinfo)
return
err
;
start_nodes
=
candidates
;
}
start_nodes
.
empty
();
dbug_tmp_restore_column_map
(
&
table
->
read_set
,
old_map
);
...
...
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