How does CockroachDB encode UUID?

sql
(Derek Zhang) #1

I am trying an experiment with EXPERIMENTAL_RANGES

SHOW EXPERIMENTAL_RANGES FROM TABLE test_table;

The primary key of test_table is UUID.

The results is a table with a list of start_key and end_key.
start_key | end_key | range_id | replicas | lease_holder
±-------------------------------------------------------------±-------------------------------------------------------------±---------±---------±-------------+
NULL | /"\x00\xdb\xd4\xcen\xb8C/\xb6#\xa8\x86҅P\x9a" | 25 | {1,2,3} | 2
/"\x00\xdb\xd4\xcen\xb8C/\xb6#\xa8\x86҅P\x9a" | /"\x01\xb9o\x90\x91\xdeO\b\xaa\x01\xebE\x89\xe0\xec\xe3" | 493 | {1,2,3} | 3
/"\x01\xb9o\x90\x91\xdeO\b\xaa\x01\xebE\x89\xe0\xec\xe3" | /"\x02\x97\xca0w!N4\xa9\x19\xe4}\x84\x8d4\xd0" | 256 | {1,2,3} | 1

Could anyone tell me how to read the keys? What encoding does CRDB use? How to convert them to UUIDs?

Thanks,
Derek

(Ron Arévalo) #2

Hey @derek.z,

When using experimental features great caution should be taken, because these features are experimental they are subject to change at any moment. However, to answer your question, you can use the built in function crdb_internal.pretty_key(), which itself is also an experimental feature in and of itself and is subject to change at any time as well.

Thanks,

Ron

(Derek Zhang) #3

I don’t know how to use the crdb_internal.pretty_key(). However, I successfully converted the hex string to UUID by python:

>>> import uuid
>>> uuid.UUID(bytes=’\x00\xdb\xd4\xcen\xb8C/\xb6#\xa8\x86҅P\x9a’)

Output: UUID(‘00dbd4ce-6eb8-432f-b623-a886d285509a’)