Cassandra 插入值消失

Cassandra insert value disappear

我想使用 Cassandra 数据库系统创建 tables。原始数据在图中

所以我创建了这些 table 并插入值

Create table course(
    Course_ID text PRIMARY KEY,
    Course_Name text,
    student_id text

);

然而,当我想要 select 美国历史课程中的所有学生 ID 时:select * from course where Course_Name = 'Biology';

Error from server: code=2200 [Invalid query] message="Cannot execute this query as it might involve data filtering and thus may have unpredictable performance. If you want to execute this query despite the performance unpredictability, use ALLOW FILTERING"

然后当我尝试打印出所有 table 时,我发现所有具有重复值的部分的值都丢失了......是不是因为我设计的方式 table 是错误的?如何更改它和 select 一门课程的所有学生 ID? 谢谢!!

问题是您对 table course 的查询没有使用主键;与关系数据库不同,Cassandra 中的 table 是根据您要执行的查询设计的,在这种情况下,您可以将课程名称作为组合键的一部分:

Create table course(
  Course_ID text,
  Course_Name text,
  student_id text,
  PRIMARY KEY (Course_Name, Course_ID)
);

已经有解释键之间区别的答案,例如this one, you may also want to read this article from Datastax