哪个列族方法在cassandra中更受欢迎?

时间:2014-03-04 15:06:51

标签: cassandra


我想创建一个带有字段的Cassandra列族(time_partition,key,period_time和period_value来存储时间序列数据。
我正在使用time_partition用于快速查询。 time_partition = period_time /(周的EPOCH);

哪个列族创建更好(我也有很多数据)?

方法1

CREATE TABLE tablename 
(
  time_partition text,
  key text,
  period_time text,
  period_value text,
  PRIMARY KEY (time_partition,key, period_time)
);

方法2

CREATE TABLE tablename 
(
  key text,
  time_partition text,  
  period_time text,
  period_value text,
  PRIMARY KEY (key,time_partition, period_time)
);

两种方法之间的区别在于主键的顺序。

2 个答案:

答案 0 :(得分:2)

的区别。您的主键定义了数据的物理存储方式,以及查询方式。

分区键(主键中的第1项)将定义数据将存储在哪个节点上。

以下查询对第一种情况有效(您可以在=旁边使用非分区键的其他关系)。

select * from tablename where time_partition = <val>;
select * from tablename where time_partition = <val> and key = <val>;
select * from tablename where time_partition = <val> and key = <val> and period_time = <val>;

对于第二种情况,这些有效查询将是

select * from tablename where key = <val>;
select * from tablename where key = <val> and time_partition = <val>;
select * from tablename where key = <val> and time_partition = <val> and period_time = <val>;

您无法为第一个架构运行select * from tablename where key = <val>;,为第二个架构运行select * from tablename where time_partition = <val>;

根据您的查询对表格进行建模。

答案 1 :(得分:0)

绝对没有区别。订单不会影响查询速度。