title: Generate non-fragmenting UUIDs in Postgres?
body: <p>If I understand correctly, fully-random UUID values create fragmented indexes. Or, more precisely, the lack of a common prefix prevents dense trie storage in the indexes.</p>
  
  <p>I've seen a suggestion to use uuid_generate_v1() or uuid_generate_v1mc() instead of uuid_generate_v4() to avoid this problem.</p>
  
  <p>However, it seems that Version 1 of the UUID spec has the <em>low</em> bits of the ID first, preventing a shared prefix. Also, this timestamp is 60 bits, which seems like it may be overkill.</p>
  
  <p>By contrast, some databases provide non-standard UUID generators with a timestamp in the leading 32-bits and then 12 bytes of randomness. See Datomic's Squuid's for example <a href="http://docs.datomic.com/identity.html#sec-6" rel="noreferrer">1</a>, <a href="http://docs.datomic.com/clojure/#datomic.api/squuid" rel="noreferrer">2</a>.</p>
  
  <p>Does it in fact make sense to use "Squuids" like this in Postgres? If so, how can I generate such IDs efficiently with pgplsql?</p>