gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 05:52:35 25 4
gpt4 key购买 nike

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

示例:

使用下面描述的表,可以找到主键具有特定typename的记录,而无需指定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)

希望对你有帮助

关于nosql - Cassandra - 使用主键列的任意子集按主键搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16575572/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com