特定列的cassandra where子句-最佳方法

cwtwac6a  于 2021-06-15  发布在  Cassandra
关注(0)|答案(1)|浏览(337)

在cassandra数据库中搜索具有特定pid的记录时,需要使用where子句

id = uuid
pid=  Property Id (text)
created_at = timestamp

我需要找到一个特定属性id的前5条记录。

CREATE TABLE property_tax (
    id uuid,
    state text, 
    area text,       
    balance_type text,
    created_at timestamp,
    created_by text,
    last_paid_at timestamp,
    max_tax float,
    min_tax float,
    pid text,
    prev_balance float,
    prev_interest float,
    property_type text,
    tax_cess float,
    tax_year timestamp,
    total_paid float,
    total_paid_cess float,
    total_paid_tax float,
    PRIMARY KEY (pid,created_at,id)
    );

我的问题是这样的

select * from property_tax where pid = 'property1' ORDER BY created_at DESC LIMIT 5;

它按我的要求工作,但我的方法正确吗?还是需要改变。是否存在将来可能出现的性能问题。我在看5亿张唱片,而且还在增长。

新编辑:

我已经添加了两列1.state 2.area在该州将有多个区域
属性id(pid)将有多个不超过100条记录

So, I need to query TABLE property_tax for below
1. Find all the pid
2. find all the pid in the area
3. find all the pid in the state
4. find Limit 5 for pid (ORDER_BY created_at DESC)

多谢沙石

zi8p0yeb

zi8p0yeb1#

如果你总是这样做的话 WITH CLUSTERING ORDER BY (created_at DESC); 所以你不需要逆向阅读(更高效一点)。但这是一个很好的查询表。
考虑到它的5亿pid,你的意思是它会很好的工作。如果它的5亿id在一个pid中,那么您可能会得到一个非常宽的分区,这会影响性能。

相关问题