performance penalty of strings as primary keys?

前端 未结 4 1715
旧巷少年郎
旧巷少年郎 2020-12-30 06:42

What would be the performance penalty of using strings as primary keys instead of bigints etc.? String comparison is much more expensive than integer comparison, but on the

4条回答
  •  感动是毒
    2020-12-30 07:36

    One thing to watch out for is page splits (I know this can happen in SQL Server - probably the same in MySQL).

    Primary keys are physically ordered. By using an auto-increment integer you guarantee that each time you insert you are inserting the next number up, so there is no need for the db to reorder the keys. If you use strings however, the pk you insert may need to be placed in the middle of the other keys to maintain the pk order. That process of reordering the pks on the insert can get expensive.

提交回复
热议问题