switched query optimization