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?

ashish p picture ashish p · Nov 28, 2012 · Viewed 7.5k times · Source

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 storing
07b319dc-7e64-4047-a3e3-63ab43864d81 as 07b319dc7e644047a3e363ab43864d81

make any difference?


Answer

Stefan Ferstl picture Stefan Ferstl · Nov 28, 2012

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.