mysql refactor