Improve single query logging and debugging