【发布时间】:2018-12-18 02:35:01
【问题描述】:
首先非常抱歉这么长的帖子,请多多包涵。
我是 cassandra 的新手,需要有人检查我的数据模型。我的目标是为社交媒体帖子表建模一个数据库。我计划有以下两个表来有效地存储和获取帖子。
- 张贴表
- posts_by_user 表
所有帖子都将存储在第一个表中,即帖子,这是结构
CREATE TABLE myapp_keyspace.posts (
id timeuuid,
createdat bigint,
city text,
topFourComments list<frozen<comment>>,
commentscount bigint,
content text,
contenttype text,
country text,
county text,
createdon bigint,
deletedon bigint,
iscreator boolean,
isdeleted boolean,
likescount bigint,
latitude double,
longitude double,
medias list<frozen<media>>,
mediatype text,
postcreatedby timeuuid,
posttype text,
postusername text,
postuserprofilepic text,
sharecount bigint,
state text,
status int,
tags list<frozen<tag>>,
timezone text,
title text,
updatedon bigint,
PRIMARY KEY (id, createdat))
下面是一个不同的表格,其中数据被复制到时间轴屏幕。时间轴屏幕还具有以下过滤器(全部、图像、视频、文本、朋友、组),这是结构。
CREATE TABLE myapp_keyspace .posts_by_user (
postcreatedby timeuuid,
contenttype text,
mediatype text,
posttype text,
createdat bigint,
comments list<frozen<comment>>,
commentscount bigint,
content text,
createdon bigint,
deletedon bigint,
id timeuuid,
iscreator boolean,
isdeleted boolean,
likescount bigint,
medias list<frozen<media>>,
sharecount bigint,
status int,
tags list<frozen<tag>>,
title text,
updatedon bigint,
PRIMARY KEY (postcreatedby, contenttype, mediatype, posttype, createdat)
以下是我的两个问题
1. 正如 cassandra 所说,为每个查询计划一个单独的表。考虑到时间轴屏幕上的所有过滤器,为所有过滤器编写单个查询是好还是我计划为每个过滤器单独编写。 (全部、图片、视频、文字、好友、群组)
2.我应该如何存储朋友的帖子。我正在考虑在 post_by_user 表中复制所有朋友的帖子。例如:如果我有 10 个朋友并且我正在发帖。所以单个帖子将被存储 10 次,posts_by_user 表中的每个朋友一个。
由于这是我在 cassandra 中的第一个项目,我希望在设计数据库时格外小心,以避免将来出现任何问题。
欢迎提出任何建议。
【问题讨论】:
标签: database cassandra data-modeling cassandra-3.0