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
Latest main at 3046f14d94b3f1a25839eeeb65729b64f85ac647.
What happened?
When a correlated scalar aggregate subquery has no matching input rows, COALESCE or IFNULL inside the subquery is not evaluated. MatrixOne returns NULL instead of the requested fallback value.
The same aggregate works when the subquery is uncorrelated, and moving COALESCE outside the scalar subquery also works. This indicates that the correlated-subquery rewrite drops the aggregate result row for an empty input.
How to reproduce
CREATETABLEparent(id INTPRIMARY KEY);
CREATETABLEchild(parent_id INT, v INT);
INSERT INTO parent VALUES (1), (2);
INSERT INTO child VALUES (1, 10);
SELECTp.id,
(SELECT COALESCE(SUM(c.v), 0)
FROM child c
WHEREc.parent_id=p.id) AS total
FROM parent p
ORDER BYp.id;
Actual result
1 10
2 NULL
Expected result
1 10
2 0
MySQL 8.0.45 returns the expected result.
Scope
The issue is reproducible with SUM, AVG, MIN, and MAX wrapped by COALESCE.
COUNT(*) returns 0 correctly.
Wrapping the correlated source in a CTE has the same incorrect result:
SELECTp.id,
(WITH x AS (SELECT v FROM child c WHEREc.parent_id=p.id)
SELECT COALESCE(SUM(v), 0) FROM x)
FROM parent p;
Moving the fallback outside the subquery is a working control:
SELECTp.id,
COALESCE((SELECTSUM(c.v) FROM child c WHEREc.parent_id=p.id), 0)
FROM parent p;
PR #26510 merged with final head 55203b022b21cc79c73b64e2b65c032e82c41725 as merge commit d6800b98855b871459c3c4bad0ce73aa7321610f. The merge is present in current main d34a6c896f5f0c07f378861704520db548f404b8.
Automated evidence:
canonical scalar_correlated_projection BVT passed 40/40 on the PR implementation head;
Verify the correlated JSON aggregate empty-input fallback returns [].
Verify present, empty, and all-NULL inner-input controls and check that ordinary correlated aggregate behavior does not regress.
PASS requires the tested version/SHA, environment, and terminal results for all scenarios. FAIL requires preserving the exact SQL, observed output/error, version, and environment. Keep the issue open and assigned to VioletQwQ-0 until terminal QA evidence is recorded.
Activity
fix(plan): preserve empty correlated aggregate projections (#26510)
VioletQwQ-0 commentedon Aug 3, 2026
QA handoff
PR #26510 merged with final head
55203b022b21cc79c73b64e2b65c032e82c41725as merge commitd6800b98855b871459c3c4bad0ce73aa7321610f. The merge is present in current maind34a6c896f5f0c07f378861704520db548f404b8.Automated evidence:
scalar_correlated_projectionBVT passed 40/40 on the PR implementation head;MOProtocolVersiontest-state leak, not from the planner change.Remaining QA on an identified MatrixOne version/environment:
0, notNULL.[].PASS requires the tested version/SHA, environment, and terminal results for all scenarios. FAIL requires preserving the exact SQL, observed output/error, version, and environment. Keep the issue open and assigned to
VioletQwQ-0until terminal QA evidence is recorded.Ariznawlll commentedon Aug 5, 2026
测试版本
maine31ee06042bc708ac5620a579715e07ec31c21b6原问题验证
重跑原始 CTE + 空相关聚合场景,三个外层键分别得到
12,0,0;缺失匹配键返回0而不是NULL。Happy Path 覆盖
COALESCE(SUM(...),0)返回正确合计12。0。[5, 7]、[null]、[],区分有值、全 NULL 和空输入。Unhappy Path 覆盖
白盒验证
本轮不以白盒作为终态依据;原始 CTE、相关聚合和 JSON 空集语义均通过公开 SQL 端到端验证。
回归测试
测试证据
b770136206c88435a51599e4b317e522eddfd085。d6800b98855b871459c3c4bad0ce73aa7321610f。测试结论
测试通过。
fix(plan): preserve empty correlated aggregate projections (matrixori…
fix(plan): preserve empty correlated aggregate projections (matrixori…
fix(plan): preserve empty correlated aggregate projections (matrixori…