- PostgreSQL suffers from index fragmentation when PRIMARY KEY is a UUID type?
Yes, this is to be expected. But if you are going to use the COMB strategy, this will not happen. Lines will always be in order (which is not entirely true, but carry with me).
In addition, the performance between native pgsql UUID and VARCHAR is not all that different . Another point to consider.
- Can fragmentation be avoided if the lower 6 bytes of the GUID are consecutive?
In my test, I found that UUID1 (RFC 4122) is sequential, the timestamp in the generated uuid is already added there. But yes, adding a timestamp to the last 6 bytes, we will calm this ordering. Thatβs all I did, because apparently the already marked timestamp is not a guarantee of order. More about COMB here
- Is the COMB GUID implemented below an acceptable and reliable way to create sequential GUIDs in Rails?
I do not use rails, but I will show you how I did it in django:
import uuid, time def uuid1_comb(obj): return uuid.uuid1(node=int(time.time() * 1000))
Where node is a 48-bit positive integer identifying the hardware address.
About your implementation, one of the main advantages of using uuid is that you can safely generate them outside the database, so using a helper class is one of the valid ways to do this. You can always use an external service to generate uuid, for example snowflake , but it may be premature optimization at this point.
Gerardo curiel
source share