Reputation: 24325
I have a database using VARCHAR(255) as its primary key on tables and they look like GUIDs. Wouldnt an Int be better for performance?
Upvotes: 2
Views: 2264
Reputation: 923
It depends on your storage engine, but generally speaking an int/bigint would be better. If you are using innodb, a uuid/guid is a bad choice for a primary key because of the way a clustered index works. read this blog to learn more about it. To sum it up, keys are stored by range and since uuids' are random they would make inserts and lookups less efficient since you would thrash the cache with reading and writing whole memory blocks for each row.
Upvotes: 2
Reputation: 39991
Ints take less space on disk so you need less I/O when searching. As long as the range suits your need I would say that an int would be faster.
Upvotes: 0