Change query to be atomic