2013-09-21 24 views
0

假設所有人員記錄都由UUID標識,並且所有組都由UUID標識。當您需要通常查詢組中所有人的列表以及某個人所屬的所有組的列表時,您將創建何種數據模型。即在cassandra下存儲個人組成員

create table membership (
    person_uuid uuid, 
    group_uuid uuid, 
    joined bigint, 
    primary key (person_uuid, group_uuid)); 

上面將優化用於通過人查詢,並且下面將優化用於通過組查詢。

create table membership (
    group_uuid uuid, 
    person_uuid uuid, 
    joined bigint, 
    primary key (group_uuid, person_uuid)); 

有沒有處理,所以你可以通過person_uuid和優化查詢通過group_uuid,而不必使用「允許過濾」一個整潔的方式,即:

select group_uuid from membership where person_uuid=? 
select person_uuid from membership where group_uuid=? allow filtering 

你先走一步,存儲兩個這兩個方向的查詢數據副本,這有原子性問題,雖然正確嗎?

回答

0

@Jacob

你可以做的是建立主鍵的第二集羣組件上二級索引,以便能夠在其上進行查詢。

create table membership (
    person_uuid uuid, 
    group_uuid uuid, 
    joined bigint, 
    primary key (person_uuid, group_uuid)); 

create index on membership(group_uuid); 

當然,那麼你就需要添加允許過濾的查詢,但它會比沒有索引快得多。

如果您選擇使用2個表的索引數據,而無需使用輔助索引,你可以使用原子批量插入數據,保證原子