Optimise sale query. Closes #3264.