开发者

Making 2 or 3 INTs unique? Is hashing the way to go?

The background is that from 2 or 3 unsigned integers I want something unique. I've done cantor pairs but they grow out of an BIGINT UNSIGNED when using 3.

Now I'm into has开发者_如何学Pythonhing, first I went with MD5 and char(32) but know I'm into CRC32 with INT UNSIGNED since it's numeric, therefore fast. The goal is high performance reading from this index.

Is hashing the only way? Can I maintain a reasonable collision probability for ~200,000 rows?


You can use binary(12) (12 bytes) which can uniquely store three 4 byte integers.

Or decimal(30) which also can do that and doesn't require you to first convert the integers to a binary encoding (just 0 pad them to 10 digits and append them together, MySql will do the conversion for you).


The likelihood of an unintentional MD5 collision is 1.47×10-29. You reasonably assume safety with 200k rows. MD5/SHA1 are designed for speed, so fast shouldn't be a concern.


How well does MySQL handle compound keys/indexes?

If MySQL can handle them in a performant way then one option would be to simply store your three integers in three separate INT columns and have a compound key that spans all three columns.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜