Skip to content

[Bug]: FULLTEXT2 zero-score matches behave inconsistently in Boolean expressions #31411

Closed

Description

@XuPeng-SH

Is there an existing issue for the same bug?

  • I have checked the existing issues.

Branch Name

main

Commit ID

24c1ac8

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');
-- 1

The 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

  1. self-assigned this
    on Oct 27, 2026
  2. added
    kind/bug
    on Oct 27, 2026
  3. added
    severity/s0
    and removed on Oct 27, 2026
  4. XuPeng-SH commented on Oct 28, 2026

    @XuPeng-SH
    ContributorAuthor

    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(...) = 0 without OR/NOT still returns 20105; that expression family is not established fixed. Keeping the current assignee pending verification.

  5. cpegeric commented on Oct 28, 2026

    @cpegeric
    Contributor

    please verify and close

  6. Ariznawlll commented on Oct 28, 2026

    @Ariznawlll
    Collaborator

    结论

    测试通过。针对本 issue 的零分命中布尔组合修复,直接 MATCH、OR、NOT 和 CASE 已一致:索引返回的零分行仍被视为命中。研发明确排除的直接分数比较问题已单独记录为 #31604,不计入本修复通过范围。

    关键证据

    • 官方 main@9eb05ce0f5ac5ddce36024aaa21c4c79d3e4334c 包含已合入修复 #31476 的 merge commit 7ae46aa38926a9ebbbcccf81c29ee05285b14cd6;macOS arm64,隔离 Log/TN、两个独立 CN,直接连接 CN 实测 git_version()=9eb05ce0f5。原报告使用 Linux/amd64,此轮未独立复跑原架构。
    • 构造 500,000 行 FULLTEXT2/gojieba 索引,每行均含 qaanchor 和 检索;TF-IDF 与 BM25 下,英文自然语言、+qaanchor 和 +检索 布尔模式各重复 3 次,id=100 的直接结果均为 (100,0)、OR false 为 1 行、NOT 为 0 行、CASE 为 y。正分稀有词对照为 (100,32.47826)。三个重复基于同一套 50 万行数据,并非三次独立部署或索引构建。
    • 当前 SHA 的 fulltext2_boolean_composition.sql BVT 连续 3 轮各 114/114,覆盖 OR/AND/NOT/CASE、NULL、分数与残余过滤;MOTR #287 新增 FULLTEXT/FULLTEXT2 零分布尔语义与正分对照,在同一 SHA 定向 3/3。MOTR PR 离线检查通过,未运行完整 MOTR suite。
    • 修复 PR #31476 的多 CN BVT 与 SCA 通过,但 Ubuntu/x86 UT 和 CI Required 显示失败;本轮未重跑完整产品 CI。

    待解决点

    直接 MATCH(...) = 0 仍返回 20105,研发在 #31476 中明确列为范围外;两种 FULLTEXT 实现各 3/3 复现并与 OR false 对照,已另建 #31604。此处不把该路径记为通过,也没有把错误录入 MOTR 成功 golden。

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

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions