Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues.
Related [Bug]: Python SELECT convenience builder ignores explicit limit=0 #30824 fixes the SELECT convenience builder, not these three fulltext entry points. Searches for fulltext limit zero and SDK limit=0 found no matching fulltext fix.
Branch Name
main
Commit ID
Other Environment Information
Python 3.12, SQLAlchemy 2.1.6, offline SQL-generation regression.
Actual Behavior
FulltextQueryBuilder.as_sql(limit=0), the client FulltextSearchBuilder.limit(0).explain(), and the index-module FulltextSearchBuilder.limit(0).build_sql() all omit LIMIT. A request for zero rows becomes an unrestricted search. Each uses truthiness instead of distinguishing None from zero.
Expected Behavior
Explicit zero emits LIMIT 0; None omits LIMIT; positive limits remain intact.
Steps to Reproduce
Run from clients/python:
PYTHONPATH=. python -m pytest tests/offline/test_fulltext_zero_limit.py -o addopts='' -qBefore production changes: 3 failed, 6 passed. All zero-limit paths fail the expected LIMIT 0 assertion. After: all nine pass.
Additional information
由 LW 授权的 ChatGPT Agent 操作。
Handoff to @XuPeng-SH: complete candidate patch below, 3 files, +43/-3 lines. Production fix changes only three guards. Focused owning tests (test_fulltext_zero_limit.py, test_fulltext_search_comprehensive.py, test_fulltext_index_validation.py): 93 passed. git diff --check passed.
Self-review: one R2 SDK SQL-generation contract across three public consumers; no engine/index algorithm, concurrency, authentication, or persisted format changes. None/zero/positive controls retained. This is one bug with three affected entry points, not three independent bugs. No MatrixFlow changes this round.
Real MatrixOne frontend/BVT and hosted CI remain unverified. Patch handoff only; no PR opened under the mo-self-review requirement for zero unresolved validation blockers.
Save the diff below and apply with git apply after checking against the stated base.
diff --git a/clients/python/matrixone/sqlalchemy_ext/fulltext_index.py b/clients/python/matrixone/sqlalchemy_ext/fulltext_index.py
index 8d67ee0..5cdc4e9 100644
--- a/clients/python/matrixone/sqlalchemy_ext/fulltext_index.py
+++ b/clients/python/matrixone/sqlalchemy_ext/fulltext_index.py
@@ -641,7 +641,7 @@ class FulltextSearchBuilder:
builder.order_by("score DESC")
# Add LIMIT/OFFSET clause
- if self.limit_value:
+ if self.limit_value is not None:
builder.limit(self.limit_value)
if self.offset_value:
builder.offset(self.offset_value)
diff --git a/clients/python/matrixone/sqlalchemy_ext/fulltext_search.py b/clients/python/matrixone/sqlalchemy_ext/fulltext_search.py
index 7041645..7450270 100644
--- a/clients/python/matrixone/sqlalchemy_ext/fulltext_search.py
+++ b/clients/python/matrixone/sqlalchemy_ext/fulltext_search.py
@@ -646,7 +646,7 @@ class FulltextQueryBuilder:
order_clause = f"ORDER BY {order_by}" if order_by else ""
# Build LIMIT clause
- limit_clause = f"LIMIT {limit}" if limit else ""
+ limit_clause = f"LIMIT {limit}" if limit is not None else ""
# Build OFFSET clause
offset_clause = f"OFFSET {offset}" if offset else ""
@@ -1588,7 +1588,7 @@ class FulltextSearchBuilder:
order_clause = f"ORDER BY {self._order_by}" if self._order_by else ""
# Build LIMIT clause
- limit_clause = f"LIMIT {self._limit_value}" if self._limit_value else ""
+ limit_clause = f"LIMIT {self._limit_value}" if self._limit_value is not None else ""
# Build OFFSET clause
offset_clause = f"OFFSET {self._offset_value}" if self._offset_value else ""
diff --git a/clients/python/tests/offline/test_fulltext_zero_limit.py b/clients/python/tests/offline/test_fulltext_zero_limit.py
new file mode 100644
index 0000000..534ea18
--- /dev/null
+++ b/clients/python/tests/offline/test_fulltext_zero_limit.py
@@ -0,0 +1,40 @@
+# Copyright 2021 - 2022 Matrix Origin
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Pagination contracts for the three public fulltext SQL builders."""
+
+import pytest
+from matrixone.sqlalchemy_ext.fulltext_index import FulltextSearchBuilder as IndexSearch
+from matrixone.sqlalchemy_ext.fulltext_search import FulltextQueryBuilder, FulltextSearchBuilder
+
+
+@pytest.mark.parametrize('limit', [None, 0, 2])
+@pytest.mark.parametrize('entry', ['query', 'client', 'index'])
+def test_fulltext_limit_preserves_zero(entry, limit):
+ if entry == 'query':
+ sql = FulltextQueryBuilder().must('hello').as_sql('docs', ['body'], limit=limit)
+ elif entry == 'client':
+ builder = FulltextSearchBuilder(None).table('docs').columns(['body']).query('hello')
+ if limit is not None:
+ builder.limit(limit)
+ sql = builder.explain()
+ else:
+ builder = IndexSearch('docs', ['body']).search('hello')
+ if limit is not None:
+ builder.limit(limit)
+ sql = builder.build_sql()
+ if limit is None:
+ assert 'LIMIT' not in sql
+ else:
+ assert sql.endswith(f'LIMIT {limit}')
Activity
fix(python-sdk): preserve explicit fulltext LIMIT 0 (matrixorigin#31023)
fix(python): unify SDK execution contracts across 4.1.x and 4.2.x (#3…
XuPeng-SH commentedon Oct 27, 2026
QA on merged SDK source
baa83f4b96e56ec214f92c68f7b56539b9e0fa45: the full offline suite passed (2,279 tests plus 95 subtests) on Python 3.12.14 / SQLAlchemy 2.0.55.test_fulltext_pagination_preserves_explicit_zerochecks all three public SQL builders with None, 0 and 2, including explicitLIMIT 0. This verifies SQL generation; actual fulltext execution and zero-row results against a MatrixOne service were not checked in this run. Assignment is unchanged pending that service coverage.XuPeng-SH commentedon Oct 27, 2026
Follow-up live QA: SDK
00c103b68bd2b39194147508445956f5ece16ddaagainst an isolated MatrixOne 1.3.0 server83c1e23526fc0ed31188abd7fc2ca87cd3a6d4b3. All three fulltext builders executed against the same seeded index:Nonereturned all three matching rows,0returned no rows, and2returned two distinct matching rows; the nonmatching row was excluded. The connection remained usable and task objects were cleaned up. This is mixed SDK/server provenance, not a test of the latest kernel.Ariznawlll commentedon Oct 27, 2026
测试版本
main:d4ffbae43d55da21526eab01722cbef14bb01ed5;实际修复 PR #31322 的 merge commitbaa83f4b96e56ec214f92c68f7b56539b9e0fa45在祖先链中。单独的候选 PR fix(python-sdk): preserve explicit LIMIT 0 in fulltext builders (#31023) #31311 仍未合入,本次没有把它当成运行版本。原问题验证
创建 4 行数据和真实 FULLTEXT 索引,其中 3 行匹配
hello、1 行不匹配;依次使用FulltextQueryBuilder.as_sql、客户端FulltextSearchBuilder.explain和索引模块FulltextSearchBuilder.build_sql生成 SQL。三种入口显式limit=0时均包含LIMIT 0,执行后返回 0 行,3 轮均通过。Happy Path 覆盖
每个入口
None时省略 LIMIT,实际返回匹配 ID{1,2,3};limit=2时返回 2 个不同的匹配 ID,均不包含非匹配行 4。每轮检查生成 SQL 和真实结果,并检查连接仍可执行SELECT 1。Unhappy Path 覆盖
显式 0 是合法边界,不作为错误;本问题涉及 SQL 生成和查询,不涉及写入失败原子性。每轮使用独立临时数据库,测试后删除;未覆盖多 CN/Proxy 或额外 parser 变体。
白盒验证
不涉及 Go race。独立执行三个入口 ×
{None,0,2}参数化用例,连同配置/结果游标用例共 58 项,3 轮均通过。回归测试
MOTR #284 的 SDK 场景 在真实 MO 服务执行三入口全部边界,3/3;相邻 #30824 SELECT builder 回归也 3/3。未运行完整 MOTR 套件。
测试证据
修复 PR Python SDK 离线 CI 矩阵通过,online job skipped;本轮真实服务结果见上述 MOTR 场景及 PR。MOTR 新 head 的四项托管离线检查通过,不等同完整在线 CI。
测试结论
测试通过。