本文介绍了Cassandra - 通过主键使用主键列的任意子集搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在Cassandra中查找主键与所有主键字段的任意子集匹配的记录?
使用下面的表格,可以找到谁的主键具有特定类型
未指定 id
或 size
?
Using the table described below, it is possible to find the records whos's primary key has a particular type
and name
without specifying an id
or size
?
CREATE TABLE playlists (
id uuid,
type text,
name text,
size int,
artist text,
PRIMARY KEY (id, type, name, size)
);
$ b
谢谢!
Thanks!
推荐答案
至少在Cassandra 1.2中是可以的,但是默认情况下是禁用的
At least in Cassandra 1.2 it is possible but it is disabled by default,
如果你尝试这样做:
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
this:
SELECT * from playlist where type = 'sometype' and name = 'somename' ALLOW FILTERING;
在您的示例中,Cassandra将允许您使用主键的完整子集从左到右执行查询例如:
In your example Cassandra will allow you to do queries using a complete subset of the primary key from left to right, for example:
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)
希望它有帮助
这篇关于Cassandra - 通过主键使用主键列的任意子集搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!