nosql – Cassandra – 使用主键列的任意子集按主键搜索
发布时间:2020-12-13 13:29:29 所属栏目:百科 来源:网络整理
导读:是否有可能在Cassandra中找到主键与所有主键字段的任意子集匹配的记录? 例: 使用下面描述的表,可以找到主键具有特定类型和名称而不指定id或大小的记录? CREATE TABLE playlists ( id uuid,type text,name text,size int,artist text,PRIMARY KEY (id,type
是否有可能在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) 希望能帮助到你 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |