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
correlated columns in SCALAR subquery deeper than 1 level not yet implemented (error 20102) — v4.0.0-rc2 #24997
8.0.30-OmniFabric-v4.0.0-rc2 (output of SELECT version())
Description
A scalar subquery that contains a nested scalar subquery whose correlation references an outer table alias more than one level up fails to plan with:
ERROR 20102 (HY000): correlated columns in SCALAR subquery deeper than 1 level will be supported in future version is not yet implemented
This is a common "value at the most-recent timestamp per entity" pattern and runs on MySQL 8 / PostgreSQL.
Reproduction
CREATETABLEj_dim (id INT);
CREATETABLEj_fact (id INT, dim_id INT, ts INT, val DOUBLE);
SELECTa.id,
(SELECTMAX(x.val)
FROM j_fact x
WHEREx.ts= (SELECTMAX(y.ts)
FROM j_fact y
WHEREy.dim_id=a.id) -- correlates to outer `a`, two levels up
) AS latest
FROM j_dim a;
Actual
ERROR 20102 (HY000): correlated columns in SCALAR subquery deeper than 1 level will be supported in future version is not yet implemented
Expected
The statement plans and runs, resolving the correlation to the outermost a from the doubly-nested scalar subquery.
Impact
Hit by a natural-language-to-SQL assistant. Questions like "give me the exact value at the latest timestamp for entity X" produce this nested-correlated scalar shape, which fails instead of running.
Unsafe forms involving COALESCE, non-NULL-on-empty aggregates, and LIMIT/OFFSET remain deliberately rejected,
preventing semantic rewrites that could produce wrong results.
Test-file changes
Added a MOTR .test file to permanently cover the original failure and supported extended query shapes.
Added the matching recorded .result file as expected output.
No MatrixOne service source code was changed.
Suggested resolution
Merge the MOTR regression PR and close #24997 as fixed by #26480.
Activity
fix(plan): support nested correlated scalar aggregates (#26480)
slyunnn commentedon Aug 7, 2026
回归测试结论:通过:BVT 15/15。
slyunnn commentedon Aug 10, 2026
Extended verification for #24997 (2026-08-10)
Follow-up to the nested correlated scalar-subquery report: verified the fix from #26480 on the latest main branch.
Verification environment
mainfa0ea95aa77b59a2947159baab31e7215d040e93fix(plan): support subqueries in left and right join ON clauses (#26763)ce384091488175e08410f0795379d217112421e3fix(plan): support nested correlated scalar aggregates (#26480)test/issue-24997-nested-correlated-scalar8134ac43484bb8a4c20ef6cd7e6515214faa9132What was covered
AVGouter aggregate with a deeply correlated innerMAX.WHEREfilter.Results
220.0,300.0,NULL.200.0,300.0,NULL.1and2.Findings
NULL.COALESCE, non-NULL-on-empty aggregates, andLIMIT/OFFSETremain deliberately rejected,preventing semantic rewrites that could produce wrong results.
Test-file changes
.testfile to permanently cover the original failure and supported extended query shapes..resultfile as expected output.Suggested resolution
Merge the MOTR regression PR and close #24997 as fixed by #26480.
Ariznawlll commentedon Aug 12, 2026
测试版本
main1c292cf20e113b296a3db2cb6a65e00af2ea2327launch-with-proxy拓扑(2 CN + 1 TN + 1 Log + Proxy),MOTR 直连 CN127.0.0.1:16001原问题验证
按 issue 的嵌套相关标量子查询场景创建
j_dim3 行、j_fact5 行,执行「外层维度行 ->MAX(val)-> 内层相关MAX(ts)」的原始查询形状。期望id/latest为1/220.0、2/300.0、3/NULL;在上述 main 上通过 MOTR--repeat 3执行,3/3 轮结果与期望完全一致,未再出现错误结果或执行异常。完整 SQL 见下方回归文件。Happy Path 覆盖
1/220.0、2/300.0、3/NULL。dim_id相关的MAX变体:返回1/200.0、2/300.0、3/NULL,未匹配维度正确保留NULL。AVG聚合变体返回200.0、300.0、NULL;相同嵌套子查询放入外层WHERE > 150时正确返回id=1,2。dim_id=1和dim_id=2两组参数执行,结果分别为200.0和300.0。Unhappy Path 覆盖
id=3,事实表中另有无匹配维度的dim_id=99;相关结果仍为id=3 -> NULL,没有被无关行污染。APPROX_COUNT、COUNT + COALESCE、COALESCE及LIMIT/OFFSET嵌套形状,各 3/3 轮稳定拒绝;每次拒绝后继续执行普通查询均成功,连接可继续使用。白盒验证
不适用:本 issue 验收的是 SQL 优化器对嵌套相关标量子查询的公开语义和结果正确性,可通过多组 SQL 输入及精确结果全量观测;本轮未额外执行聚焦 Go UT/故障注入。
回归测试
已由 motr PR #94 合入回归;精确测试文件:
issue_24997_nested_correlated_scalar.test。本轮在最新 main 上对该 case 执行 MOTR--repeat 3,3/3 轮成功,每轮 18 条语句均与期望输出匹配。测试证据
8134ac43484bb8a4c20ef6cd7e6515214faa9132中的测试文件。14_issue_regression.issue_24997_nested_correlated_scalar重复 3 轮,3/3 成功。测试结论
测试通过。
fix(plan): support nested correlated scalar aggregates (matrixorigin#…
fix(plan): support nested correlated scalar aggregates (matrixorigin#…
fix(plan): support nested correlated scalar aggregates (matrixorigin#…