optimizing queries when knowing the result type.