是否有可能在Cassandra中找到主键与所有主键字段的任意子集匹配的记录?
例:
使用下面描述的表,可以找到主键具有特定类型和名称而不指定id或大小的记录?
CREATE TABLE playlists ( id uuid,type text,name text,size int,artist text,PRIMARY KEY (id,type,name,size) );
谢谢!
解决方法
至少在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)
希望能帮助到你