Cassandra:如何选择过去30天内更新的数据

Ana*_*ika 5 cassandra nosql cassandra-3.0

我们要求从表中加载最近30天的更新数据.

下面的潜在解决方案之一不允许这样做.

select * from XYZ_TABLE where WRITETIME(lastupdated_timestamp) > (TOUNIXTIMESTAMP(now())-42,300,000);

select * from XYZ_TABLE where lastupdated_timestamp > (TOUNIXTIMESTAMP(now())-42,300,000);
Run Code Online (Sandbox Code Playgroud)

该表有列

lastupdated_timestamp (with an index on this field)
lastupdated_userid (with an index on this field)
Run Code Online (Sandbox Code Playgroud)

任何指针......

小智 6

除非您的表是使用此查询构建的,否则您的查询将搜索数据库的每个分区,一旦您的数据集变大并且可能导致超时,这将变得非常昂贵.

为了有效地完成此查询,XYZ_TABLE应该具有如下所示的主键:

PRIMARY KEY ((update_month, update_day), lastupdated_timestamp)
Run Code Online (Sandbox Code Playgroud)

这是如此Cassandra知道在哪里找到数据.它有快速查找的月和日桶,然后您可以运行这样的查询以查找某一天的更新.

SELECT * FROM XYZ_TABLE WHERE update_month = 07-18 and update_day = 06
Run Code Online (Sandbox Code Playgroud)