如何解决是否可以仅使用时间戳 PK 字段并且不使用 ALLOW FILTERING 和 TTL 选项来删除 Cassandra 中早于“x”的数据?
标题说明了一切。我有一张表 timestampTEST
html,body {
height: 100%;
margin: 0;
padding: 0;
}
div#container {
height: 100%;
}
div#container > aside {
background-color: #e87800;
overflow-y: auto;
z-index: 10;
}
div#container > main > nav {
position: fixed;
top: 0;
height: 60px;
width: 100%;
background-color: seagreen;
}
div#container > main > div {
height: 100%;
margin-top: 60px;
overflow-y: auto;
}
@media (min-width: 768px) {
div#container > aside {
position: fixed;
left: 0;
top: 0;
bottom: 0;
height: 100%;
width: 80px;
}
div#container > main {
margin-left: 80px;
}
div#container > main > nav {
position: fixed;
top: 0;
}
}
@media (min-width: 992px) {
div#container > aside {
width: 300px;
}
div#container > main {
margin-left: 300px;
}
}
尝试时
create table timestampTEST ( timestamp timestamp,test text,PRIMARY KEY(timestamp));
我有错误
select * from messagesbytimestampTEST where timestamp > '2021-01-03' and timestamp < '2021-01-04' ;
我在这里看到的 https://docs.datastax.com/en/dse/5.1/cql/cql/cql_using/refTimeUuidFunctions.html 这个示例(但我认为它只是 cql 查询的一部分):
InvalidRequest: Error from server: code=2200 [Invalid query] message="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"
我知道上面与 timeuuid 有关,但我也尝试过,它产生相同的错误。
解决方法
没有 ALLOW FILTERING
就不可能在 CQL 中进行。主要原因是在您的表中,主键与分区键相同,为了完成您的查询,您需要扫描所有服务器上的数据。发生这种情况是因为分区键没有排序 - 该值是散列的,并用于选择将存储它的服务器。所以 CurrentTime-1sec 将在一台服务器上,CurrentTime-10sec - 在另一台上,依此类推。
通常,对于此类查询,人们会使用一些外部工具,例如 DSBulk 或带有 Spark Cassandra 连接器的 Spark。您可以参考我已经提供的关于该主题的以下答案:
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。