sql improovements