44

When I use IdentityUser model in Asp.Net Identity with EntityFramework, it creates some standard fields in the database. All the fields are self explanatory except for the below two fields.

  • NormalizedUsername - Which contains the uppercase value of the Username
  • NormalizedEmail - Which contains the uppercase value of the Email

My doubts are:

  1. Why do we need these Normalized fields? Where does it get used?
  2. What is the purpose of persisting it in the database?
2

2 Answers 2

50

By my understanding, both fields are there for performance reasons. It's sort of explained in the following thread Normalization on UserName and Email causes slow performance and are used to validate the case insensitive uniqueness of the UserName and Email fields. They are persisted in the database in order be able to create index on them, thus making the lookups by the normalized user name and email sargable.

There is no other reason or usage of these fields.

8
  • 1
    whats the advantage of having indexes on normalized names rather than, indexing names without normalizing them ? Dec 16, 2018 at 21:04
  • 4
    @brainoverflow98 to be able to use the index for case insensitive searches
    – Ivan Stoev
    Dec 17, 2018 at 7:04
  • 3
    It bugs me that it's using capitalized version in normalization. Performance-wise, we'd achieve the same result if we'd go lowercased too. It doesn't go any faster to index just because the computer SCREAMS AT US... Aug 2, 2021 at 13:42
  • 4
    @KonradViltersten A wild guess could be for uppercase selection is that ordinary users generally tend to write their email in all lowercase. So, it may increase developer awareness about normalized fields when the developer look at data on the table and see normalized fields are all in uppercase. If lowercase was chosen for normalization, especially first-time developers could look into the table and say "Normalized fields are same with original fields, so what is the point?". When they saw all uppercase, they can at least say "something is fishy here". As I say, this is a only a guess by me.
    – MÇT
    Jan 21, 2022 at 8:49
  • @MÇT Interesting point. I've got a comment from an (older) developer who had the idea that originally, waaay back, everything was upper-case for the simple reason that lower-case didn't exist in the set of available characters being processed. We're talking the days when T-Rex would be typing the code if the arms' length allowed. Apparently, according to him, they didn't have a full ASCII table to play with and mainly could process capitals and digits. Hence, the shouting syntax of SQL with it's SELECT X FROM Y WHERE... Jan 21, 2022 at 16:21
3

Because in String.Compare("a", "A"), "a" is greater than "A" based on the binary values. The above compare statment translates to String.Compare(01100001, 01000001). As you can see one value is greater than the other.

Normalization brings the property to UpperCase (I believe) where SQL can index the UserName binary values sequentially without any surprise out of sequence lower case letters and their respective binary values.

This improves performance when searching or querying the database.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.