When querying for a large dataset, the query stalls with the error in this issue title. Looks like the code has an order problem.