复合分区键 - 行搜索VS.列搜索

时间:2016-06-07 08:02:56

标签: cassandra cassandra-2.0

我的查询是获取特定考试的特定学生的分数。对于Cassandra表设计,选项1,

 CREATE TABLE student_score (
  student_name text,
  exam_name text,
  score int,
  exam_time timeuuid
  PRIMARY KEY (exam_name,student_name)
 )
 WITH CLUSTERING ORDER BY (student_name DESC);

exam_name将是分区键,所有学生都将在广泛的行中。

选项2,

 CREATE TABLE student_score (
  student_name text,
  exam_name text,
  score int,
  exam_time timeuuid
  PRIMARY KEY ((exam_name,student_name))
 )

exam_name和student_name一起形成分区键,因此没有宽行。

选项1是标准方式。但是选项2有什么问题?

1 个答案:

答案 0 :(得分:2)

选项2没有任何问题,但使用选项2,您只能使用exam_name和student_name一起查询。

如果有更多学生参加特定考试,选项一将面临数据分发问题,即数据不会均匀分布。

如果同一个考试中出现多名同名学生,则这两种方法都会遇到问题。