Cassandra uuid or text with uuid from Java
Asked Answered
S

2

5

I was thinking, instead of creating Cassandra table with uuid column if I create a text column , at the end I am going to insert in it Java.util.uuid.random string. So what will be the difference performance wise if I use text in place of Cassandra unidirectional

Subjoinder answered 3/9, 2015 at 1:3 Comment(0)
E
11

Storing a UUID as a text field would probably use a lot more storage space. A UUID is encoded with 16 bytes, but as a string it would use considerably more.

In addition to using more storage space, it would probably slow down operation somewhat since you are reading and writing more data, and if it is part of the partition key, there would be some additional overhead of calculating the token hash from a long string versus the UUID.

Esophagitis answered 3/9, 2015 at 2:48 Comment(0)
I
0

"The UUID (universally unique id) comparator type is used to avoid collisions in column names."

From Documentation on UUID In Cassandra 2.0 and 2.1: http://docs.datastax.com/en/cql/3.1/cql/cql_reference/uuid_type_r.html

If you choose to use a text field, and insert a string, it is up to the application code to ensure its a proper UUID. However, if you use the database field type of UUID, the database will ensure a proper UUID.

Please see this example in a related post How to auto generate uuid in cassandra CQL 3 command line:

"INSERT INTO users(uid, name) VALUES(uuid(), 'my name');"

Infracostal answered 3/9, 2015 at 1:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.