Skip to content

[4.2-dev] fix(fulltext): lowercase a <3-rune NL pattern before the prefix search (#30484) - #30612

Merged
XuPeng-SH merged 2 commits into
matrixorigin:4.2-devfrom
cpegeric:bug_30484_4.2
Oct 22, 2026
Merged

XuPeng-SH merged 2 commits into
matrixorigin:4.2-devfrom
cpegeric:bug_30484_4.2

Conversation

@cpegeric

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #30484

What this PR does / why we need it:

Backport of #29296 / PR #29354 (d99187d7b3) to 4.2-dev.

On the 4.2 line, a classic FULLTEXT natural-language query term shorter than
3 runes that contains uppercase
silently matched nothing — DB, Db, Xy,
XY → empty, while db/xy and any length-≥3 term (ABC, MatrixOne) work.
This hits the very common 2-letter uppercase acronyms (AI, DB, ID, UI,
IP, VM, …) as a silent under-recall.

Root cause

ParsePatternInNLMode handles a term shorter than ngram_size (3) with a
prefix (STAR) shortcut that built the pattern from the raw query string,
bypassing the case-folding the SimpleTokenizer applies to longer terms (and
that the document side applies at index time). So DB became the prefix DB*
and looked up the lowercased stored token db, matching nothing. (Boolean mode
was unaffected — it lowercases the whole pattern up front.)

Fix (cherry-picked from main)

Normalize the short pattern the same way the index stores tokens:
normalizeShortPattern folds only Latin-class runes (<0x7FF, matching
outputLatin) and preserves wider runes verbatim (outputCJK). A blanket
strings.ToLower would be wrong — it would fold full-width/CJK capitals like
A/ẞ that the ngram index stores cased; json_value is preserved verbatim.

Cherry-pick is clean in pkg/fulltext/fulltext.go; the only conflict was an
adjacent test block in jieba_test.go (other backlog tests not part of this
fix), resolved to keep exactly #29296's three regression tests.

Validation (on 4.2-dev)

🤖 Generated with Claude Code

matrixorigin#29296) (matrixorigin#29354)

- [ ] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [ ] Test and CI
- [ ] Code Refactoring

issue matrixorigin#29296

A classic-fulltext natural-language / default `MATCH ... AGAINST`
pattern shorter than 3 runes was turned into a `STAR` prefix of the
**raw** pattern by `ParsePatternInNLMode`, with no case folding. Indexed
Latin tokens are stored lowercased (`SimpleTokenizer.outputLatin`) and
`prefix_eq` is case-sensitive, so `AGAINST('Hi')` / `'HI'` / `'Ab')`
prefix-searched the capitalized string and returned **0 rows** even
though the documents contain `high` / `hi` / `Abyss`.

Boolean mode already lowercases its whole pattern, and a ≥3-rune NL
pattern folds case through the tokenizer — only this short branch missed
it.

**Fix:** lowercase the pattern before appending `*`:
```go
return []*Pattern{{Text: strings.ToLower(pattern) + "*", Operator: STAR}}, nil
```
The other short-pattern `STAR` sites in the same function build from
tokenizer output (already lowercased), so this is the only site. The
`<3`-rune prefix rule and the ≥3-rune exact-token rule are unchanged,
and the `-5` breaker-prefix case is out of scope. fulltext2 already
lowercases its own query path.

Live: `Hi` / `HI` → `{1,2}`, `Ab` / `AB` → `{5}` (all were empty);
lowercase controls, `hig` (3-rune exact → no match), and `HIGH` (≥3
tokenized → `{1}`) unchanged.

- Unit `TestParsePatternInNLModeShortLowercases` over `""` / `ngram` /
`default` (plus the `hig` exact-token control), **proven to fail on the
pre-fix code**.
- BVT `fulltext_short_pattern_case` locks the SQL behavior.
- Full `pkg/fulltext` UT and the classic `fulltext` (1636) and
`fulltext2` (909) BVT suites pass; gofmt clean.

---------

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
Co-authored-by: XuPeng-SH <[email protected]>
(cherry picked from commit d99187d)
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify mergify Bot added the kind/bug Something isn't working label Oct 19, 2026
@matrix-meow matrix-meow added the size/M Denotes a PR that changes [100,499] lines label Oct 19, 2026
XuPeng-SH added a commit that referenced this pull request Oct 20, 2026
## What type of PR is this?

- [x] API-change
- [x] BUG
- [ ] Improvement
- [ ] Documentation
- [ ] Feature
- [x] Test and CI
- [ ] Code Refactoring

## Which issue(s) this PR fixes:

Related to #30231.

## What this PR does / why we need it:

Fix two independently reproduced UT flake mechanisms seen in #30609 and
#30612 on `4.2-dev`:

- Scope catalog admission hooks to the intended service, connection and
active transaction. An unrelated transaction on the same CN could
capture the barrier and leave the writer admission count at zero. Apply
the same ownership rule to the neighboring DDL-first and stale-ALTER
fixtures. Add real competing SQL before and during the paused writer;
retain all ALTER/standalone, retry, rollback, result and
neighboring-index assertions.
- Semantic-backport main's optional caller-context CN label API from
#30337, preserving the legacy three-second operational API and existing
HAKeeper execution path. Use a bounded phase context and authoritative
refresh in the IVF integration test. Remove redundant label updates and
resultless refresh polling.
- Serialize strict-boundary invalidation with cleanup. Cancel and join
the callback before restoring labels with a fresh context; attempt every
target after partial failure and report cleanup errors. Check exact CN
identities and both labels.

Validation (Go 1.26.4, Darwin/arm64, matching native libraries):

- Full `clusterservice` and operational `ctl` packages: normal and race.
- All affected Issue29715/27966 tests: normal and race.
- Ten race repetitions of ALTER/standalone late admission; three race
repetitions of the real IVF test.
- Deadline/error/identity and partial-update/refresh/cleanup unit cases;
configured incremental gofmt, vet, molint and golangci-lint.
- `gpt-6.1-sol` / `xhigh` design and overall review.

No production query-path, wire, schema or global-timeout change. This
fixes the demonstrated fixture mechanisms; it does not establish the
physical cause of the historical HAKeeper slowdown or eliminate every
possible CI flake. Linux CI remains pending.

### CI follow-up

The first Linux run exposed two additional test synchronization defects:

- Lock caller-deadline tests shared the holder's setup budget, then
asserted a lower bound on only the remaining wait. Separate setup from
the fresh caller deadline, observe real contention, and require
`context.DeadlineExceeded` rather than elapsed-time floors. Cover zero
and explicit lock timeouts and successful release; cancel, release and
join workers before restoring private hooks.
- The tenant stage/fulltext2 test polled MATCH before CDC readiness.
Wait for the durable tail before the first content query, using the same
boundary as its mutation checks. Bound tail/checksum SQL with one
30-second context per transition, report SQL errors, and stop indexed
work before closing the HTTP source. Preserve TXT/PDF/Chinese/DOCX,
mutation, compaction/HNSW and authorization assertions.

A real-SQL diagnostic probe observed an initial empty MATCH, recovery
after durable tail, and successful first MATCH on a fresh
readiness-first table. It did not reproduce a persistent stale cache or
prove the historical failure's exact cache state; no diagnostic eviction
is included in the patch.

Additional local validation: complete lockservice/embed packages in
normal and race modes; final changed lock cases in normal/race with ten
bounded repetitions; three focused readiness-root race repetitions; two
expected-failure controls rejecting premature errors and ignored caller
contexts; incremental formatting/vet/molint/lint. The `gpt-6.1-sol` /
`xhigh` review's cleanup finding was corrected and re-reviewed.

The old UT run also exhausted the outer 60-minute wrapper before
plan/report completion. These focused corrections do not establish a
whole-CI runtime improvement. PROXY's check annotation reports that its
hosted runner lost communication; its absent coverage is a consequence
of that interruption. New-head remote CI remains pending.
@XuPeng-SH

XuPeng-SH commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-xupeng · done

Commit: 6c9643db481a0072b2e0683ff0db46174763efb6

Review completed. Read the assessment.

@XuPeng-SH

XuPeng-SH commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

mo-bot review · mo-bot-local · done

Commit: 6c9643db481a0072b2e0683ff0db46174763efb6

Review completed. Read the assessment.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-local · review

Commit: 6c9643db481a0072b2e0683ff0db46174763efb6

Assessment: approve

Reviewed all four changed files and surrounding callers. The normalization helper correctly restores short uppercase NL matches while preserving wide-character and json_value case semantics. Added work is bounded to fewer than three runes, with no new shared state or I/O. No actionable findings remain.

Model: gpt-6-astra / xhigh

Session: 01a13dcf-1517-7f90-b3f9-c5f9f9e7031b · slot 0 · generation 1

Validation:

  • All three added regressions and two independent probes passed. Tokenizer and generated-SQL parity covered 5,679 short inputs across parser aliases, NL/default modes and BM25/TFIDF.

  • All 73 pkg/fulltext tests passed using the supplied isolated executor. The same parity probe failed with the exact merge-base production file on uppercase A versus stored token a, confirming detection of the original defect.

  • Verified unchanged frozen source, the complete patch, 8,439 tracked-file hashes and 171 native-input hashes. Repository-owned native build, receipt reconciliation and git diff --check passed.

  • Evidence: /home/xupeng/.local/state/mo-bot/jobs/63d3840d4e56ab10ab752a57/attempt-1/validation-audit.json. Final audit receipt: checks/1792496525487426137-4.json.

  • Frozen evidence reports successful Ubuntu UT and proxy/pessimistic BVT checks.

Limitations:

  • The 25-statement SQL fixture was reviewed but not rerun locally. Local probes validate tokenization and generated SQL, not server execution; raw CI and author BVT logs were not supplied.

  • The linked issue body was unavailable. Performance cost was assessed from bounded code paths; no benchmark or race stress was warranted for this stateless sequential change.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mo-bot review · mo-bot-xupeng · review

Commit: 6c9643db481a0072b2e0683ff0db46174763efb6

Assessment: approve

Reviewed the complete four-file delta and relevant callers. Short-query normalization matches document tokenization while preserving wide-character and json_value case semantics. No actionable defects or material coverage omissions found.

Model: gpt-6-astra / xhigh

Session: 01a14d34-4e51-79a3-a62d-6c9c16279dc8 · slot 0 · generation 0

Validation:

  • Isolation preflight passed. Native prerequisites were built through repository Makefiles from verified current-revision inputs.

  • All three added regressions passed; full pkg/fulltext and pkg/monlp/tokenizer suites passed with -count=1 through test-exec.

  • Diagnostic probes passed for 1,875 short inputs across four parsers, comparing actual document tokens with generated prefix SQL; JSON-value case preservation also passed.

  • Source remained unchanged and git diff --check passed. Commands, source fingerprints, exit receipts, logs and diagnostic hashes were reconciled in /home/xupeng/.local/state/mo-bot/jobs/58ef1642309ae1bb05903940/attempt-1/review-evidence.json.

Limitations:

  • Distributed SQL BVT was reviewed but not rerun locally. Frozen CI success summaries and author execution claims lacked raw logs for independent per-case verification.

  • Linked issue #30484 text was absent from the supplied evidence; its behavioral contract was assessed from the PR description and frozen sources.

This branch was previously deployed

1 inactive deployment
ci — 2529b0bc Deployed Oct 22, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/M Denotes a PR that changes [100,499] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants