Select count optimization