Difference in primary-key column order in YugabyteDB

14 Views Asked by At

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)
1

There are 1 best solutions below

0
dh YB On

For the above table, does it change the performance or partitioning logic if we change the sequence to below one. PRIMARY KEY ((listId, item_value))

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_id is 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.