在 Cassandra 中建模 M:M 关系的替代方法有哪些?

发布于 2024-08-27 19:00:57 字数 113 浏览 5 评论 0原文

考虑需要在 Cassandra 数据存储中表示的 M:M 关系。

有哪些 M:M 建模选项可用?对于每一种选择,什么时候是首选?您在 Cassandra 支持的项目中做出了哪些 M:M 建模选择?

Consider a M:M relation that needs to be represented in a Cassandra data store.

What M:M modeling options are available? For each alternative, when is it to prefer? What M:M modeling choices have you made in your Cassandra powered projects?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初熏 2024-09-03 19:00:57

您不必像使用 RDBMS 那样使用连接表,而是拥有一个 ColumnFamily,其中每个 X 包含一行以及与其关联的 Y 列表,然后是一个 CF,其中包含每个 Y 的一行以及每个关联的 X 的列表与它。

如果事实证明您并不真正关心查询这些方向之一,那么只保留您确实关心的 CF。

Instead of using a join table the way you would with an rdbms, you would have one ColumnFamily containing a row for each X and a list of Ys associated with it, then a CF containing a row for each Y and a list of each X associated with it.

If it turns out you don't really care about querying one of those directions then only keep the CF that you do care about.

ゃ人海孤独症 2024-09-03 19:00:57

Cassandra设计为Key value数据库,因此要实现M:M有两种方法可以实现。

  1. 对数据进行反规范化,以便每个关系都应该重复数据。

    即。 x->y(值) 和 x->z(值) 和 a->y(值)

    y 应该保存为 x 和 a

    应该这样做,因为它可以增强数据库的强度

  2. 将关系键的引用保存为值。

    x->y(键)和 x->z(键)和 a->y(键)

    因此,如果您需要 x 的值为 y,则应该进行两次操作,获取 x,这将为您提供 y 的值。然后在单独的操作中获取 y 本身。

Cassandra 不是 RDBMS,因此不要将您的注意力集中在通过删除值和定义关系的传统方式上。

Cassandra by design is Key value database, so to achieve M:M there are two ways to do it.

  1. De-normalize your data so every relation ship should duplicate data.

    ie. x->y(value) and x->z(value) and a->y(value)

    y should be saved for x and a

    This is how it should be done as it's give you strength of database

  2. Save reference for relational key as value.

    x->y(key) and x->z(Key) and a->y(Key)

    So if you need x with value of y it should be two operation, get x which will give you value of y. Then get y itself in a separate operation.

Cassandra is not RDBMS so don't wrap you mind around traditional way of doing it by dropping values and define relationship.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文