I’m thinking of using MongoDB’s ObjectIds for my primary keys in MySQL. ObjectIds are stored as BINARY(12) and I think they are very unlikely to have a duplicate primary key globally. I want to avoid the performance issues with using UUID() which are BINARY(16), but require rearranging the order of the bytes for good performance. And, ObjectIds are 32-bits shorter. I was thinking of using short UUIDs as primary keys since they fit in 64 bits but I think they might have too high a chance of generating a duplicate.
I am in the process of shard’ing a database that currently uses BIGINT auto-increment primary keys and now needs the primary keys to be globally unique since they may be generated from a lot of different shards/mysql servers.
Is this a good idea? Or, is there some performance hit that the database will take because of the choice of BINARY(12) primary keys based on MongoDB’s ObjectIds?