This is the case: the user table contains the usernamechar (16) NOTNULLCOMMENT & #039; username & #039;, passwordchar (32) NOTNULLCOMMENT & #039; password & #039;, emailchar (32) NOTNULLCOMMENT & #039; user email & #039;, mobilechar (15) NOTNULLCOMMENT... the situation is as follows:
These fields are in the User table.
usernameChar (16) not null comment 'username ',
passwordChar (32) not null comment 'Password ',
emailChar (32) not null comment 'user mailboxes ',
mobileChar (15) not null comment 'user phone ',
Username email mobile is unique, so I want to create a unique index for them.
However, during registration, the user may only need a mobile phone number. You do not need to enter the email address or user name. In this case, a problem occurs. If you only have a mobile phone number while the user name is used for registration, the mailbox has a null string by default, but it cannot be inserted because it has a unique index. I want to set null by default, that is, to allow null, but I can see this sentence:
Avoid NULL as much as possible: the column should be specified as not null unless you want to store NULL. In MySQL, it is difficult to query and optimize columns with null values, because they make the index and index statistics and comparison operations more complex. You should replace null values with 0, a special value, or an empty string.
If I have saved null in the user name and mailbox, then there will be no index. Will this field be unable to be indexed? Performance problems?
Please tell me how to solve this problem
Reply content:
The situation is as follows:
These fields are in the User table.
usernameChar (16) not null comment 'username ',
passwordChar (32) not null comment 'Password ',
emailChar (32) not null comment 'user mailboxes ',
mobileChar (15) not null comment 'user phone ',
Username email mobile is unique, so I want to create a unique index for them.
However, during registration, the user may only need a mobile phone number. You do not need to enter the email address or user name. In this case, a problem occurs. If you only have a mobile phone number while the user name is used for registration, the mailbox has a null string by default, but it cannot be inserted because it has a unique index. I want to set null by default, that is, to allow null, but I can see this sentence:
Avoid NULL as much as possible: the column should be specified as not null unless you want to store NULL. In MySQL, it is difficult to query and optimize columns with null values, because they make the index and index statistics and comparison operations more complex. You should replace null values with 0, a special value, or an empty string.
If I have saved null in the user name and mailbox, then there will be no index. Will this field be unable to be indexed? Performance problems?
Please tell me how to solve this problem
The post I saw on the v site may help you solve your problem.
Https://www.v2ex.com/t/60437