是否可以仅使用时间戳 PK 字段和 w/o ALLOW FILTERING 和 TTL 选项删除 Cassandra 中早于 'x' 的数据?
Is it possible to delete data older than 'x' in Cassandra using only timestamp PK field and w/o ALLOW FILTERING and TTL option?
标题说明了一切。我有一个 table timestampTEST
create table timestampTEST ( timestamp timestamp, test text, PRIMARY KEY(timestamp));
尝试时
select * from messagesbytimestampTEST where timestamp > '2021-01-03' and timestamp < '2021-01-04' ;
我收到错误
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"
我在这里 https://docs.datastax.com/en/dse/5.1/cql/cql/cql_using/refTimeUuidFunctions.html 看到的是这个示例(但我认为它只是 cql 查询的 部分 ):
SELECT * FROM myTable
WHERE t > maxTimeuuid('2013-01-01 00:05+0000')
AND t < minTimeuuid('2013-02-02 10:00+0000')
我知道以上与 timeuuid 有关,但我也试过了,它产生了同样的错误。
如果没有 ALLOW FILTERING
,在 CQL 中是不可能做到的。主要原因是在您的 table 中,主键与分区键相同,并且为了完成您的查询,您需要扫描所有服务器上的数据。发生这种情况是因为分区键未排序 - 该值经过哈希处理,并用于 select 将存储它的服务器。所以 CurrentTime-1sec 将在一台服务器上,CurrentTime-10sec - 在另一台服务器上,等等
通常,对于此类查询,人们会使用一些外部工具,例如 DSBulk 或带有 Spark Cassandra Connector 的 Spark。您可以参考我已经提供的关于该主题的以下答案:
- Data model in Cassandra and proper deletion Strategy
标题说明了一切。我有一个 table timestampTEST
create table timestampTEST ( timestamp timestamp, test text, PRIMARY KEY(timestamp));
尝试时
select * from messagesbytimestampTEST where timestamp > '2021-01-03' and timestamp < '2021-01-04' ;
我收到错误
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"
我在这里 https://docs.datastax.com/en/dse/5.1/cql/cql/cql_using/refTimeUuidFunctions.html 看到的是这个示例(但我认为它只是 cql 查询的 部分 ):
SELECT * FROM myTable
WHERE t > maxTimeuuid('2013-01-01 00:05+0000')
AND t < minTimeuuid('2013-02-02 10:00+0000')
我知道以上与 timeuuid 有关,但我也试过了,它产生了同样的错误。
如果没有 ALLOW FILTERING
,在 CQL 中是不可能做到的。主要原因是在您的 table 中,主键与分区键相同,并且为了完成您的查询,您需要扫描所有服务器上的数据。发生这种情况是因为分区键未排序 - 该值经过哈希处理,并用于 select 将存储它的服务器。所以 CurrentTime-1sec 将在一台服务器上,CurrentTime-10sec - 在另一台服务器上,等等
通常,对于此类查询,人们会使用一些外部工具,例如 DSBulk 或带有 Spark Cassandra Connector 的 Spark。您可以参考我已经提供的关于该主题的以下答案:
- Data model in Cassandra and proper deletion Strategy