You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: correlated ORDER BY LIMIT returns NULL for a matching row #32441
A correlated scalar subquery with ORDER BY ... DESC LIMIT 1 silently returns NULL for a parent that has a matching child. The query succeeds but produces an incorrect result:
0 NULL
2 2
The result reproduced 3/3 times in a fresh database.
Expected Behavior
The first parent matches a child with event_idx = 1, so the result should be:
0 1
2 2
Steps to Reproduce
Run this in an empty test database:
CREATETABLEparent (id INT, ceiling BIGINT);
CREATETABLEchild (unused INT, parent_id INT, event_idx BIGINT);
INSERT INTO parent VALUES (0, 2), (2, 2);
INSERT INTO child VALUES (0, 0, 1), (0, 2, 1), (0, 2, 2);
SELECTp.id,
(SELECTc.event_idxFROM child AS c
WHEREc.parent_id=p.idANDc.event_idx>0ANDc.event_idx<=p.ceilingORDER BYc.event_idxDESCLIMIT1)
FROM parent AS p
ORDER BYp.id;
Additional information
A non-correlated LEFT JOIN grouped by p.id with MAX(c.event_idx) returns the expected result on this fixture. No indexes are needed. All reproduction data is synthetic; the temporary database was removed after testing.
Related query shape: #32440 reports a panic for a correlated MAX subquery on the same build. A common underlying cause has not been established.
Activity
fix(plan): preserve correlated pagination per outer row (#32459)
Ariznawlll commentedon Nov 30, 2026
结论
测试通过。原始相关 ORDER BY DESC LIMIT 1 的错误 NULL 结果已不再复现,原始数据及扩展精确行集均通过。
关键证据
版本与环境
df65fa5b21d2da5bbca119236bbf7829f88d78dd,实际连接两个 CN 核对git_version()。这是 MO SHA,不是 MOTR commit。复现步骤、实际输出与扩展结果
parent、child表和五条合成记录,不增加索引,执行相关子查询ORDER BY event_idx DESC LIMIT 1。两个 CN 各连续三轮均返回:与独立的 LEFT JOIN / MAX 对照一致,没有原来的
0 -> NULL错误结果。(parent_id,event_idx)索引前后分别执行;SQL PREPARE/EXECUTE 的 LIMIT 1 同样核对完整结果。删除父键 0 的子行后事务内结果为 NULL,回滚后恢复原来的值,再从两个 CN 复核。prepared correlated subquery with LIMIT 0 is not yet implemented,回归保留该特定拒绝断言。普通 SQL 的 LIMIT 0 正确返回 NULL。没有将这一额外形态写成“预编译支持已通过”;本 Issue 原始 LIMIT 1 错误结果已不再出现。回归与 CI
ab70a005350fe6165b777320d8acf4e6adcc98d6。待解决点
没有找到可确认与本工单一一对应的修复 PR,因此不猜测修复归因;依据实际 4.2-dev 运行版本和原始复现结果验收。预编译相关 LIMIT 0 属于上述明确拒绝的额外边界,不是本 Issue 报告的 LIMIT 1 错误结果,也不宣称它已经支持。
本 Issue 原始验收范围无未通过项。回归已提交,按用户允许在回归 PR 合入前关闭的流程处理。
最终结论:测试通过。原始复现、上述扩展与对应分支 MOTR/CI 已完成;本 Issue 原始验收范围内未通过项:无。按授权关闭 #32441。