RUID - Compact and usable unique identifiers

Reason

  • UUID representation in hex takes too much space.
  • Hex does not work as identifier depending on context.

Solution

  • Encode to base64 for fewer characters.
  • Pad UUID before encoding and cut off again afterwards to make use of the padding in a way it guarantees a range of start and end characters.

Example

Comparison of a single UUID vs. RUID:

5b0ba39c-6597-11e2-9d36-001b211595d1 (36)

vs.

FsLo5xllxHinTYAGyEVldE (22)

This accumulates very fast and leads to a lot of terminal space taken. For example the output of a table with just three columns with UUIDs compared to the same output with RUIDs:

Before

SELECT uuid_generate_v1(), uuid_generate_v1(), uuid_generate_v1();
           uuid_generate_v1           |           uuid_generate_v1           |           uuid_generate_v1           
--------------------------------------+--------------------------------------+--------------------------------------
 5b0ba39c-6597-11e2-9d36-001b211595d1 | 5b0ba5c2-6597-11e2-a017-001b211595d1 | 5b0ba766-6597-11e2-b5df-001b211595d1
(1 row)

After

SELECT uuid_generate_v1()::ruid, uuid_generate_v1()::ruid, uuid_generate_v1()::ruid;
    uuid_generate_v1    |    uuid_generate_v1    |    uuid_generate_v1    
------------------------+------------------------+------------------------
 HnDG6hllxHitpAAGyEVldE | HnDHeJllxHisUEAGyEVldE | HnDH5BllxHioSEAGyEVldE
(1 row)

Future Plans

  • Getting rid of uuid-ossp dependency.
    • Implement UUID version 1 using PostgreSQLs internal information.
    • UUID version 3 (MD5), 4 (random) and 5 (SHA1) are easy to implement.
  • Integrate with PostgreSQL core using a type modifier for UUID or as separate but binary compatible type.
  • Benchmarks to get an idea of possible performance impact.
  • Measurement of bandwith savings.

Copyright and License

Copyright (c) 2010-2013 Simon Bertrang janus@errornet.de

Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.