portfolio query optimization