【发布时间】:2014-01-13 06:33:30
【问题描述】:
我是 Cassandra 的新手,并尝试了解数据模型。所以我知道如果“bob”跟随“james”,如何插入。我也知道如何查询以获取所有关注“bob”的人的列表,并且我知道如何查询以获取“bob”关注者的列表。
我的问题是,鉴于以下情况,如果我想知道“bob”是否跟随“james”,查询会是什么样子? (是或否)
这是正确的查询吗?
SELECT * FROM followers WHERE username="bob" AND following="james"
我是否需要在 FOLLOWING 上设置第二个索引才能执行上述查询?
-- User storage
CREATE TABLE users (username text PRIMARY KEY, password text);
-- Users user is following
CREATE TABLE following (
username text,
followed text,
PRIMARY KEY(username, followed)
);
-- Users who follow user
CREATE TABLE followers (
username text,
following text,
PRIMARY KEY(username, following)
);
【问题讨论】: