Fixed query dirty flag calculation.