Repository navigation
Description
Summary
LEFT JOIN and RIGHT JOIN still reject subqueries in the ON condition on the latest main, although the general JOIN-ON subquery issue #24996 was closed after support was added for INNER JOIN.
Both correlated and non-correlated scalar subqueries are rejected. EXISTS in an outer-join condition is rejected as well.
Environment
- Branch:
main - Commit:
3046f14d94b3f1a25839eeeb65729b64f85ac647 - MatrixOne version:
8.0.30-MatrixOne-v1.3.0 - MySQL comparison:
8.0.45
Reproduction
CREATE TABLE l(id INT PRIMARY KEY, k INT);
CREATE TABLE r(id INT PRIMARY KEY, k INT);
INSERT INTO l VALUES (1,1),(2,2),(3,NULL);
INSERT INTO r VALUES (11,1),(12,1),(13,3),(14,NULL);
-- Correlated scalar subquery in LEFT JOIN ON.
SELECT l.id,r.id
FROM l LEFT JOIN r
ON l.k=r.k
AND r.id=(SELECT MIN(r2.id) FROM r r2 WHERE r2.k=l.k)
ORDER BY l.id,r.id;
-- Correlated scalar subquery in RIGHT JOIN ON.
SELECT l.id,r.id
FROM l RIGHT JOIN r
ON l.k=r.k
AND l.id=(SELECT MIN(l2.id) FROM l l2 WHERE l2.k=r.k)
ORDER BY r.id,l.id;Actual result
Both statements fail during planning:
ERROR 20102 (HY000): subquery in JOIN condition is not yet implemented
The behavior reproduced 3/3 times for LEFT JOIN and 3/3 times for RIGHT JOIN. A non-correlated scalar subquery and a correlated EXISTS predicate in LEFT JOIN ON fail with the same error.
An equivalent INNER JOIN query succeeds on the same server, confirming that #24996's INNER JOIN path is active.
Expected result
The valid outer-join statements should plan and execute with normal null-extension semantics, matching MySQL 8.0.
White-box evidence
In pkg/sql/plan/query_builder.go, buildJoinTable selects NewJoinOnBinder only for plan.Node_INNER; every other join type uses NewTableBinder. TableBinder.BindSubquery returns the NYI error when allowSubquery is false.
The INNER JOIN implementation introduced for #24996 moves subquery predicates to a filter above the join. That transformation is not semantically valid for outer joins, so LEFT/RIGHT JOIN require a separate lowering strategy that preserves unmatched rows rather than reusing the INNER JOIN rewrite.
Impact
Standard MySQL-compatible queries that select a best/latest matching row inside an outer-join condition cannot run. Moving the predicate to WHERE is not an equivalent workaround because it can remove null-extended rows.
Related: #24996
Activity
Ariznawlll commentedon Aug 10, 2026
测试版本
main3c7392a0f86b23712da71f31d7a9198a2c8591a9原问题验证
原始相关标量子查询分别置于 LEFT/RIGHT JOIN ON,连续 3 次均成功执行并保留未匹配侧的 NULL 扩展行,不再报
subquery in JOIN condition is not yet implemented。Happy Path 覆盖
(1,11)、(2,NULL)、(3,NULL),验证相关MIN子查询及左侧保留。(1,11)、(1,12)、(NULL,13)、(NULL,14),验证右侧保留。Unhappy Path 覆盖
EXISTS正常执行,匹配行和 NULL 扩展行均正确;这覆盖 issue 报告的另一失败形式。白盒验证
不适用:通过公开 SQL 的 LEFT/RIGHT JOIN 语义验证。
回归测试
已加入 motr PR #89 的
suites/14_issue_regression/t/issue_26269_25973_25389_25327_25326_sql_semantics.test(commita6a50dfcf7053027dab5e9117fde7bdd7b5cdefb);非关联/EXISTS 扩展对照已独立连续验证 3 次。测试证据
MOTR 固定回归连续 3 轮通过;关联 5 个场景合计 15/15 成功、171 条断言成功。
测试结论
测试通过。