cockroachdb / cockroachdb/cockroach
opt: no data source matches with SRF and mix of comma and JOIN syntax in FROM
- Dominant language
- Go
- Stars
- 32.5k
- Forks
- 4.1k
- PR merge metrics
- PR metrics pending
Description
Looks like there might be a scope bug in optbuilder when we have a mix of comma and `JOIN` syntax in `FROM` plus an SRF or lateral join. The following query executes on PostgreSQL 14.9 but not on CRDB:
```sql
CREATE TABLE ab (a INT PRIMARY KEY, b JSONB);
SELECT * FROM ab AS x, jsonb_array_elements(x.b) AS y JOIN (VALUES (1)) AS z ON true;
```
CRDB gives this error:
```
demo@127.0.0.1:26257/demoapp/defaultdb> SELECT * FROM ab AS x, jsonb_array_elements(x.b) AS y JOIN (VALUES (1)) AS z ON true;
ERROR: no data source matches prefix: x in this context
SQLSTATE: 42P01
```
As a workaround, changing the SRF data source from comma syntax to `JOIN` syntax seems to fix it:
```
demo@127.0.0.1:26257/demoapp/defaultdb> SELECT * FROM ab AS x JOIN jsonb_array_elements(x.b) AS y ON true JOIN (VALUES (1)) AS z ON true;
a | b | y | column1
----+---+---+----------
(0 rows)
Time: 2ms total (execution 2ms / network 0ms)
```
Jira issue: CRDB-31853
Contributor guide
Assessment
This issue has not been assessed yet.