0
votes

According to the cassandra architecture we should mention fields as COMPOUND KEY. By that keys we can select data from column.

For examlpe:

CREATE TABLE hotelier.country (
    uuid ascii PRIMARY KEY,
    name ascii
) WITH bloom_filter_fp_chance = 0.01

Can select data only by uuid field

If want to select by name, need to ad field name as compound key.

Correct.

My question is why need to use UUID if in general compound key unique. Why need to add auxiliary field UUID?

BR!

2

2 Answers

0
votes

If want to select by name, need to ad field name as compound key.

No, if you add name as compound primary key, you can select by uuid AND name, you can not select just by name, you must provide always the uuid at the same time

My question is why need to use UUID if in general compound key unique.

Because in Cassandra, there is no sequence like in Oracle to generate surrogate keys. The way to do this is to use a random uuid generator client side, for example java.util.UUID.randomUUID()

0
votes

My question is why need to use UUID if in general compound key unique. Why need to add auxiliary field UUID?

You don't need to use UUID if you are really sure that your COMPOUND KEY is really UNIQUE.

e.g. if your PK is email, and you are sure that no one uses the same email address, you can just use the PK as PRIMARY KEY (email).


UUID just used to make sure that row/partition is unique, because it is a random of 32 alphanumeric characters, so the duplication probability is super low.

According to wikipedia, regarding the probability of duplicates in random UUIDs:

Only after generating 1 billion UUIDs every second for the next 100 years, the probability of creating just one duplicate would be about 50%. Or, to put it another way, the probability of one duplicate would be about 50% if every person on earth owned 600 million UUIDs.