首页 > 代码库 > cassandra的primary key, partition key, cluster key,
cassandra的primary key, partition key, cluster key,
https://stackoverflow.com/questions/24949676/difference-between-partition-key-composite-key-and-clustering-key-in-cassandra
primary key是一个宏观概念,用于从表中取出数据,primary key由多个column组合而成。
create table stackoverflow ( key text PRIMARY KEY, data text );
如上面的语句所示,主键可以是一个单独的列。但是主键也可以是由多个列组成的,如composite。
create table stackoverflow ( key_part_one text, key_part_two int, data text, PRIMARY KEY(key_part_one, key_part_two) );
在组合主键的情况下,第一部分称作Partition Key(key_par_one就是partition key),第二部分是CLUSTERING KEY(key_part_two)。
同时也需要注意,parition key和clustering key可以是由多个column组成的。
create table stackoverflow ( k_part_one text, k_part_two int, k_clust_one text, k_clust_two int, k_clust_three uuid, data text, PRIMARY KEY((k_part_one,k_part_two), k_clust_one, k_clust_two, k_clust_three) );
解释:
- Partition Key 负责将数据分布到集群节点上
- Clustering Key 负责在partition中的数据排序
- Primary key在表的key只有一个field的情况下雨partition key是等效的
- Composite/compound Key是多列key
cassandra的primary key, partition key, cluster key,
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。