Cassandra中分区键,复合键和聚类键之间的区别?

本文翻译自:Difference between partition key, composite key and clustering key in Cassandra?

I have been reading articles around the net to understand the differences between the following key types. 我一直在阅读网络上的文章,以了解以下key类型之间的差异。 But it just seems hard for me to grasp. 但这对我来说似乎很难掌握。 Examples will definitely help make understanding better. 实例肯定有助于更好地理解。

primary key,
partition key, 
composite key 
clustering key

#1楼

参考:https://stackoom.com/question/1ggY8/Cassandra中分区键-复合键和聚类键之间的区别


#2楼

There is a lot of confusion around this, I will try to make it as simple as possible. 围绕这个有很多困惑,我会尽量让它变得简单。

The primary key is a general concept to indicate one or more columns used to retrieve data from a Table. 主键是一般概念,用于指示用于从表中检索数据的一个或多个列。

The primary key may be SIMPLE and even declared inline: 主键可以是SIMPLE ,甚至可以内联声明:

 create table stackoverflow_simple (
      key text PRIMARY KEY,
      data text      
  );

That means that it is made by a single column. 这意味着它是由一个列组成的。

But the primary key can also be COMPOSITE (aka COMPOUND ), generated from more columns. 但主键也可以是COMPOSITE (又名COMPOUND ),由更多列生成。

 create table stackoverflow_composite (
      key_part_one text,
      key_part_two int,
      data text,
      PRIMARY KEY(key_part_one, key_part_two)      
  );

In a situation of COMPOSITE primary key, the "first part" of the key is called PARTITION KEY (in this example key_part_one is the partition key) and the second part of the key is the CLUSTERING KEY (in this example key_part_two ) COMPOSITE主键的情况下,键的“第一部分”称为PARTITION KEY (在此示例中, key_part_one是分区键),键的第二部分是CLUSTERING KEY (在此示例中为key_part_two

Please note that the both partition and clustering key can be made by more columns , here's how: 请注意,分区和群集键都可以由更多列创建 ,具体方法如下:

 create table stackoverflow_multiple (
      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)      
  );

Behind these names ... 这些名字背后......

  • The Partition Key is responsible for data dis
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值