Optimize query to use the index