Skip to content

refactor(fulltext): move text analysis and ranking into Rust - #2797

Open
footka wants to merge 24 commits into
masterfrom
fulltext
Open

footka wants to merge 24 commits into
masterfrom
fulltext

Conversation

@footka

@footka footka commented Dec 2, 2026

Copy link
Copy Markdown
Member

解决方案

  • 将全文分词、IK 词典、布尔查询编译、BM25、倒排合并和 Top‑K 排名迁到 Rust。
  • 由 Rust 决定倒排扫描模式与字段权重校验。C++ 负责 SQL 计划、存储游标和现有 SQL 错误映射。
  • 复用数据块的 BM25 剪枝上界,减少排名过程中对同一窗口的重复计算。
  • 移除旧的 C++ 分词与排名实现、IK 字典系统表、字典缓存及对应构建输入。

footka added 23 commits December 2, 2026 12:25
Observer supplies the active DAS text retrieval engine. Delete its unused SQL-side predecessors and the retrieval program with no installed factory. Add direct includes and resolve vector types whose scope depended on unity source order.

Verified with the Linux x86_64 release seekdb build and git diff --check.
Share one native scorer between retrieval and the existing SQL function. Keep the portable libm logarithm and preserve the order of operations for scores and existing block statistics.

Verified with Cargo tests on Rust 1.100.0, a mutation of the IDF floor, a Linux x86_64 release build, and matching SQL BM25 results on the baseline and candidate.
Share the query parser and term binding with SQL planning. Pack the normalized terms and the scoring program for the retrieval executor. Keep database encoding conversion in the SQL adapter.

Verified with four Rust unit tests on 1.100.0 and a Linux x86_64 release seekdb build.
Feed posting batches and numeric corpus statistics from the DAS snapshot into the native ranker. Switch the Boolean query program to its Rust representation and retire the internal BM25 expression tree. Keep block scans and SQL projection in their existing owners.

Verified with the Linux x86_64 release build and seven Rust tests. SQL exposed a score-tied top-k row selection difference in simple_query, tracked for the follow-up ranking change.
Use one analyzer for DML, backfill, natural MATCH, planning and TOKENIZE. Keep the database collation adapter and index row layouts. Load built-in IK dictionaries into a shared Rust trie and remove the retired SQL loaders, table locks and dictionary tables.

Verified with cargo test --offline -p fulltext-analysis --features cxx and git diff --check. Full server build and SQL verification are tracked in the full-text handoff.
Avoid one allocation per occurrence and avoid creating a stopword collation map for ASCII documents. Keep exact database collation equivalence for non-ASCII terms. Apply basic English length limits after the original charset lowercase operation.

Verified with cargo test --offline -p fulltext-analysis --features cxx, including filtered frequencies and overlapping n-grams, and git diff --check.
…afely

Use the legacy score-only replacement and sift semantics while allocating the heap only as matches arrive. Convert the persisted BM25 reference pair into a conservative query-time upper bound, including a fixture where a different posting wins after length normalization.

Verified seven fulltext Rust tests, including weighted pruning, seek reduction and ranking ties. SQL rerun underway.
Remove the obsolete text DAAT, TAAT, BMW and lookup iterators together with their text-only ObSR helper classes. Retain the active sparse-vector retrieval factory and shared block-statistic iterator, returning raw BM25 reference statistics for text and preserving sparse inner-product scoring.

Reference audit found no callers of the deleted symbols beyond the removed group. Full O2 build and SQL rerun are in progress.
Assert that the retired dictionary cache cannot be flushed. Cover one whole document spanning the old IK batch boundary and verify mixed-language smart and max-word behavior.

Verified with the focused cn_word SQL regression and eight native analysis tests.
The Boolean match program runs in the native Rust ranker. Keep the SQL-callable BM25 function as a datum adapter and use the same Rust scoring formula.

Verified the replacement native query and score behavior with Cargo tests. Server verification runs on the combined worktree.
Keep the existing rowset bound for point lookup and let normal TAAT scans use fixed windows. Fetch scalar rows in one source callback and preserve the first execution failure.

Verified eleven native retrieval and scoring tests and a ranking-only Linux release build.
Include SQL candidates with the same BM25 score when a secondary key or WITH TIES decides the boundary. Keep the existing SQL sorter for those queries.

Reproduced on origin/master with three tied rows, where LIMIT 2 selected IDs 10 and 30 instead of 10 and 20. The added mysqltest asserts the correct two IDs.
Record the fulltext analysis and ranking crate manifests from the combined workspace. Verified Cargo resolution with offline locked native tests.
Reserve term cursors, Boolean buffers and CXX input copies before filling them. Accumulate bounded TAAT candidates in a reusable hash table and max-key heap with fallible growth. Walk sorted lookup ordinals to preserve duplicates and miss scores without an allocation per key.

Nine fulltext Cargo tests and cargo check with the CXX feature passed. The preceding Linux O2 branch revision passed 16 local and 8 downstream SQL cases.
Keep word and n-gram boundaries across character batches and retain only unique collation classes and grouped terms across normalization batches. Reserve document buffers fallibly and report allocation errors without publishing partial terms. Preserve IK arbitration while emitting its resolved spans into the same batch pipeline.

Verified with nine native Cargo tests, including a 10,000-character ngram2 document with 16 unique collation groups and an equivalent spelling in its last batch, and git diff --check.
Identify the Observer implementation as the active posting source. Name the persisted BM25 pair for its reference score, and saturate a pushed limit plus offset before conversion to the Rust capacity.

Verified the affected production call sites and git diff --check. The Linux release build and SQL regression run target the combined worktree.
Limit the tie guard to descending retrieval, which applies a score-only cutoff. Preserve the old SQL errors for null and non-positive field boosts. Fit the collation allocator label within the database limit.

The previous combined run passed all 19 local SQL cases. The downstream general_query and ES mode diffs isolated these plan and error-message changes, and the release compiler identified the label length.
Compile the Boolean expression in Rust and transfer its handle through DAS. Each ranking run shares the validated expression and owns its scan state. Return a ranking handle only on successful construction and reset block iterators directly during scan reuse.

Verified with the O2 seekdb build, 11 fulltext Rust tests, and SQL comparisons for grouped terms, repeated terms, lookups, and nested-loop rescans.
Carry the parsed analyzer kind through SQL and build a valid analysis handle in one call. Emit canonical JSON only for DDL. Check SQL integer options in statement order, then validate parser compatibility and cross-field constraints when building the index.

Verified with the O2 seekdb build, nine analyzer Rust tests, and baseline SQL comparisons for TOKENIZE, DDL readback, duplicate properties, and error order.
The IK dictionary is initialized once per process and the old cache name is gone. Remove the flush, its admin connection, and its expected error from cn_word. Keep the insert and search checks.

The product fts_index.cn_word case passed on Linux x86_64 host 37 against seekdb fcd8c9e.
IK loads bundled word and quantifier lists. The old table options, unused stopword file, and retired dictionary DDL state no longer have a runtime role.

Remove the parser properties and resolver paths together, drop the unused data file, and simplify the fulltext index build state machine.

Verified with an optimized seekdb build, 10 Rust tests, and a mysqltest smoke on 6.13.50.37 for SQL error 1064 on the three removed options, a working IK index, and absent dictionary tables. The smoke binary still declared the three unused item type constants removed in this commit.
Keep scan-mode and nonpositive boost rules with the native Rust query and ranking APIs. DAS consumes the resulting mode before allocating storage iterators and maps Rust errors to the established SQL errors.

Verified the 256/257-token boundary, lookup restrictions, and duplicate Boolean term selection in Rust. The combined change built in O2 and passed 20 product mysqltests and the 146-case downstream baseline comparison on 6.13.50.37.
Repeatedly evaluating the same block bounds increased CPU work on score-only Top-K. Keep the weighted bound with its block and reuse the outcome until the cursor leaves its window or the heap threshold increases enough to prune.

Verified in five paired 100k-document runs on 6.13.153.80. Double-term Top-20 p50 falls from 3.66 ms toward 2.87 ms, with both Recall@10 and Recall@100 at 100%. The 21 Rust tests and 20 product mysqltests passed, and all 23 downstream failure signatures matched the preceding release.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-02T04:37:26.861986Z 976291a PR opened
🔒 Security Review ✅ Completed 2026-12-02T04:37:19.398847Z 976291a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Keep the fixed ngram window inline to avoid a per-document heap allocation. Compile the two DDL helpers only when their CXX callers are enabled.

Ran the full CI Clippy command with warnings denied and tested fulltext-analysis with and without CXX.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant