【发布时间】:2014-09-27 07:11:12
【问题描述】:
我反复听说二级索引(在 cassandra 中)只是为了方便而不是为了更好的性能。唯一建议在基数较低时使用二级索引的情况(例如性别column,它有两个值男性或女性)
考虑这个例子:
CREATE TABLE users (
userID uuid,
firstname text,
lastname text,
state text,
zip int,
PRIMARY KEY (userID)
);
现在我无法执行此查询,除非我在 users 上的 firstname index 上创建二级索引
select * from users where firstname='john'
我如何对这个表进行非规范化以便我可以有这个查询: 这是使用复合键的唯一有效方法吗? 还有其他选择或建议吗?
CREATE TABLE users (
userID uuid,
firstname text,
lastname text,
state text,
zip int,
PRIMARY KEY (firstname,userID)
);
【问题讨论】:
标签: cql3 cassandra-2.0 secondary-indexes