MySQL PRIMARY KEYs: UUID / GUID vs BIGINT (timestamp+random)

后端 未结 4 1890
谎友^
谎友^ 2020-12-24 07:47

tl;dr: Is assigning rows IDs of {unixtimestamp}{randomdigits} (such as 1308022796123456) as a BIGINT a good idea if I don\'t want to deal with UUIDs?

4条回答
  •  忘掉有多难
    2020-12-24 08:45

    Use the GUID as a unique index, but also calculate a 64-bit (BIGINT) hash of the GUID, store that in a separate NOT UNIQUE column, and index it. To retrieve, query for a match to both columns - the 64-bit index should make this efficient.

    What's good about this is that the hash:
    a. Doesn't have to be unique.
    b. Is likely to be well-distributed.

    The cost: extra 8-byte column and its index.

提交回复
热议问题