Are you only doing this to keep them unique? It would be faster to just keep an integer around and increment it every time you create a user rather than querying the DB every time.