You have several options:
- Save it as VARCHAR (36), as you said. It will take 36 bytes (288 bits) of memory per UUID, not counting the overhead.
- Store each UUID in two BIGINT columns, one for the least significant bits and one for the most significant bits; use UUID # getLeastSignificantBits () and UUID # getMostSignificantBits () to capture each part and save it properly. It takes 128 bits of storage per UUID, not counting any overhead.
- Store each UUID as an OBJECT object; this saves it as a binary serialized version of the UUID class. I have no idea how much space this takes; I need to run a test to find out what the standard serialized form of Java UUID is.
The top and bottom sides of each approach are based on how you pass the UUIDs in your application - if you pass them as your string equivalents, then the flaw requires a double storage capacity VARCHAR (36) will probably outweigh without reinstalling them every time You are executing a query or updating a database. If you pass them as native UUIDs then the BIGINT method is likely to be pretty low. Upstairs.
Oh, and it's nice that you want to consider questions about speed and storage space, but as many of them, as I said, it’s also good that you acknowledge that this may not be critical, given the amount of data your application will stored and maintained. As always, micro-optimization for performance’s sake is important only if it doesn’t lead to unacceptable cost or performance. Otherwise, these two problems — the UUID memory space and the time required to service and query the database — are of rather low importance, given the cheap storage cost and the ability of database indexes to make your life much easier. :)
delfuego
source share