Repository navigation
Description
Is there an existing issue for performance?
- I have checked the existing issues.
Related work: #27801 (CJK phrase evaluation), #27250 (query-local metadata reuse), #27155 (deferred positions), #27245 (pure-term MUST). This issue consolidates measured evidence for three slow FULLTEXT2 query shapes and identifies two optimization tracks; it does not claim a new correctness defect.
Environment
- Measured commit:
6690f1af97977ad5671235e9204296cd2d504ad5. - Linux amd64, native Go 1.26.4 kernel harness on shared mo-129; C1,
GOMAXPROCS=4, 6 GiB cap. Accepted profiles had CPU idle above 92%, low iowait and no swap-out. Resource-gated, not host-exclusive. - Real 100k-document subset; ten 10k-document positional segments; BM25, TopK100, no business filter. Heap-backed deserialization, not the SQL service/cache path.
- Frozen query packs from nightly 35241042673. CPU profiles compare pre-parsed search-only with query-construction-plus-search; allocation and counters use separate runs.
Details of Performance
Main finding
The selected queries are search-bound, not primarily tokenizer-bound. There are two distinct problems to investigate:
- ngram natural/MUST: short CJK prefixes trigger expensive posting materialization; MUST also repeats phrase matching for global DF before final intersection.
- gojieba BOW: WAND spends substantial CPU evaluating block bounds and aligning cursors, with little whole-block skipping for the selected query.
Source check on 2026-09-22, main 3727c5c5436ca136d7b0312f75bc223a11692a85: these search implementations are unchanged from the measured commit. The FULLTEXT2 package delta only changes INCLUDE predicates/tests. Main was source-checked, not runtime-benchmarked.
1. ngram: prefix work dominates natural and MUST
| Selected query | Key evidence | Interpretation |
|---|---|---|
natural_mixed, human #104 |
mergeStarPostings ~78% cumulative CPU in both entrypoints. Separate allocation profile: decodeTermEntry 38%, merge itself 20%, FST state decoding 20%, position materialization 10% of allocated bytes. |
Prefix enumeration, repeated metadata lookup and posting/position merging are costly even when the final result is empty. |
boolean_must, human #153 |
Nine CJK operands, four short. unionDocIDs ~73% cumulative CPU; phraseHits and phraseDf each ~47%. Both entrypoints return empty results. |
Operands become phrase/prefix clauses, not atomic-term MUST. The full evaluator computes clause matches before intersection; global DF repeats phrase search. |
Cumulative CPU percentages overlap and must not be added. Allocation percentages describe allocation sources, not retained memory or a leak.
The query builder and Boolean routing/evaluation explain why adding CJK MUST operands does not necessarily produce cheap posting intersection. Prefix fallback and global phrase DF identify the repeated work.
2. gojieba BOW: expensive WAND iteration, limited block skipping
Selected query: human #42, eight SHOULD terms, 100 returned results. CPU profiles show searchWAND ~98%, blockMax 29–32%, skipTo ~21%; end-to-end query construction is 0.13% and gojieba tokenization/CGo 0.10%.
Request-local diagnostic counts, summed across ten segments:
| Event | Per request |
|---|---|
| Pivots found | 57,605 |
| Block upper-bound calls | 205,271 |
| Block-prune branch executions | 397 |
Cursor jumps (skipTo) |
38,468 |
| Whole intervening blocks skipped without decoding | 0 |
| Block decode calls | 1,686 |
| Candidates actually scored | 19,137 |
| Individual term scoring calls | 62,605 |
Only 0.69% of pivots take the block-prune branch; 38,071 jumps are alignment. This supports investigating repeated upper-bound and cursor work in the WAND loop, rather than changing the tokenizer.
Three diagnostic requests produced identical counts, and every segment's PK/score/include results exactly matched the uninstrumented implementation. Counters are request-local; the performance binary was unchanged. Zero whole-block skips does not mean zero pruning benefit: it excludes the already decoded current block, within-block movement and unvisited tails after early termination. Counts alone do not establish whether bounds are too loose.
Next work and acceptance
- Prefix track: reduce repeated FST/metadata work and unnecessary posting materialization; investigate bounded candidate-first MUST evaluation and repeated DF work. Do not reintroduce an unbounded hits cache or change global scoring semantics.
- WAND track: test request-local reuse of repeated block bounds, then inspect cursor alignment and threshold progression. Bound tightness and threshold evolution still need evidence before changing pruning logic.
- Validate each change: same frozen inputs/configuration, ordinary timing plus separate profiles; exact result/score checks including zero/nonzero hits, phrase/prefix semantics, liveness, multiple segments and TopK ties; bounded memory and lifecycle behavior. Then validate through SQL on the full corpus.
Not yet proven: a speedup, a regression against an older release, a WAND correctness bug, pack-wide behavior, or the cause of the full nightly QPS magnitude. No production optimization has been implemented. The evidence supports mechanisms for three representative queries, not completion of performance acceptance.
Additional information
Evidence identity and availability
Collected 2026-09-21/22. All query indices above are one-based.
- Full cleaned corpus: 2,303,643 rows, SHA256
548adc995d00fbc13138c74ecb6259f53b681cb4695cb75dd1137211cc3e77e5. - 100k subset SHA256:
eaa37328d81eedecf1b8e526d88d2c8fe3b9b7b92e05edbea4731520701cad3b. - Natural pack (188 queries):
a73f75109c0d460d020f2c587aec997fc7edd47150b46633535511cf28f91e94; selected query hash prefix5b744c972b5e. - Ngram MUST pack (200):
750fb61fc2cf67336880ad5937605fdf871b445ab827cea24516da101c67b859; selected query hash prefixcfe01ee6366d. - Gojieba BOW pack (200):
f6ce089380452686462329a91b48da58e19d9399ec57ddc9c12fd8f224852934; selected one-query pack including newline:1aa425e8425ba4e5bbf2888784ecd8c270407c0ce9393346a72be55cb2e43393. - CPU/allocation binary Build ID:
c60716fa4a0942e40986a9026b8fd4f6a7fbfc5b. - Counter binary SHA256:
788025dc3f3bb5122b655de833b685fc81bcfe17284638abbe2a0b9a9991728a. - Evidence directories in the controlled experiment:
results/target-cpu-v1,results/followup-profile-v1,results/bow-profile-v1,results/bow-counts-v1. Contention-failed attempts are excluded. Allocation uses separately sampledallocs(end)-allocs(base)and is subject to GC reporting lag. - Counter validation: native build, counter boundary tests and selected-query equivalence PASS; diagnostic terminated successfully with MainPID=0, no swap-out, peak RSS about 412 MiB.
The assignee retains structured results, profiles and manifests. Raw query text/corpus/profiles are not publicly attached; the test-only harness is not committed upstream. This issue is therefore an evidence summary, not a standalone turnkey reproducer.
Activity
[-][Performance]: short CJK prefixes dominate FULLTEXT2 natural/MUST queries through posting materialization and repeated DF scans[/-][+][Performance]: FULLTEXT2 natural/MUST prefix overhead and BOW WAND iteration costs[/+]VioletQwQ-0 commentedon Sep 24, 2026
Follow-up preflight for #29205 — corrected evidence scope and next gates (diagnostic only, not PR-head or SQL/nightly validation).
6690f1af97977ad5671235e9204296cd2d504ad5; source-equivalent paths on checked main780ef933f2479aa1679faf13d08850ce6c8f7c2f. Shared mo-55 used Linux amd64 / Go 1.26.6 and a verified 100,000-document subset (eaa37328d81eedecf1b8e526d88d2c8fe3b9b7b92e05edbea4731520701cad3b) in ten loaded segments per parser. This is a different host/toolchain from the earlier mo-129 profile; no paired wall-time comparison exists.alpha 中国) and M1/M2 matched baseline there. A separate loaded-index single-star control returned 9,616 documents with identical per-segment TF; it is a correctness control, not a measured non-empty allocation gain. The injected duplicate-position TF counterexample is not known to be reachable through normal SQL: for a fixed phrase slot, the same phrase start implies the same document position, while the tested normal ngram producer emitted one term per position. Other legitimate producers would need a concrete same-position witness before this becomes a public correctness claim.get, not the directory decode. M2, tested on M1, omits only the residentblockMaxTf/blockMinDocLnarrays on the phrase path; it still parses the fields and retainsblockLastDoc,blockOff, andblockPosOff. For natural Missing Create Table Statement #104, ten requests allocated 912.5 MB Go bytes / 15.62M mallocs at baseline, 651.4 MB / 13.36M with M1, and 642.2 MB / 11.10M with M1+M2. M1 saves ~28.6% bytes; M2 adds ~1.0% of baseline bytes (~1.4% relative to M1) and ~16.9% fewer mallocs relative to M1. The historicaldecodeTermEntryand FST flat-allocation shares cannot be added as removable work. A new per-source allocation profile is needed to explain residual costs. None of these numbers is a wall-time speedup.Updated order: (1) keep M1 as a minimal production-path prototype candidate, not a merge-ready performance fix; test a non-empty mixed star+exact phrase on the real loaded subset for result/score and allocation; (2) profile baseline/M1/M1+M2 allocations by FST, directory, and materialization/merge source before deciding M2's value; (3) reconcile BOW counters and measure
blockIndexAt's actual share withinblockMaxbefore attempting a request-local valid-block-range cache; (4) require clean-host paired timing, non-empty controls, full query packs, and then production SQL/nightly evidence before claiming a speedup. The shared host failed the 60-second idle/iowait/no-swap admission check, so wall-time/QPS remainsBLOCKED_ENVIRONMENT/NOT_MEASURED. No production algorithm or index format was changed by this preflight.fulltext2: reuse prefix iterator posting offsets (#29696)