dolthub / dolthub/dolt

Dolt reaches an analyzer internal error for a legal correlated LEFT JOIN LATERAL

Open
#11,552 0 comments 0 reactions 0 assignees View on GitHub
analyzer bad error message bug correctness customer issue good repro sql
Dominant language
Go
Stars
24.4k
Forks
873
Avg merge
1d 9h
Merged PRs (30d)
121

Description

## What happened

Dolt rejects a legal correlated `LEFT JOIN LATERAL` query with the analyzer error `rule 'hoistOutOfScopeFilters' tried to hoist filters above root node`.
The query should return one matched lateral row and one NULL-extended row.

## Environment

Dolt main (commit `c3b5ce3c67f8677ca08a0a58d8c03cdc95bff8b7`). MySQL version 8.0.43.

## How to reproduce

Run the corresponding SQL in a fresh Dolt repository.

```sql
CREATE TABLE t(id INT PRIMARY KEY);
INSERT INTO t VALUES (1),(2);

SELECT o.id, q.tag
FROM t AS o
LEFT JOIN LATERAL (
SELECT o.id + 1 AS tag
WHERE o.id = 1
) AS q ON TRUE
ORDER BY o.id;
```

Run [DOLT-WF-227.sql](DOLT-WF-227.sql) in a fresh Dolt repository.

## Expected Result

MySQL documents that a lateral derived table may reference preceding tables and may be the right operand of an `INNER`, `CROSS`, or `LEFT` join.
See the [MySQL 8.4 Lateral Derived Tables documentation](https://dev.mysql.com/doc/refman/8.4/en/lateral-derived-tables.html).

For the two input rows, the independent exact-INT expected result is:

```text
id tag
1 2
2 NULL
```

The row with `o.id = 1` satisfies the correlated lateral filter and produces `1 + 1`; the row with `o.id = 2` produces no right row and is preserved by the `LEFT JOIN` with a NULL `tag`.

## Actual Result

Dolt returned no result and failed during analysise:

```text
error on line 1 for query SELECT o.id, q.tag FROM t AS o LEFT JOIN LATERAL
(SELECT o.id + 1 AS tag WHERE o.id = 1) AS q ON TRUE ORDER BY o.id:
rule 'hoistOutOfScopeFilters' tried to hoist filters above root node
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Run DOLT-WF-227.sql, or the inline query, in a fresh Dolt repository and reproduce the analyzer failure. Start by tracing the analyzer rule named hoistOutOfScopeFilters and how it handles the correlated LEFT JOIN LATERAL. Done means the query returns id 1 with tag 2 and id 2 with a NULL tag without an internal error.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, sql
Domain
databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.