【发布时间】:2015-11-09 21:58:11
【问题描述】:
我的架构是:
A)
CREATE TABLE friend_list (
userId uuid,
friendId uuid,
accepted boolean,
ts_accepted timestamp,
PRIMARY KEY ((userId) ,accepted, ts_accepted)
) with clustering order by (accepted desc, ts_accepted desc);
B)
CREATE TABLE friend_list (
userId uuid,
friendId uuid,
accepted boolean,
ts_accepted timestamp,
PRIMARY KEY (userId , ts_accepted)
) with clustering order by (ts_accepted desc);
CREATE INDEX ON friend_list (accepted);
这将为查询提供最佳性能:
SELECT * FROM friend_list WHERE userId="---" AND accepted=true;
据我了解,Cassandra 会自动按 ASC 顺序对聚集的列进行排序,如果我们需要更改默认排序顺序以实现高效查询,我们指定 DESC。
使用我的架构 A,我将“接受”作为聚集键,但我需要对其进行不必要的排序,因为我必须将“ts_accepted”排序为 DESC。 这种不需要的“已接受”排序会影响性能吗?
如果是这样,假设我将“接受”作为模式 B 中的二级索引。我知道二级索引对于低基数值(布尔值)并不坏。但查询仍然可能存在一些性能问题。
请告诉我实现此查询的有效方法。
【问题讨论】:
-
就您的方案 B 而言,此答案可能有助于您了解二级索引的作用:stackoverflow.com/questions/29692738/…
标签: cassandra cassandra-2.0 query-performance nosql