Some sql performance changes