【问题标题】:Am I using cassandra efficiently?我是否有效地使用了 cassandra?
【发布时间】:2015-10-22 02:53:50
【问题描述】:

我有这些表

CREATE TABLE user_info (
    userId uuid PRIMARY KEY,
    userName varchar,
    fullName varchar,
    sex varchar,
    bizzCateg varchar,
    userType varchar,
    about text,
    joined bigint,
    contact text,
    job set<text>,
    blocked boolean,
    emails set<text>,
    websites set<text>,
    professionTag set<text>,
    location frozen<location>
);

create table publishMsg
(
    rowKey uuid,
    msgId timeuuid,
    postedById uuid,
    title text,
    time bigint,
    details text,
    tags set<text>,
    location frozen<location>,
    blocked boolean,
    anonymous boolean,
    hasPhotos boolean,
    esIndx boolean, 
    PRIMARY KEY(rowKey, msgId)      
) with clustering order by (msgId desc);

create table publishMsg_by_user
(
    rowKey uuid,
    msgId timeuuid,
    title text,
    time bigint,
    details text,
    tags set<text>,
    location frozen<location>,
    blocked boolean,
    anonymous boolean,
    hasPhotos boolean,
    PRIMARY KEY(rowKey, msgId)      
) with clustering order by (msgId desc);

CREATE TABLE followers
(
    rowKey UUID,
    followedBy uuid,
    time bigint,
    PRIMARY KEY(rowKey, orderKey)
);
  1. 我在 BATCH 中执行 3 INSERT 语句,将数据放入 publishMsgpublishMsg_by_userfollowers 表中。

  2. 要显示一条消息,我必须在不同的表上查询三个 SELECT 查询:

publishMsg - 获取发布消息的详细信息,其中rowkeymsgId 给出。

userInfo - 基于postedById 得到fullName

followers - 了解postedById 是否关注给定主题

这是使用 cassandra 的合适方式吗?由于给定的 scanerio 数据无法放入单个表中,这会不会很有效。

【问题讨论】:

  • 追随者中的“rowKey”意味着什么?是特定消息的关注者,还是特定用户的关注者?
  • 啊,一定是用户的。当您说“显示一条消息”时,为什么需要了解用户的关注者?
  • followers rowKey 中是一些主题,后面是ID 为followedBy 的用户。所以从这张表中我想知道给定的用户是否关注给定的主题

标签: cassandra cql cassandra-2.0 datastax


【解决方案1】:

很抱歉在回答中提出这个问题,但我没有代表发表评论。

暂时忽略表格,您的应用程序需要询问哪些信息?理想情况下,在 Cassandra 中,您只需对一张表执行一次查询即可获取返回给客户端所需的数据。您无需执行 3 个查询即可获得所需的内容。

此外,您的关注者表似乎缺少 orderkey 字段。

【讨论】:

  • 我需要的一个信息是show a publish message and whether i am following that message or not 那么你将如何继续前进?
猜你喜欢
  • 2011-01-30
  • 2011-01-22
  • 2017-02-20
  • 1970-01-01
  • 1970-01-01
  • 2014-07-17
  • 2017-06-13
  • 1970-01-01
相关资源
最近更新 更多