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
[Feature Request]: Support correlated subquery with multi levels #7559
Verified on MatrixOne origin/main commit 19e01d261b078c172585a3ca46da86eb7e446921 (test: reduce race fixture work and strengthen regression coverage (#29520)).
The running mo-service binary was freshly built from that exact worktree; its SHA-256 was 1e03ca96c78d8a11f2807c30aee5d92cee3a3d62ce10fad0d776763926397c48, matching the binary mounted in CN1.
Topology: 2 CN / 1 TN / 1 Log service / Proxy. The isolated MySQL endpoints were Proxy 6621 (service port 6009), CN1 16621 (service port 16001), and CN2 16622 (service port 16002). All endpoints were reachable and passed post-query health checks.
Client protocol: MySQL text protocol via mysql CLI. Endpoint cases ran in parallel with isolated databases and no shared test objects.
OK One-level correlated EXISTS control returned 1,2,3 through Proxy, CN1, and CN2.
OK Two-level correlated EXISTS returned the expected 1 through Proxy, CN1, and CN2.
OK Two-level correlated IN returned the expected 1 through Proxy, CN1, and CN2.
Failed Two-level correlated scalar-subquery form returned ERROR 20102: correlated columns in SCALAR subquery deeper than 1 level ... is not yet implemented, consistently through all three endpoints.
OK Each endpoint completed SELECT 1 after the tested statements.
OK Focused planner test TestNestedCorrelatedScalarStillRejectsUnsafeShapes passed with exit status 0; it asserts this current explicit rejection.
Not covered General multilevel decorrelation across all subquery categories, aggregates, FROM-subqueries, arbitrary parameter domains, demand/cardinality handling, and materialization budgets. The issue is a broad feature request without a finalized general implementation design.
Findings
MatrixOne currently has partial multilevel correlation support: the representative two-level EXISTS and IN forms execute correctly, while a representative two-level scalar correlation is intentionally rejected by pkg/sql/plan/flatten_subquery.go. Therefore, the requested general capability is not implemented. The linked timeline event only assigned the issue; it did not indicate a completed implementation.
Current main supports the tested multilevel EXISTS and IN forms but does not support the tested multilevel scalar-subquery form; #29452 provides physical prerequisites only and must not be treated as a fix for the general feature.
MOTR / BVT Coverage
No MOTR case, branch, recording, replay, commit, or PR was created. This is an open kind/feature request rather than a fixed bug regression, and adding a MOTR expectation for a deliberately unsupported feature would not provide valid coverage. Existing planner coverage explicitly verifies the current rejection; the real SQL endpoint matrix above verifies the current public behavior.
Large-data regression is not required. The observed limitation is a planner/decorrelation capability gate that occurs before data-volume-dependent execution; row count, block/batch boundaries, memory/spill, concurrency, skew, network transfer, and resource scale do not change the support decision.
Regression and extended verification for #7559 (2026-10-22)
Verification Environment
Executed git fetch origin main in the running-source worktree. HEAD and origin/main both resolved to ada0bde326adec3c3906d2f417c266d0ada5b054 — feat: control TPC-H comparison resources and paired measurement (#30599).
The actual mo-service binary was built from this ref: Go 1.27.1, commit ada0bde326, running from the local current-main source worktree.
Complete topology: 2 CN / 1 TN / 1 Log service / Proxy, launched with the local proxy configuration. Proxy 6001, CN1 16001, and CN2 16002 were reachable.
All SQL used the MySQL TCP protocol via the MySQL CLI. Original multilevel, empty-scalar, Prepared Statement, cardinality-error, cleanup, and health checks ran through Proxy 6001; core execution and health checks ran directly through CN1 16001 and CN2 16002.
Related implementation: PR #30116, feat(sql): support multilevel correlated subqueries, merged as 94760aa93223924df314c12d7079323f2e89c2b1. Its main implementation commit is 7010830b375096c5f3683f261cf68bedbc157d63. The merge commit is an ancestor of the verified current main.
What Was Covered
OK — Two-level correlated scalar query through Proxy, CN1, and CN2 returned (1,2), (2,3), and (3,4) for SELECT o.k, (SELECT (SELECT o.k + 1)).
OK — Three-level ancestor reference through Proxy returned (1,2), (2,4), and (3,6) for SELECT o.k, (SELECT (SELECT (SELECT o.k * 2))).
OK — Correlated aggregate with nested EXISTS returned (1,21), (2,20), and (3,30) through Proxy, CN1, and CN2.
OK — Empty nested scalar result preserved SQL NULL semantics: every empty_scalar_is_null result was 1.
OK — Prepared Statement through Proxy preserved multilevel correlation and parameter binding: k > 1 with delta 10 returned (2,12) and (3,13).
OK — Unhappy path: a demanded nested scalar returning two rows was rejected with standard ERROR 1242 (Subquery returns more than 1 row); subsequent Proxy SELECT 1 succeeded.
OK — CN1 and CN2 each completed post-query SELECT 1; both direct endpoints produced the same functional results as Proxy.
Not covered — Proxy connection migration/capability downgrade, cancellation fault injection, authorization/revocation, and full DML/CTE/window/set-operation matrix. These are broader PR feat(sql): support multilevel correlated subqueries #30116 execution-scope areas, not part of the original minimal feature request or this independent SQL verification.
Not covered — Large-data performance and throughput characterization. The feature is not a row-count, LIMIT, block/batch, spill, index, skew, or network-transfer defect. The small multi-row/duplicate-inner fixture exercises demanded invocation and cardinality behavior; no large-data regression is required for this functional conclusion.
Not covered — No engine worker-parallel claim is made. The verification ran serially; MOTR -j N was not used as a proxy for engine behavior.
Findings
The requested multilevel correlated-subquery capability is now present in verified current main for nested scalar ancestor references, correlated aggregates, empty scalar results, Prepared Statement parameters, and standard scalar-cardinality errors. The historical unsupported deeper-than-one scalar rejection is not reproduced. Proxy, CN1, and CN2 returned consistent results.
MOTR / BVT Coverage
No new MOTR/BVT case was needed or created. PR #30116 already contains extensive owned planner/execution and public SQL coverage for this large feature. The independent verification above exercised the issue contracts directly against the actual latest-main multi-CN service, so no test branch, recording/replay, commit, push, or daily-summary entry applies.
Final Conclusion
Fixed — PR #30116 is merged in verified origin/main, and actual Proxy/CN1/CN2 MySQL-protocol validation confirms the requested multilevel correlated-subquery support within the tested functional scope.
Verified on main@3ad9adbb4c (PR #30116 merged) — no transfer, slyunnn already owns testing
Built mo-service from current main locally (CGo, arm64) and ran adversarial multi-level correlated cases against a fresh isolated instance, using an equivalent JOIN/GROUP BY rewrite as the oracle (independent of the subquery decorrelation path):
createtablet1(a int, b int);
createtablet2(a int, c int);
createtablet3(c int, d int);
insert into t1 values (1,10),(2,5),(3,1);
insert into t2 values (1,100),(1,200),(2,50),(3,7),(3,9);
insert into t3 values (100,11),(200,9),(50,6),(7,0),(9,20);
-- two-level correlation: inner EXISTS references the outermost tableselect a, (selectmax(c) from t2
wheret2.a=t1.aand exists (select1from t3 wheret3.c=t2.candt3.d>t1.b)) as v
from t1 order by a;
Actual on HEAD: 1|100, 2|50, 3|9 — identical to the oracle
selectt1.a, max(t2.c) from t1
join t2 ont2.a=t1.ajoin t3 ont3.c=t2.candt3.d>t1.bgroup byt1.aorder byt1.a;
Nested scalar-inside-scalar with two outer references also produces the manually verified values (1|1, 2|1, 3|0; for a=3 the only c=7 row has d=0 < b=1, so 0 is correct).
Assignees left unchanged: slyunnn already handles testing on this issue, so per policy no transfer is performed — this comment is verification evidence only.
Not covered here: 3+ level nesting, correlation through LATERAL/set operations, and performance at scale.
Activity
5 remaining items
slyunnn commentedon Sep 30, 2026
Verification Environment
origin/maincommit19e01d261b078c172585a3ca46da86eb7e446921(test: reduce race fixture work and strengthen regression coverage (#29520)).mo-servicebinary was freshly built from that exact worktree; its SHA-256 was1e03ca96c78d8a11f2807c30aee5d92cee3a3d62ce10fad0d776763926397c48, matching the binary mounted in CN1.2 CN / 1 TN / 1 Log service / Proxy. The isolated MySQL endpoints were Proxy6621(service port6009), CN116621(service port16001), and CN216622(service port16002). All endpoints were reachable and passed post-query health checks.mysqlCLI. Endpoint cases ran in parallel with isolated databases and no shared test objects.a97f9c940bba4bcbc6d7c615f789fccab1ac25f9,fix(sql): preserve join locality and numeric CAST metadata(#29452). Its design and PR description explicitly state that it is prerequisite work only and does not implement or close [Feature Request]: Support correlated subquery with multi levels #7559.What Was Covered
EXISTScontrol returned1,2,3through Proxy, CN1, and CN2.EXISTSreturned the expected1through Proxy, CN1, and CN2.INreturned the expected1through Proxy, CN1, and CN2.ERROR 20102:correlated columns in SCALAR subquery deeper than 1 level ... is not yet implemented, consistently through all three endpoints.SELECT 1after the tested statements.TestNestedCorrelatedScalarStillRejectsUnsafeShapespassed with exit status0; it asserts this current explicit rejection.FROM-subqueries, arbitrary parameter domains, demand/cardinality handling, and materialization budgets. The issue is a broad feature request without a finalized general implementation design.Findings
MatrixOne currently has partial multilevel correlation support: the representative two-level
EXISTSandINforms execute correctly, while a representative two-level scalar correlation is intentionally rejected bypkg/sql/plan/flatten_subquery.go. Therefore, the requested general capability is not implemented. The linked timeline event only assigned the issue; it did not indicate a completed implementation.Current
mainsupports the tested multilevelEXISTSandINforms but does not support the tested multilevel scalar-subquery form; #29452 provides physical prerequisites only and must not be treated as a fix for the general feature.MOTR / BVT Coverage
No MOTR case, branch, recording, replay, commit, or PR was created. This is an open
kind/featurerequest rather than a fixed bug regression, and adding a MOTR expectation for a deliberately unsupported feature would not provide valid coverage. Existing planner coverage explicitly verifies the current rejection; the real SQL endpoint matrix above verifies the current public behavior.Large-data regression is not required. The observed limitation is a planner/decorrelation capability gate that occurs before data-volume-dependent execution; row count, block/batch boundaries, memory/spill, concurrency, skew, network transfer, and resource scale do not change the support decision.
XuPeng-SH commentedon Oct 18, 2026
continue20 独立实测:#30116 对本 issue“超过一层的关联子查询”报告范围已经通过,转测试。
main
2508ce7029b03e6bb3ac0bd8e66a994d12593664,Linux/amd64、Go1.27.1、CPU/CGo,隔离worktree;使用仓库mo-cgo-test入口及测试Go overlay,未改产品源代码。证据
/workspace/work/pr-audit-continue20/logs/:public-matrix.log、dependent-public-cancel-enabled.log(exit0)、dependent-full.log、dependent-consumers.log、dependent-race.log、dependent-frontend.log、planner-parser-full.log。coverage/dependent-union.json保留分母与同SHA profile。公开命令:MO_TEST_CLUSTER_TCP_ONLY=1 .agents/skills/mo-dev/scripts/mo-cgo-test -overlay=/workspace/work/pr-audit-continue20/public-overlay.json -p 1 -v -count=1 -timeout=10m -run '^TestAudit20PublicMatrix$/^CN[01]$/^30116_multilevel_correlated$' ./pkg/tests/issues;race选择TestDependent.*|TestCorrelation.*|TestNativeKernelTerminalCause|TestSourceEdgeRetiresRoundControlBudget|TestPublicDependentStreamingExecution,覆盖dependent/plan/compile/process四包,exit0。按main报告范围转 @Ariznawlll,移除原开发指派;不自动要求pick到4.2。此结果不表示最近100个PR已全部完成高覆盖实测。
slyunnn commentedon Oct 22, 2026
Regression and extended verification for #7559 (2026-10-22)
Verification Environment
git fetch origin mainin the running-source worktree.HEADandorigin/mainboth resolved toada0bde326adec3c3906d2f417c266d0ada5b054—feat: control TPC-H comparison resources and paired measurement (#30599).mo-servicebinary was built from this ref: Go1.27.1, commitada0bde326, running from the local current-main source worktree.2 CN / 1 TN / 1 Log service / Proxy, launched with the local proxy configuration. Proxy6001, CN116001, and CN216002were reachable.6001; core execution and health checks ran directly through CN116001and CN216002.feat(sql): support multilevel correlated subqueries, merged as94760aa93223924df314c12d7079323f2e89c2b1. Its main implementation commit is7010830b375096c5f3683f261cf68bedbc157d63. The merge commit is an ancestor of the verified current main.What Was Covered
(1,2),(2,3), and(3,4)forSELECT o.k, (SELECT (SELECT o.k + 1)).(1,2),(2,4), and(3,6)forSELECT o.k, (SELECT (SELECT (SELECT o.k * 2))).EXISTSreturned(1,21),(2,20), and(3,30)through Proxy, CN1, and CN2.empty_scalar_is_nullresult was1.k > 1with delta10returned(2,12)and(3,13).ERROR 1242(Subquery returns more than 1 row); subsequent ProxySELECT 1succeeded.SELECT 1; both direct endpoints produced the same functional results as Proxy.LIMIT, block/batch, spill, index, skew, or network-transfer defect. The small multi-row/duplicate-inner fixture exercises demanded invocation and cardinality behavior; no large-data regression is required for this functional conclusion.MOTR -j Nwas not used as a proxy for engine behavior.Findings
The requested multilevel correlated-subquery capability is now present in verified current
mainfor nested scalar ancestor references, correlated aggregates, empty scalar results, Prepared Statement parameters, and standard scalar-cardinality errors. The historical unsupported deeper-than-one scalar rejection is not reproduced. Proxy, CN1, and CN2 returned consistent results.MOTR / BVT Coverage
No new MOTR/BVT case was needed or created. PR #30116 already contains extensive owned planner/execution and public SQL coverage for this large feature. The independent verification above exercised the issue contracts directly against the actual latest-main multi-CN service, so no test branch, recording/replay, commit, push, or daily-summary entry applies.
Final Conclusion
Fixed — PR #30116 is merged in verified
origin/main, and actual Proxy/CN1/CN2 MySQL-protocol validation confirms the requested multilevel correlated-subquery support within the tested functional scope.XuPeng-SH commentedon Oct 22, 2026
Verified on
main@3ad9adbb4c(PR #30116 merged) — no transfer,slyunnnalready owns testingBuilt
mo-servicefrom currentmainlocally (CGo, arm64) and ran adversarial multi-level correlated cases against a fresh isolated instance, using an equivalent JOIN/GROUP BY rewrite as the oracle (independent of the subquery decorrelation path):Actual on HEAD:
1|100,2|50,3|9— identical to the oracleNested scalar-inside-scalar with two outer references also produces the manually verified values (
1|1,2|1,3|0; fora=3the onlyc=7row hasd=0 < b=1, so0is correct).Assignees left unchanged:
slyunnnalready handles testing on this issue, so per policy no transfer is performed — this comment is verification evidence only.Not covered here: 3+ level nesting, correlation through
LATERAL/set operations, and performance at scale.