CHAR() or VARCHAR() as primary key in an ISAM MySQL table?

后端 未结 4 1953
无人共我
无人共我 2020-12-10 16:31

I need a simple table with a user name and password field in MySQL. Since user names must be unique, it makes sense to me to make them the primary key.

Is it better

4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-10 17:08

    may as well just use a user ID index, it's much faster for joins vs char/varchar. the two seconds it takes to add that now could save you a lot of time later if you accidently have to expand the functionality of your schema.

    some pitfalls to think about:

    • say we add a few tables at a future date, what if someone wants to change a username?
    • say the app is more successful then we think, and we have to look at optimization, do you really want to redo your schema at this point to reduce the overhead of a varchar'ed index?

提交回复
热议问题