Iva*_*nov 6 cassandra cassandra-3.0
假设我在 Cassandra 中有下表:
customer_bought_product (
store_id uuid,
product_id text,
order_time timestamp,
email text,
first_name text,
last_name text,
PRIMARY KEY ((store_id, product_id), order_time, email)
Run Code Online (Sandbox Code Playgroud)
分区键是store_id和order_id,用于存储时间序列数据。
数据没有TTL,因为它应该可以随时访问。
在某些情况下,我们可能需要删除给定store_id. 这样做的最佳做法是什么?
到目前为止,我想到了以下解决方案:
store_id. - 缺点是随着我们在表中插入更多数据,这将花费越来越多的时间。store_id,从中获取键并为每个或这些键创建删除语句。- 我不喜欢这个概念,因为我必须维护记录。有没有人遇到过这个问题?从 Cassandra(不包括TTL)清除未使用记录的最佳做法是什么?
创建一个物化视图来存储属于相应store_ids的product_ids。这样您就可以在 MV 中查询给定的 store_id,然后从主表中删除相应的行。这样就可以避免使用额外的应用程序代码来维护两个不同的表。
create materialized view mv_customer_bought_product
as select product_id, store_id, order_time, email
from customer_bought_product
where order_time is not null
and email is not null
and product_id is not null
and store_id is not null
primary key (store_id, product_id, order_time, email) ;
Run Code Online (Sandbox Code Playgroud)