Fix optimization for complex update_all queries