#372 Improve validation of subqueries