What are the alternative ways to model M:M relations in Cassandra?

前端 未结 2 1637
一向
一向 2021-02-04 06:56

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

2条回答
  •  清酒与你
    2021-02-04 07:28

    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.

提交回复
热议问题