What is the efficient way to store UUID generated in Java to Oracle DB? Will removing or not removing hyphen in the UUID be any use - storage/performance?
Will storing 07b319dc-7e64-4047-a3e3-63ab43864d81
as it is
OR storing07b319dc-7e64-4047-a3e3-63ab43864d81
as 07b319dc7e644047a3e363ab43864d81
make any difference?
The UUID_TO_BIN() function is used to convert the UUID values from a human-readable format into a compact format for storing it in the databases. The BIN_TO_UUID() function is used to convert the UUID from the compact format to a human-readable format for displaying.
About 20 microseconds per UUID.
Java UUID Class A UUID is a class that represents an immutable Universally Unique Identifier (UUID). A UUID represents a 128-bit long value that is unique to all practical purpose. It is used to identify information in the computer system. The UUID class belongs to java. util package.
The SID is a unique identifier that is used to distinguish this instance from other Oracle Database instances that you may create later and run concurrently on your system. The global database name is the full name of the database that uniquely distinguishes it from any other database.
Removing the hyphens will save you exactly 4 characters per row on the database, which is not really worth the effort. Oracle will not be significantly slower or faster because of these four characters. Even worse, if you want to select the the value back to your Java application and recreate an java.util.UUID
object, you need to re-insert the hyphens at the correct place.
If you want to save a little memory on the database, RAW(16)
(as vcsjones mentioned in the comment of your question) would have the smallest footprint. However, if you want to use the RAW
type, you need to disassemble the UUID into a byte[]
array. This is a bit tricky since java.util.UUID
only returns a String
representation or two long
values. Recreation of a UUID
object from a byte[]
array is even trickier.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With