Skip to content

[Compatibility]: deep correlated EXISTS and IN predicates referencing innermost and outer columns are rejected #28293

Closed

Description

@Ariznawlll

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;
  • OR instead of AND;
  • outer NOT EXISTS;
  • equivalent nested IN forms.

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.grp in the deepest query: MatrixOne and MySQL both return 1,2,3, 3/3.
  • Moving i.grp = o.grp to the middle query block while keeping j.id = i.id in 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

Activity

  1. added this to the MO-202609 milestone on Sep 7, 2026
  2. added
    kind/bug
    on Sep 7, 2026
  3. added theissue type on Sep 7, 2026
  4. added
    severity/s0
    on Sep 7, 2026
  5. added a commit that references this issue on Sep 8, 2026
    67677d9
  6. assigned and unassigned on Sep 8, 2026
  7. Ariznawlll commented on Sep 8, 2026

    @Ariznawlll
    CollaboratorAuthor

    测试版本:main@8934da6,本地单机 CN/TN/LogService。

    测试步骤:

    1. 创建 outer_t 和 inner_t,并写入原 issue 的 group/id 数据。
    2. 执行最内层同时引用 j.id、i.id 和两层外 o.grp 的 EXISTS 查询;核对结果为 1、2、3。
    3. 执行同一嵌套结构的 NOT EXISTS 控制查询;核对结果为 4。
    4. 连续执行 3 轮,结果一致。

    结论:深层相关谓词已可执行并返回正确结果。黑盒回归已加入 MOTR PR #150:issue_28293_deep_correlated_exists;该用例已连续 3 轮通过。

  8. added 3 commits that reference this issue on Sep 17, 2026
    a7622cf
    38566ce
    0ca0a11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions