scheduler: SQL optimisation - running and overtimed commands