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

oyxsuwqo  于 2021-06-15  发布在  Cassandra
关注(0)|答案(1)|浏览(287)

有没有可能在cassandra中找到主键与所有主键字段的任意子集匹配的记录?

示例:

使用下面描述的表,可以找到主键具有特定属性的记录 type 以及 name 不指定 id 或者 size ?

CREATE TABLE playlists (
  id      uuid,
  type    text,
  name    text,
  size    int,

  artist text,

  PRIMARY KEY (id, type, name, size)
);

谢谢!

siv3szwd

siv3szwd1#

至少在Cassandra1.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)

希望有帮助

相关问题