datafusion icon indicating copy to clipboard operation
datafusion copied to clipboard

MySQL does not support derived tables without aliases

Open peasee opened this issue 1 year ago • 0 comments

Describe the bug

In some logical plans, .derive() creates a new subquery as a derived table like FROM (SELECT ...).

In MySQL, every derived table requires an alias. .derive() does not supply an alias to these derived tables, so the queries fail in MySQL.

To Reproduce

Run a query on MySQL that triggers a logical plan derive, like:

select min(ta.j1_id) as j1_min from j1 ta order by min(ta.j1_id) limit 10;

Observe the query fail, because the re-written SQL contains a derived table without an alias.

Expected behavior

The query should succeed without a syntax error.

Additional context

As seen from the MySQL manual: https://dev.mysql.com/doc/refman/8.4/en/derived-tables.html

The [AS] tbl_name clause is mandatory because every table in a FROM clause must have a name.

peasee avatar Oct 18 '24 06:10 peasee