We have one ycql table items where we have defined primary key on two columns. Wanted to understand if there is any significance on the sequence of columns.
CREATE TABLE items (
item_value text,
list_id uuid,
created_at timestamp,
metadata jsonb,
PRIMARY KEY ((item_value, listId))
) WITH default_time_to_live = 0
AND transactions = {'enabled': 'true'};
For the above table, does it change the performance or partitioning logic if we change the sequence to below one.
PRIMARY KEY ((list_id, item_value))
Cardinality:
list_id-> (100)
item_value-> (10000)
No, it doesn't. Because both keys will be taken together as a single value and hashed. You might have a little better on-disk compression when
list_idis first because there will be less cardinality. It would make a difference if your primary key was:PRIMARY KEY ((listId), item_value)Which would hash only on the first column.