Improve one of the queries related to queueing

/cc @joshk