【问题标题】:How deep the nesting can be in super-column families?超级列族中的嵌套可以有多深?
【发布时间】:2013-07-06 07:12:40
【问题描述】:

我正在尝试了解 Cassandra 的 DB 模型,但运气不佳。几乎所有的文档都在解释 Twissandra,一个 twitter 克隆,但它实际上是一个相当简单的案例,并没有真正帮助学习如何有效地使用 Cassandra;或者它是非常基本的低级别的东西,并没有真正展示你在现实世界中通常对列/超级列所做的事情。

所以我认为论坛是一个足够复杂的应用程序,可以从中学习。假设一个网络论坛有点像 phpBB;您可以有多个论坛,每个论坛显示多个主题,每个主题都有多个帖子。

我最初想到有单独的帖子、主题和论坛列,但这似乎与我在 RDBMS 上实现的方式没有什么不同。

所以现在我想知道超级列族中的嵌套有多深。类似下面的伪模型是一种合适的建模方式吗?

Forums = {
    forum001: {
        name: "General News",
        topics: {
            topic000001: {
                subject: "This is what I think",
                date: "2012-08-24 10:12:13",
                posts: {
                    post20120824.101213: { username: "tom", content: "Blah blah", datetime: "2012-08-24 10:12:13" }
                    post20120824.101513: { username: "dick", content: "Blah blah blah", datetime: "2012-08-24 10:15:13" }
                    post20120824.103213: { username: "harry", content: "Blah blah", datetime: "2012-08-24 10:32:13" }
                }
            },
            topic000002: {
                subject: "OMG Look at this",
                date: "2012-08-24 10:42:13",
                posts: {
                    post20120824.104213: { username: "tom", content: "Blah blah", datetime: "2012-08-24 10:42:13" }
                    post20120824.104523: { username: "dick", content: "Blah blah blah", datetime: "2012-08-24 10:45:23" }
                    post20120824.104821: { username: "harry", content: "Blah blah", datetime: "2012-08-24 10:48:21" }
                }
            }
        }
    },
    forum002: {
        name: "Specific News",
        topics: {
            topic000003: {
                subject: "Whinge whine",
                date: "2012-08-24 10:12:13",
                posts: {
                    post20120824.101213: { username: "tom", content: "Blah blah", datetime: "2012-08-24 10:12:13" }
                    post20120824.101513: { username: "dick", content: "Blah blah blah", datetime: "2012-08-24 10:15:13" }
                }
            }
        }
    }
}

【问题讨论】:

  • 我会首先考虑您希望如何查询数据。例如,您是想查找给定用户在特定日期范围内的所有帖子,还是要列出给定主题的所有帖子等。查询比其他任何事情都更能驱动模型。

标签: cassandra


【解决方案1】:
  1. 除非您正在编写不打算直接查询的 JSON 文档,否则您无法拥有该级别的嵌套。
  2. 不应使用超列,因为它们已被弃用。
  3. Chris 对您的问题的评论是绝对正确的:首先要问自己您打算如何查询数据,然后按照您打算阅读的方式编写。有时这意味着编写不止一种方式(即标准化不是目标)。
  4. 您可以通过使用复合键和/或列来获得额外的“嵌套”。
  5. 由于您只能按键和列范围进行查询,或者使用二级索引,您通常需要为不适合二级索引的列(即具有高基数)编写自己的索引。

我知道这些规则不会为您提供模型,但您的模型完全依赖于查询。这是一种与 RDBMS 不同的看待世界的方式。如果您确实需要临时查询支持(许多用例确实不需要),Cassandra 不是正确的选择。

【讨论】:

    猜你喜欢
    • 2013-01-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多