Fix the performance issue with Query and Location insert function.