Basket query optimization