Cassandra - 使用主键列的任意子集按主键搜索

时间:2013-05-15 21:49:48

标签: nosql cassandra

是否可以在Cassandra中查找主键与所有主键字段的任意子集匹配的记录?

实施例

使用下面描述的表格,可以查找主键具有特定typename的记录,而无需指定id或{{1} }?

size

谢谢!

1 个答案:

答案 0 :(得分:15)

至少在Cassandra 1.2中,它是可能的,但默认情况下是禁用的,

如果您尝试这样做:

SELECT * from playlist where type = 'sometype' and name = 'somename';

您将收到此错误:

Bad Request: 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

然后你可以启用它运行:

SELECT * from playlist where type = 'sometype' and name = 'somename' ALLOW FILTERING;

在您的示例中,Cassandra允许您从左到右使用主键的完整子集进行查询,例如:

SELECT * from playlist where id = 'someid'; (ALLOWED)
SELECT * from playlist where id = 'someid' and type = 'sometype'; (ALLOWED)
SELECT * from playlist where id = 'someid' and type = 'sometype' and name = 'somename'; (ALLOWED)
SELECT * from playlist where id = 'someid' and type = 'sometype' and name = 'somename' and size=somesize; (ALLOWED)

希望有所帮助