Optimize query to see if mode is used