Skip to content

[Bug]: LATERAL and derived-table outer references are not supported like MySQL #25376

Open

Description

@Ariznawlll

Description

MySQL 8.0 supports LATERAL derived tables, and MySQL 8.0.14+ also allows derived tables inside subqueries to contain outer references in supported contexts. MatrixOne currently rejects these MySQL-compatible Model 10 join/subquery shapes.

References:

Reproduce

Verified on latest origin/main at 51656deb6.

drop database if exists mysql_compat_model10_min;
create database mysql_compat_model10_min;
use mysql_compat_model10_min;

create table t1 (id int primary key, grp int);
create table t2 (id int primary key, t1_id int, val int);
insert into t1 values (1,10),(2,10),(3,20);
insert into t2 values (101,1,5),(102,1,7),(103,2,9);

select t1.id, x.max_val
from t1
left join lateral (
  select max(val) as max_val from t2 where t2.t1_id = t1.id
) x on true
order by t1.id;

select t1.id
from t1
where t1.grp < (
  select avg(dt.val)
  from (
    select t2.val from t2 where t2.t1_id = t1.id
  ) dt
)
order by t1.id;

MySQL 8.0.45 Result

The LATERAL query succeeds:

id  max_val
1   7
2   9
3   NULL

The nested derived outer-reference query is also accepted. With the sample data above it returns an empty result set.

MatrixOne Result

LATERAL query:

ERROR 1064 (HY000): SQL parser error ... near "select max(val) as max_val ..."

Nested derived outer reference:

ERROR 20102 (HY000): correlated subquery in FROM clause is not yet implemented

Expected

MatrixOne should support these MySQL 8.0-compatible derived-table / correlated-subquery shapes, or explicitly document them as unsupported incompatibilities.

Activity

  1. added this to the MO-202607 milestone on Jul 2, 2026
  2. added
    kind/bug
    on Jul 2, 2026
  3. added theissue type on Jul 2, 2026
  4. added
    ai-heavy
    on Jul 3, 2026
  5. daviszhen commented on Jul 3, 2026

    @daviszhen
    Contributor

    支持完整的lateral 工作量大.
    短期支持, 只能做到半拉子.
    先做其他的内容

  6. Ariznawlll commented on Sep 7, 2026

    @Ariznawlll
    CollaboratorAuthor

    在最新 main(74668fc075c965c462b30f10ae24a1c19c289cfd,本地单 CN,2026-09-07)复核,LATERAL 仍未进入解析/规划路径。MySQL 8.0.45 可执行以下两类典型用法:

    1. JOIN LATERAL 中按当前外层行计算 MAX(),结果按四个 outer row 分别为 5, 5, 10, NULL;
    2. LEFT JOIN LATERAL 中使用相关 ORDER BY ... LIMIT 1 获取每组首行,同时保留无匹配 outer row。

    MO 对两条语句均在 LATERAL ( 后的子查询位置返回 1064 parser error。作为语义对照,将同样的相关聚合或 Top-1 写成 SELECT-list scalar subquery 时,MO 能返回与 MySQL 一致的结果,因此本次现象仍限定在 LATERAL/相关 FROM 能力本身。

    上述两种形状各重复 3 次,行为一致;无数据修改。

  7. XuPeng-SH commented on Oct 29, 2026

    @XuPeng-SH
    Contributor

    Consolidated acceptance scope from #23099: partitioned-table LATERAL and top-N test cases. Please retain the original reproduction and discussion in the linked issue. This consolidation does not claim the bug is fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai-heavydeferredkind/bug

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions