I just found an edge case where the current implementation of the subquery rewrite produces wrong results. The problem occurs when a non-related join alias is used in the ON clause with a key restriction. Something like
currently produces SQL like
The subquery uses a join alias that is only available outside of it. The fix is to prevent inlining such columns. A PR is on it's way...
Fixed in 5.1 as well.