improve setting sql query