Made sort_query support scalar subqueries