The partition key picks a row's partition and the nodes that store it, and the clustering key sorts the rows inside that partition. Cassandra hashes the partition key to pick the replica nodes, and every row with the same partition key lives in one partition.
CREATE TABLE events (
user_id UUID,
event_time TIMESTAMP,
event_type TEXT,
data TEXT,
PRIMARY KEY (user_id, event_time, event_type)
);
Here user_id is the partition key, and event_time and event_type are clustering keys. All events for one user are stored together, sorted by time and then by type.
An efficient query gives the full partition key, because by default CQL refuses a query that would scan every partition. It can then restrict the clustering keys in the order they are declared, such as every event after a given time. You fix the clustering order when you create the table and can't change it later.
This answer doesn't lend itself to a diagram - it reads best . No credits were charged.
Why there's no diagram: “”
The interactive diagram is below the answer - jump to diagram ↓ · Below it, the related concept . Jump to it ↓
The diagram below the answer is the concept . Jump to it ↓