Difference between partition key, composite key and clustering key in Cassandra?

前端 未结 8 1302
無奈伤痛
無奈伤痛 2020-11-22 12:18

I have been reading articles around the net to understand the differences between the following key types. But it just seems hard for me to grasp. Examples will

8条回答
  •  长情又很酷
    2020-11-22 12:59

    Adding a summary answer as the accepted one is quite long. The terms "row" and "column" are used in the context of CQL, not how Cassandra is actually implemented.

    • A primary key uniquely identifies a row.
    • A composite key is a key formed from multiple columns.
    • A partition key is the primary lookup to find a set of rows, i.e. a partition.
    • A clustering key is the part of the primary key that isn't the partition key (and defines the ordering within a partition).

    Examples:

    • PRIMARY KEY (a): The partition key is a.
    • PRIMARY KEY (a, b): The partition key is a, the clustering key is b.
    • PRIMARY KEY ((a, b)): The composite partition key is (a, b).
    • PRIMARY KEY (a, b, c): The partition key is a, the composite clustering key is (b, c).
    • PRIMARY KEY ((a, b), c): The composite partition key is (a, b), the clustering key is c.
    • PRIMARY KEY ((a, b), c, d): The composite partition key is (a, b), the composite clustering key is (c, d).

提交回复
热议问题