Primary key database

I have a user table where there are hundreds of millions of rows and a user name field (varchar), should I make it the primary key instead of a unique index? What are the advantages or disadvantages of adding an additional user_id (int) field and making a primary key instead? I do not see where I will use user_id, except to say about the state of the connection, where the union in int will be faster than the union on varchar? or that? (since both fields are indexed)

update: suppose changing a username is not an option.

+3
source share
4 answers

, : , - . , , , , . , , .

( - ) - . , . , , , . .

+3

.

, -imho- "-". - , , .
, , .

: , . .

, , , 4 , USename .
, , , .
, , , , , , .

+3

, PK, - , .

, , , , .

, . MySQL "auto_increment" , Postgres Oracle .

, , . PK, , , , .

+2

Source: https://habr.com/ru/post/1784260/


All Articles