optimize query for select min id in database backup