2013-11-04 30 views
0

選擇適合卡桑德拉「表」正確的模式,我們正在努力存儲大量的屬性爲表內的特定PROFILE_ID(使用CQL3),並不能完成我們的頭周圍哪種方法是最好的:在CQL3

一。 create table mytable(profile_id,a1 int,a2 int,a3 int,a4 int ... a3000 int)主鍵(profile_id);

b。創建很多表,例如。 create table mytable_a1(profile_id,value int)主鍵(profile_id); create table mytable_a2(profile_id,value int)主鍵(profile_id); ... create table mytable_a3000(profile_id,value int)主鍵(profile_id);

c。 create table mytable(profile_id,a_all text)主鍵(profile_id); (1,「a1:1,a2:5,a3:55,.... a3000:5」)插入到mytable(profile_id,a_all)中; ,並且只存儲a_all中的3000個「列」,如: ;

d。以上都不是

的類型,我們會在這個表上運行查詢的: SELECT * FROM MYTABLE其中PROFILE_ID在(1,2,3,4,5423,44)

我們嘗試第一種方法並且查詢保持超時,有時甚至殺死cassandra節點。

回答

2

答案是使用聚類列。羣集列允許您創建可用於保存屬性名稱(col名稱)及其值(col值)的動態列。

表將

create table mytable ( 
    profile_id text, 
    attr_name text, 
    attr_value int, 
    PRIMARY KEY(profile_id, attr_name) 
) 

這允許你添加像

insert into mytable (profile_id, attr_name, attr_value) values ('131', 'a1', 3); 
insert into mytable (profile_id, attr_name, attr_value) values ('131', 'a2', 1031); 
..... 
insert into mytable (profile_id, attr_name, attr_value) values ('131', 'an', 2); 

該刀片將是最佳的解決方案。

因爲你再要做到以下幾點 「的類型,我們會在這個表上運行的查詢:從mytable的選擇*其中PROFILE_ID在(1,2,3,4,5423,44)」

這需要引擎蓋下的6個查詢,但cassandra應該能夠很快做到這一點,特別是如果您有多節點集羣。

此外,如果您使用DataStax Java驅動程序,則可以在羣集上異步併發地運行這些請求。

有關數據建模和DataStax Java驅動程序的更多信息,請查看DataStax的免費在線培訓。它值得一看 http://www.datastax.com/what-we-offer/products-services/training/virtual-training

希望它有幫助。