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

前端 未结 8 1314
無奈伤痛
無奈伤痛 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 13:05

    Primary Key: Is composed of partition key(s) [and optional clustering keys(or columns)]
    Partition Key: The hash value of Partition key is used to determine the specific node in a cluster to store the data
    Clustering Key: Is used to sort the data in each of the partitions(or responsible node and it's replicas)

    Compound Primary Key: As said above, the clustering keys are optional in a Primary Key. If they aren't mentioned, it's a simple primary key. If clustering keys are mentioned, it's a Compound primary key.

    Composite Partition Key: Using just one column as a partition key, might result in wide row issues (depends on use case/data modeling). Hence the partition key is sometimes specified as a combination of more than one column.

    Regarding confusion of which one is mandatory, which one can be skipped etc. in a query, trying to imagine Cassandra as a giant HashMap helps. So in a HashMap, you can't retrieve the values without the Key.
    Here, the Partition keys play the role of that key. So each query needs to have them specified. Without which Cassandra won't know which node to search for.
    The clustering keys (columns, which are optional) help in further narrowing your query search after Cassandra finds out the specific node(and it's replicas) responsible for that specific Partition key.

提交回复
热议问题