try to improve sql and reduce time in find next and previous time