Repository navigation
fix(fulltext): expand BOOLEAN trailing-star CJK stem to a positional phrase (#29273) - #29366
Conversation
…phrase (matrixorigin#29273) In classic fulltext BOOLEAN mode a trailing `*` did a prefix_eq of the whole stem. The ngram tokenizer stores a CJK stem as sliding trigrams (苹果香蕉 -> 苹果香/果香蕉/香蕉/蕉) and caps Latin tokens at 23 bytes, so prefix_eq'ing the raw stem matched a token that is never stored -> 0 rows. Expand a multi-trigram CJK (or multi-word gojieba) star stem into a positional phrase at SQL-gen time: leading exact piece(s) + last piece as prefix_eq + HAVING COUNT(*)=N. The parse tree stays a plain STAR leaf so the `+` form and the Index/leaf paths are untouched. Also cap the star prefix at the 23-byte stored-token boundary so an over-long Latin stem matches the truncated token. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Qodo reviews are paused for this user.Troubleshooting steps vary by plan Learn more → On a Teams plan? Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center? |
|
fixed |
…alue + linear CJK offsets (matrixorigin#29273) P1 (correctness): json_value stores each JSON value as ONE verbatim token (capped at 127 bytes by bytejson.fillToken), not trigrams. genStarPhraseSql routed json_value into cjkStarPhraseChildren, so `苹果香蕉*` required never-stored 苹果香/蕉 tokens and returned nothing; and truncateStarPrefix cut a json_value Latin query to the SimpleTokenizer 23-byte cap, so a 26-char prefix wrongly matched sibling values. Make both parser-aware: json_value returns ok=false (whole-value prefix_eq) and caps at 127 bytes. Other parsers are unchanged. P2 (perf): cjkStarPhraseChildren computed each child's byte Position via string(runes[:i]), re-encoding the whole preceding prefix every trigram -> O(n^2) on a long CJK stem. Track the byte offset in one pass so construction is linear. Add json_value SQL counterexamples (CJK whole-value star; 26-char Latin prefix) as unit + BVT, plus truncateStarPrefix/genStarPhraseSql json_value unit cases. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…ion boundary (matrixorigin#29273) truncateStarPrefix's non-json_value path used a clean UTF-8 backoff (inspecting the byte AT the 23-byte cut), but SimpleTokenizer.outputLatin keys off the last KEPT byte and drops a trailing multi-byte char that straddles the cap: `a`+12×`я` (25B) is stored as `a`+10×`я` (21B), not a clean 23B. The query therefore built a prefix one char longer than the stored token, so prefix_eq was false and a BOOLEAN `AGAINST('<multibyte-Latin >23B>*')` on an ngram index missed the row. Reuse tokenizer.TruncateLatinToken, which reproduces outputLatin's boundary exactly (the classic-fulltext analogue of the fulltext2 fix in matrixorigin#29276). ASCII, CJK trigram tails, and short gojieba words are unaffected. Assert the exact stored bytes (é×12->é×11, a+12я->a+10я, and !=clean-23B) plus an end-to-end SimpleTokenizer round-trip, and add a live Cyrillic BVT case. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
XuPeng-SH
left a comment
There was a problem hiding this comment.
Deep re-review of 0919d491e7 against 9322133017. All five changed files and the index-writer/tokenizer consumers were reviewed; no subagents.
Decision: approve this reviewed revision.
Previous findings are substantively closed:
- #discussion_r4106602574: all four STAR SQL-generation sites are parser-aware.
json_valueretains whole-value matching and its 127-byte cap; it does not enter CJK/jieba phrase expansion. - #discussion_r4106602583: CJK byte positions are accumulated once, removing repeated prefix re-encoding.
Design / QA audit:
- R2 query/index contract: checked ngram CJK positional tokens, short/exact/no-star controls, Latin/Cyrillic token boundaries, gojieba segmentation and json_value adjacent-prefix nonmatches. The unchanged index writer is the independent representation oracle.
- R2 scale: reviewer mixed 3-/4-byte Unicode and 24K-rune offset probes pass. A 5-iteration benchmark measured 6K/12K/24K runes at approximately 0.227/0.471/0.782 ms and 201/402/804 KB per operation. This supports linear construction, not a general query-execution speedup claim.
- Ownership / unhappy paths: generated patterns and SQL remain request-owned; jieba initialization errors propagate; no new worker, cache, wire/catalog format or index rebuild requirement. The shared native tokenizer retains its existing ownership contract.
- Engineering: reuses positional phrase SQL and tokenizer boundaries, without a second indexing implementation. No blocking overengineering finding.
Verification:
- Full
./pkg/fulltextsuite passed on this head, including gojieba (no skips). - The committed
fulltext_star_phrase.sql/.resultran in normal mo-tester comparison mode twice on the same exact-head embedded instance: 35/35 each, zero failed/ignored/abnormal. An independent catalog query confirmedft_star_phraseabsent after each run, before the next runner could clean it. - Exact-head CI run 36399151966 also actually selected this case: 35/35, not merely a green aggregate status.
The branch is behind its current target; this approval is tied to the SHA above and does not certify a future rebase or merge result.
aptend
left a comment
There was a problem hiding this comment.
Reviewed exact head 0919d49. Rechecked both prior findings against the incremental and complete diff, historical inline threads/replies, token storage semantics for ngram/gojieba/json_value, all four STAR SQL-generation paths, and the added SQL/Go regression cases. The CJK byte-position construction is linear and the parser-specific fallback matches the indexed token boundaries. No remaining blocking issue found. Head CI (UT, BVT, SCA) is green. Local focused rerun was unavailable because this isolated worktree has no matching CGo artifacts; I did not alter the primary checkout.
Merge Queue Status
This pull request spent 1 hour 10 minutes 35 seconds in the queue, including 1 hour 10 minutes 18 seconds running CI. Required conditions to merge
|
What type of PR is this?
Which issue(s) this PR fixes:
issue #29273
What this PR does / why we need it:
In classic fulltext (
MATCH ... AGAINSTin BOOLEAN mode), a trailing*on a CJK stem returned no rows for a document that clearly contains the stem, e.g.苹果香蕉*missed a row storing苹果香蕉.Root cause
BOOLEAN-mode
*was implemented asprefix_eq(word, stem)over the whole stem, but the ngram tokenizer never stores the whole stem:苹果香蕉→苹果香,果香蕉,香蕉,蕉— soprefix_eq(word, '苹果香蕉')matches nothing.MAX_TOKEN_SIZE(23 bytes), so an over-long Latin stem prefix-matched the untruncated string and missed the stored (truncated) token.Fix (
pkg/fulltextonly — no SQL/plan-layer changes)genStarPhraseSqlexpands a multi-trigram CJK stem (or a multi-word gojieba stem) into a positional phrase at SQL-gen time: the leading exact piece(s) + the last piece asprefix_eq, joined on a shared positional anchor withHAVING COUNT(*) = N. So苹果香蕉*becomesword = '苹果香'+prefix_eq(word,'蕉')— matching苹果香蕉/苹果香蕉西瓜but not the sibling苹果香瓜.(* stem*)STAR leaf, so the+苹果香蕉*form and the Index/leaf-extraction paths are untouched.truncateStarPrefixcaps the star prefix at the 23-byte stored-token boundary (rune-aware) at all prefix sites, fixing the Latin facet.苹果*,苹果香*) stays a plainprefix_eq— existing behavior.Test
pkg/fulltext/star_phrase_29273_test.go(CJK positional-phrase expansion, Latin 23-byte truncation, gojieba last-segment star).test/distributed/cases/fulltext/fulltext_star_phrase.{sql,result}covering ngram CJK (incl.+form and non-star controls), Latin truncation, and gojieba.fulltextBVT suite 1643/1643 andfulltext2909/909 — no regressions;gofmt/go vetclean.🤖 Generated with Claude Code