refactoring mysql massive select method