4

是否可以在 Cassandra 中找到主键匹配所有主键字段的任意子集的记录?

例子:

使用下面描述的表,可以找到谁的主键具有特定的记录type并且name不指定idor size

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

  artist text,

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

谢谢!

4

1 回答 1

16

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

希望能帮助到你

于 2013-05-15T22:14:10.437 回答