Cassandra之中一共包含下面5种Key:

  1. Primary Key
  2. Partition Key
  3. Composite Key
  4. Compound Key
  5. Clustering Key
首先,Primary key 是用来获取某一行的数据, 可以是一列或者多列(复合列 composite)
Primary = Partition Key  + [Clustering Key] (Clustering Key 可选)
Clustering keys 包括下面两种情况:
(1) composite key
(2) compound key
 
1
2
3
4
5
6
7
8
9
10
11
12
-- 一列
(
PRIMARY KEY,
      
);
-- 复合列
(
text,
int,
text,
      
  );

 
在上面复合列的table之中,全称:  Composite Primary Key
并且:
(1) key_part_one  –> partition key
(2) key_part_two  –> clustering key
注意: partition key, clustering key 都可以是复合列。
Partition Key : Cassandra会对partition key 做一个hash计算,并自己决定将这一条记录放在哪个node
Partition Key的设计,可以完全的借用MySQL的主键。
Cassandra会给每一行数据一个timestamp,如果有多行数据,Cassandra会取时间最新的数据返回!

Clustering Key :   主要用于进行Range Query. 并且使用的时候需要按照建表顺序进行提供信息!

参考下面代码:
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
-- 创建表
-- 注意state 这个field
(
text,
text,
int,
text,
int,
uid)
)
 
 
-- 插入一些值
zip)
98100);
xxxx more
zip)
10840);

有效的查询:
 
1
'ny';

本质是先node上查找后,然后range筛选!
 

相关文章:

  • 2022-12-23
  • 2021-10-03
  • 2022-12-23
  • 2021-10-12
  • 2021-05-01
  • 2021-07-03
猜你喜欢
  • 2021-08-20
  • 2021-11-01
  • 2021-10-10
  • 2021-05-17
  • 2021-10-02
  • 2022-12-23
  • 2021-07-13
相关资源
相似解决方案