Skip to content

[Bug]: Python fulltext builders do not group additional OR predicates #32018

Closed

Description

@MatrixAdventurer

On main d24f446, both FulltextQueryBuilder.as_sql(where_conditions=...) and FulltextSearchBuilder.where() join raw conditions with AND without grouping each condition.

Reproduction:

from matrixone.sqlalchemy_ext.fulltext_search import FulltextQueryBuilder
print(FulltextQueryBuilder().must('needle').as_sql(
    'articles', ['content'],
    where_conditions=["category = 'a' OR category = 'b'", 'active = 1']))

Actual WHERE:

MATCH(`content`) AGAINST('+needle' IN BOOLEAN MODE) AND category = 'a' OR category = 'b' AND active = 1

Expected WHERE:

MATCH(`content`) AGAINST('+needle' IN BOOLEAN MODE) AND (category = 'a' OR category = 'b') AND (active = 1)

Because AND binds more tightly than OR, category b can bypass the search predicate and category a can bypass the active filter. A later OR condition can also bypass earlier conditions. Each supplied predicate should be a conjunct of the search and other predicates.

An offline SQLite Boolean-semantics regression substitutes only the MATCH expression with a precomputed search_score column. Six cases fail before the fix across the two public builders; two no-additional-condition controls pass. This isolates predicate grouping; it does not test MatrixOne fulltext scoring.

Activity

  1. self-assigned this
    on Nov 2, 2026
  2. added a commit that references this issue on Nov 2, 2026
    c9b9177
  3. XuPeng-SH commented on Nov 2, 2026

    @XuPeng-SH
    Contributor

    QA 交接(转测,不代表验收通过)

    关联已合并修复:#32019,main merge SHA c9b9177bc1e6531cf26edd251f3a5edb56027110(2026-11-02 09:54:56 UTC)。FulltextQueryBuilder.as_sql 和 FulltextSearchBuilder._build_sql 均为每个附加条件加括号,防止 OR 绕过 MATCH 或其他过滤条件;完整 issue 评论当前为空,PR 讨论/复审未留下未完成开发 follow-up 或当前适用的已验证反例。

    验证证据:作者报告修复前 6 项回归失败、2 项控制通过;修复后离线全套 2953 tests + 103 subtests 通过,格式/静态检查通过。独立评审批准;本轮远端回读最终 PR head fe485ddd842221f7818fef67135c2d22e425768a 的 8 个 SDK offline CI job 及 CI Required 均成功。这些是作者报告/远端核对,本轮未运行本地测试。

    交 @Ariznawlll 回归两个公开 builder:单个 OR、首/末位置 OR 与多条件链、MATCH 不命中但类别命中的负控,以及无附加条件对照。新增离线测试仅将 MATCH 替换为预计算 score 后用 SQLite 验证布尔分组,不证明真实 MatrixOne 全文评分/分词;online CI 被跳过,真实 MatrixOne 服务上的组合查询、评分和运行环境仍待 QA。不要把本次交接视为这些未测范围的验收通过。

  4. slyunnn commented on Nov 4, 2026

    @slyunnn

    Regression and extended verification for #32018 (2026-11-04)

    Verification Environment

    • Remote main was fetched and frozen at test start to 0f6c07639604c40d7ca880cb63d1d282239def08, test(plan): cover subscription CLONE planning-error alias preservation (#32107). A new native build, binary version output and SELECT git_version() confirmed the runtime identity.
    • macOS/arm64, Go 1.27.1. Fresh native 2 CN / 1 TN / 1 Log service / Proxy topology, co-hosted by the launcher. Proxy localhost:6001, CN1 localhost:16001, CN2 localhost:16002 were connectable and all executed the relevant original scenarios and extensions.
    • Python 3.14, SQLAlchemy 1.4.54, 2.0.55, 2.1.6. Sync Client/PyMySQL and async AsyncClient/aiomysql used the MySQL text protocol. The SDK source matched the frozen main commit.

    What Was Covered

    • OK Both public fulltext builders executed real MATCH ... AGAINST queries against an actual fulltext index.
    • OK No additional filter, a single OR, OR as the first chained condition and OR as the final condition. Exact expected IDs were checked in all 18 version/client/endpoint cells, totaling 144 builder/scenario checks.
    • OK A category-matching row without the search term remained excluded. A search-matching inactive row remained excluded when required. Unfiltered controls retained all expected matching IDs.
    • OK Post-query health, zero checked-out pool connections and database teardown. Endpoint fixtures used independent schemas and ran concurrently.
    • Not covered Other Python versions, other tokenizers and performance benchmarks.

    Findings

    The original precedence defect did not reproduce. Each additional predicate remains a conjunct of the fulltext search and other filters.

    Associated fix is c9b9177bc1e6531cf26edd251f3a5edb56027110, fix(python): group additional fulltext WHERE predicates (#32019). Fix PR

    MOTR / BVT Coverage

    Existing test_fulltext_where_grouping.py and test_json_expression_traversal.py passed all 14 selected tests with each SQLAlchemy version. Real MatrixOne queries supplemented their SQLite oracles. SQL-only MOTR tests bypass these Python builders, so existing SDK coverage was reused and no duplicate SQL regression was added.

    Final Conclusion

    Fixed on the tested main commit. Large-data regression is unnecessary because Boolean grouping is exposed by the four-row positive/negative fixture.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions