What happens when I exhaust a bigint generated key? How to handle it?

前端 未结 4 1295
夕颜
夕颜 2020-12-03 01:37

I can\'t imagine for myself a good answer for this, so I thought of asking it here. In my mind, I\'m always wondering what will happen if the AUTO INCREMENT PRIMARY ID

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-03 02:22

    Large data sets don't use incrementing numbers as keys. Not only because you have an implicit upper limit, but it also creates problems when you have multiple servers; because you run the risk of having duplicate primary keys since they are incremental.

    When you reach this limit on MySQL, you'll get a cryptic error like this:

    Error: Duplicate entry '0' for key 1
    

    Its better to use a unique id or some other sequence that you generate. MySQL doesn't support sequences, but postgresql does.

提交回复
热议问题