matrixorigin / matrixorigin/matrixone
[Bug]: LATERAL and derived-table outer references are not supported like MySQL
- Dominant language
- Go
- Stars
- 1.9k
- Forks
- 311
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 768
Description
## 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:
- MySQL JOIN syntax includes `[LATERAL] table_subquery`: https://dev.mysql.com/doc/en/join.html
- MySQL derived table outer references in 8.0.14+: https://dev.mysql.com/doc/refman/8.0/en/derived-tables.html
- TiDB documents scalar, derived, existential, quantified, and correlated subquery categories: https://docs.pingcap.com/developer/dev-guide-use-subqueries/
## Reproduce
Verified on latest `origin/main` at `51656deb6`.
```sql
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:
```text
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:
```text
ERROR 1064 (HY000): SQL parser error ... near "select max(val) as max_val ..."
```
Nested derived outer reference:
```text
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.
Contributor guide
Assessment
This issue has not been assessed yet.