Major optimization to query performance.