Skip to content
Advertisement

mariadb/mysql Nested `WITH` statement causes table-not-found error

I am not sure if this is a documented limit in mariadb or a bug in its query parsing. We are porting some enormous queries from vertica to mariadb, and I have encountered cases where queries with nested WITH clauses is throwing a bogus table-not-found error.

Running mariadb version: 10.3.14

The actual sql is monstrous, but I have been able to reduce it to a simple case which fails. with-bad.sql

Fails with error:

But, it does work if I have one less WITH. with-good.sql

And also works if there is no join in the 3rd WITH. with-nojoin.sql

The with-bad.sql example does work in other database engines (e.g. vertica) so not a stupid typo by me (the cause of most of my errors).

Does anyone know if this is a known mariadb/mysql limit, or known bug? Feels like a bug (i.e. the extra code which causes it does not even reference v1 directly).

Any suggested “mechanical” workarounds would be very much appreciated. Actual SQL is very complex, so hoping to avoid a complete rewrite/restructure it if possible.

Thanks

Advertisement

Answer

Do NOT use nested WITH, use chained one.

For example, your with-bad.sql should be

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement