MDEV-37559 MDEV-42375 MDEV-42376 MHNSW: exact visited set, search statistics kept across cache resets, reachable pruned nodes #6201
All Vouch review confidence checks passed
Residual risk 0.27 = Change Risk (0.50) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.50 · 594 lines diff across 7 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.382
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #6201"
general
weight: 0.35
gkodinov
Description
This pull request fixes three causes of rows missing from MHNSW vector index searches. Each commit is self-contained and adds the test that fails without it.
1. MDEV-37559 (main.vector sporadic failures):
search_layer()recorded the visited nodes in a Bloom filter, whose false positives make the search skip nodes it has never visited, together with every node reachable only through them. The filter is replaced by an exact open addressing hash set of node addresses that doubles when it is half full, so the result no longer depends on wheremalloc()placed the nodes, and a search that visits more nodes than estimated no longer saturates it.2. MDEV-42375: when the graph is larger than
mhnsw_max_cache_size,reset()discardedef_poweranddiametertogether with the share, so every search after a reset started from the defaults and terminated early. The replacement share now inherits them.3. MDEV-42376: when
update_second_degree_neighbors()prunes a full neighbor list, a dropped node could lose its last incoming link, and no search reached it afterwards. Such a node now replaces the farthest newly selected neighbor that is still linked from another node.We found these issues in production (MariaDB 12.3.3, 165,000 rows,
VECTOR(192),M=16 DISTANCE=cosine, default cache), where 2.3% of the rows were not returned when searched with their own vector. The details are in MDEV-42375 and MDEV-42376.Cost
CPU time of
mariadbdon the data of the new tests:| | insert 20,000 rows | 2,000 searches, 1 MiB cache | 2,000 searches, 1 GiB cache (warm) |
|---|---|---|---|
| 11.8 | 23.6 s | 5.0 s, 500 rows not found | 0.38 s, 84 rows not found |
| this pull request | 55.9 s | 17.5 s, 1 row not found | 0.36 s, 0 rows not found |
Searches with a cache that holds the graph cost the same. Inserts on 11.8 take about 2.4 times longer, because the construction searches now visit the nodes that the saturated filter used to skip; with 11.8 as it is, the resulting graph loses 84 of the 2,000 rows even with a 1 GiB cache. Searches with a cache that is too small cost more because they no longer stop early.
Notes
PatternedSimdBloomFilteris no longer used.bloom_filters.his still included for its SIMD target macros; I can remove the class here or in a separate change, as you prefer.Release Notes
Vector index searches no longer miss rows when the index graph is larger than
mhnsw_max_cache_size, rows no longer become unreachable through a vector index after inserts, and vector search results no longer vary between runs because of false positives in the tracking of visited nodes. Inserts into a vector index can take longer, as the graph is now built from complete searches. No system or status variables change.How can this PR be tested?
Two tests are added, both with 20,000 clustered 192-dimensional vectors and
M=16 DISTANCE=cosine:main.vector_cache_resetsearches 2,000 rows with their own vector and a 1 MiB cache. As the search is approximate, it accepts fewer than 10 rows not found.main.vector_reachablesearches every row with a cache that holds the graph and retries each miss withmhnsw_ef_search=10000; no row may be missed.MDEV-37559 is shown by running the existing tests repeatedly:
./mtr --repeat=200 main.vector2 main.vector_innodb.Results on 11.8 after each commit:
| | rows not found (
vector_cache_reset) | rows no search reaches (vector_reachable) |main.vector2/main.vector_innodb,--repeat=200||---|---|---|---|
| 11.8 | 512 | 155 | failed on run 27 / on run 63 |
| + MDEV-37559 | 36 | 6 | 200 / 200 passed |
| + MDEV-42375 | 1 | 6 | 200 / 200 passed |
| + MDEV-42376 | 1 | 0 | 200 / 200 passed |
All vector tests pass at each commit (13 tests;
atomic.vector_innodb,atomic.vector_myisamandmain.vector_debugwere skipped because they require a debug build). Built and tested on aarch64 (Ubuntu 24.04, GCC 13.3, RelWithDebInfo).Basing the PR against the correct MariaDB version
mainbranch.PR quality check