Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Branch Name
main
Commit ID
Other Environment Information
Linux/amd64, isolated single-CN embedded cluster; 500,000 rows with FULLTEXT2/gojieba index on an English/Chinese body column. Both BM25 and TF-IDF settings were checked.
Actual Behavior
For a row whose body contains a term present in every document, the term has relevance score 0. On the same id=100 row, direct MATCH returns the row, but the logically equivalent MATCH OR false does not; NOT MATCH also returns the row. CASE WHEN MATCH THEN ... agrees with the latter, not the direct WHERE. This can silently drop rows when a user composes a fulltext predicate with other Boolean conditions.
Expected Behavior
Equivalent Boolean expressions should select the same rows, and a predicate and its negation should not both select the same row. Define and consistently implement zero-score matching semantics, including projection and Boolean composition.
Steps to Reproduce
-- docs has 500,000 rows; every body contains qaanchor, including id=100.
-- A FULLTEXT2 index with gojieba exists on body.
SELECT id, MATCH(body) AGAINST('qaanchor') AS score
FROM docs WHERE id=100 AND MATCH(body) AGAINST('qaanchor');
-- id=100, score=0
SELECT COUNT(*) FROM docs
WHERE id=100 AND MATCH(body) AGAINST('qaanchor');
-- 1
SELECT COUNT(*) FROM docs
WHERE id=100 AND (MATCH(body) AGAINST('qaanchor') OR id=-1);
-- 0 (id=-1 is false for this row)
SELECT COUNT(*) FROM docs
WHERE id=100 AND NOT MATCH(body) AGAINST('qaanchor');
-- 1The same discrepancy was observed for Boolean-mode +qaanchor and Chinese +检索; a selective positive-score term had consistent direct/OR/NOT behavior. A small standalone reproduction for both FULLTEXT implementations is still being run.
Additional information
The Boolean-composition rewrite in pkg/sql/plan/apply_indices_fulltext_boolean.go uses a LEFT JOIN and coalesces absent scores to zero; the direct MATCH filter uses posting membership. This is a plausible explanation, not a prescription to remove the score or to change Boolean semantics without checking callers. Separately, direct comparisons such as MATCH(...)=0 can fail with error 20105 while the same comparison under OR false executes; verify the broader expression family as part of a systematic fix.
Activity
fix(plan): a MATCH used as a condition is whether the index returned …
XuPeng-SH commentedon Oct 28, 2026
QA status for merged main
df8bfd602ecc036424ff7897187565657366919d(#31476): this environment has not run the affected planner tests or current-head FULLTEXT/FULLTEXT2 SQL because available headroom under the existing guard is insufficient for a safe large link or service build. The PR describes external planner and BVT runs; those are not local results from this QA environment.The original zero-score membership and projection contract, OR/AND/NOT/CASE and NULL boundaries, residual filters and actual query plans remain pending local acceptance. The PR explicitly states direct
MATCH(...) = 0without OR/NOT still returns 20105; that expression family is not established fixed. Keeping the current assignee pending verification.cpegeric commentedon Oct 28, 2026
please verify and close
Ariznawlll commentedon Oct 28, 2026
结论
测试通过。针对本 issue 的零分命中布尔组合修复,直接 MATCH、OR、NOT 和 CASE 已一致:索引返回的零分行仍被视为命中。研发明确排除的直接分数比较问题已单独记录为 #31604,不计入本修复通过范围。
关键证据
main@9eb05ce0f5ac5ddce36024aaa21c4c79d3e4334c包含已合入修复 #31476 的 merge commit7ae46aa38926a9ebbbcccf81c29ee05285b14cd6;macOS arm64,隔离 Log/TN、两个独立 CN,直接连接 CN 实测git_version()=9eb05ce0f5。原报告使用 Linux/amd64,此轮未独立复跑原架构。qaanchor和检索;TF-IDF 与 BM25 下,英文自然语言、+qaanchor和+检索布尔模式各重复 3 次,id=100 的直接结果均为(100,0)、OR false为 1 行、NOT 为 0 行、CASE 为y。正分稀有词对照为(100,32.47826)。三个重复基于同一套 50 万行数据,并非三次独立部署或索引构建。fulltext2_boolean_composition.sqlBVT 连续 3 轮各 114/114,覆盖 OR/AND/NOT/CASE、NULL、分数与残余过滤;MOTR #287 新增 FULLTEXT/FULLTEXT2 零分布尔语义与正分对照,在同一 SHA 定向 3/3。MOTR PR 离线检查通过,未运行完整 MOTR suite。待解决点
直接
MATCH(...) = 0仍返回 20105,研发在 #31476 中明确列为范围外;两种 FULLTEXT 实现各 3/3 复现并与OR false对照,已另建 #31604。此处不把该路径记为通过,也没有把错误录入 MOTR 成功 golden。