← Back to Pull requests

MDEV-37559 MDEV-42375 MDEV-42376 MHNSW: exact visited set, search statistics kept across cache resets, reachable pruned nodes #6201

Open
unknown opened this pull request with 594 lines diff across 7 files
View on GitHub
unknown unknown commented on Nov 23, 2026 22:59 UTC
Author

  • The Jira issue number for this PR is: MDEV-42375 (also MDEV-42376 and MDEV-37559, one commit each)
  • 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 where malloc() 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() discarded ef_power and diameter together 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 mariadbd on 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


  • The commit-time invalidation of unchanged nodes is not part of this pull request; it is MDEV-39832 (#5173).

  • PatternedSimdBloomFilter is no longer used. bloom_filters.h is 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_reset searches 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_reachable searches every row with a cache that holds the graph and retries each miss with mhnsw_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_myisam and main.vector_debug were 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


  • This is a new feature or a refactoring, and the PR is based against the main branch.

  • This is a bug fix, and the PR is based against the earliest maintained branch in which the bug can be reproduced.
  • PR quality check


  • I checked the CODING_STANDARDS.md file and my PR conforms to this where appropriate.

  • For any trivial modifications to the PR, I am ok with the reviewer making the changes themselves.
  • Diff: 594 lines (+445 / -149) across 7 files Reviewer: gkodinov Review duration: 10517m
    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
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 50% (MEDIUM) · Higher = larger blast radius
    50%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 26.7% · Safe to merge
    26.7%
    Repository