在 Cassandra 中建模 M:M 关系的替代方法有哪些?
考虑需要在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不必像使用 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.
Cassandra设计为Key value数据库,因此要实现M:M有两种方法可以实现。
对数据进行反规范化,以便每个关系都应该重复数据。
即。 x->y(值) 和 x->z(值) 和 a->y(值)
y 应该保存为 x 和 a
应该这样做,因为它可以增强数据库的强度
对
将关系键的引用保存为值。
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.
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
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.