Closed isomorpheme closed 2 weeks ago
I think this behavior is specific to MySQL materializing doubly nested subqueries. This looks like the DB is actually the one in the wrong as users is lexically in scope and the planner must run the corellated query per row.
Suppose this toy schema:
And this query code:
Printing
userWithPostCounts
produces SQL that looks like this:For me on MariaDB at least, running this produces an error:
(The
where
clause beingWHERE `post`.`author` = `user`.`id`
.)So it seems like using
from
with a subquery doesn't always produce well-scoped code:user.id
isn't in scope in the subquery in theFROM
clause.