Nosql Cassandra-使用主键列的任意子集按主键进行搜索
可以在Cassandra中找到谁的主键匹配所有主键字段的任意子集的记录吗? 例子: 使用下表,可以找到主键具有特定Nosql Cassandra-使用主键列的任意子集按主键进行搜索,nosql,cassandra,Nosql,Cassandra,可以在Cassandra中找到谁的主键匹配所有主键字段的任意子集的记录吗? 例子: 使用下表,可以找到主键具有特定类型和名称的记录,而无需指定id或大小 CREATE TABLE playlists ( id uuid, type text, name text, size int, artist text, PRIMARY KEY (id, type, name, size) ); 谢谢 至少在Cassandra 1.2中是可能的,但默
类型
和名称
的记录,而无需指定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)
希望这有帮助Ah ok,因此使用不符合顺序的任意子集可能会导致性能不符合O(log n)时间?示例中的id字段是分区键,它确定行的存储位置。在where子句中使用此键的筛选器使Cassandra能够有效地将查询重定向到具有相应数据的节点。缺少此分区键使得Cassandra必须将查询发送到集群中的所有节点,这是低效的,因此默认情况下是禁用的。“ALLOW FILTERING”子句支持此类搜索,但您应该将此视为您可能希望更改架构的提示。。。