Repository navigation
Description
Description
MatrixOne rejects valid MySQL multi-level correlated EXISTS/IN predicates when the innermost predicate directly compares an innermost column with a column two query levels above. The previously fixed shape in #23110, where the deepest query references a middle-level column and the middle-level column references the outer query, works on the same build; this is a different remaining planner boundary.
Environment
- Branch:
main - Commit:
74668fc075c965c462b30f10ae24a1c19c289cfd - Deployment: local single-CN
etc/launch/launch.toml - Comparison: MySQL 8.0.45
- Date: 2026-09-07
Steps to reproduce
CREATE DATABASE deep_corr_repro;
USE deep_corr_repro;
CREATE TABLE outer_t(id INT PRIMARY KEY, grp INT NOT NULL);
CREATE TABLE inner_t(id INT PRIMARY KEY, grp INT NOT NULL);
INSERT INTO outer_t VALUES (1,1),(2,1),(3,2),(4,3);
INSERT INTO inner_t VALUES (10,1),(11,1),(12,2),(13,2),(14,4);
SELECT id
FROM outer_t o
WHERE EXISTS (
SELECT 1
FROM inner_t i
WHERE EXISTS (
SELECT 1
FROM inner_t j
WHERE j.id = i.id AND j.grp = o.grp
)
)
ORDER BY id;Actual behavior
MatrixOne rejects the statement:
ERROR 20102 (HY000): deep correlated predicate containing inner columns cannot be pulled above mark join is not yet implemented
The same restriction also affects:
- an innermost predicate containing only
j.grp = o.grp; ORinstead ofAND;- outer
NOT EXISTS; - equivalent nested
INforms.
Expected behavior
The query should execute with MySQL-compatible correlation semantics and return:
1
2
3
MySQL 8.0.45 executes all listed forms; the result varies correctly with EXISTS, NOT EXISTS, IN, and AND/OR semantics.
Stability and controls
- Reproducer and four variants: 3/3 identical error on MatrixOne; 3/3 deterministic rows on MySQL.
- Feature Limitation: Correlated subquery depth limitation (only 1 level supported) #23110-compatible control, with
j.id = i.id AND i.grp = o.grpin the deepest query: MatrixOne and MySQL both return1,2,3, 3/3. - Moving
i.grp = o.grpto the middle query block while keepingj.id = i.idin the innermost block also works on both systems, 3/3. - The error does not mutate data; subsequent ordinary subqueries remain usable.
Code analysis
pkg/sql/plan/flatten_subquery.go pulls deep correlated predicates above the nested subquery and dispatches them into filter and join predicates. When a remaining filter still refers to the inner relation, hasInnerColumnInDeepCorrelatedFilters triggers an explicit NYI guard because a MARK JOIN exposes only its marker. The guarded shape is also encoded as an expected-error planner test, so the black-box behavior matches the current implementation boundary rather than an environment or fixture error.
Regression coverage
After implementation, add planner UT for the pull-up/remapping shape and SQL regression coverage for EXISTS, NOT EXISTS, IN, AND/OR, empty matches, and NULL-bearing predicates.
Related
- Feature Limitation: Correlated subquery depth limitation (only 1 level supported) #23110: closed after the different middle-to-outer correlation shape was implemented.
- correlated columns in SCALAR subquery deeper than 1 level not yet implemented (error 20102) — v4.0.0-rc2 #24997: closed scalar-aggregate deep-correlation issue; scalar aggregation is not involved here.
Activity
fix(sql): support bounded deep existential predicates (#28364)
Ariznawlll commentedon Sep 8, 2026
测试版本:main@8934da6,本地单机 CN/TN/LogService。
测试步骤:
结论:深层相关谓词已可执行并返回正确结果。黑盒回归已加入 MOTR PR #150:issue_28293_deep_correlated_exists;该用例已连续 3 轮通过。
fix(sql): support bounded deep existential predicates (matrixorigin#2…
fix(sql): support bounded deep existential predicates (matrixorigin#2…
fix(sql): support bounded deep existential predicates (matrixorigin#2…