簡體   English   中英

如何在cassandra中為聚類列選擇所有行?

[英]How do I select all rows for a clustering column in cassandra?

我有一個分區密鑰:A

聚類列:B,C

我知道我可以這樣查詢

Select * from table where A = ?
Select * from table where A = ? and B = ?
Select * from table where A = ? and B = ? and C = ?

在某些情況下,我希望B值可以是該列中的任何值。

有沒有辦法像下面這樣查詢?

Select * from table where A = ? and B = 'any value' and C = ?

選項1:

在Cassandra中,您應該設計數據模型以適合您的查詢。 因此,支持第四個查詢(通過A和C查詢,但不一定知道B值)的正確方法是創建一個新表來處理該特定查詢。 該表幾乎相同,不同之處在於“集群列”的順序略有不同:

PRIMARY KEY (A, C, B)

現在此查詢將起作用:

Select * from table where A = ? and C = ? 

選項2:

或者,您可以創建具有不同聚類順序的實例化視圖。 現在,Cassandra將使MV與您的表數據保持同步。

create materialized view mv_acbd as 
select A, B, C, D 
from TABLE1 
where A is not null and B is not null and C is not null  
primary key (A, C, B);

現在,針對此MV的查詢將像超級按鈕一樣工作

Select * from mv_acbd where A = ? and C = ? 

選項3:

不是最好的,但是您可以對表使用以下查詢

Select * from table where A = ? and C = ? ALLOW FILTERING

依靠ALLOW FILTERING絕不是一個好主意,而且絕對不是您在生產集群中應該做的事情。 對於這種特定情況,掃描位於同一分區內,並且性能可能會因您的用例在每個分區中具有多少個群集列的比率而異。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM