为什么 DynamoDB 不支持多列键(Cassandra 概念中的复合键)

Why multi-column key (composite in Cassandra's concept) is not supported in DynamoDB

我最近从 Cassandra 过渡到 DynamoDB,发现两者之间存在差异(至少对我来说非常重要)。术语有点不同,所以为了简单起见,我将它们称为 partition keyclustering key.

在 Cassandra 中,我们有一个叫做 composite key 的概念——分区键可以是多列值,也可以是聚类键。但是,DynamoDB 中似乎没有这样的概念。 AWS document 中提到了 composite,但它只是表示主键可以由 :

组成

Partition key and sort key – Referred to as a composite primary key, this type of key is composed of two attributes. The first attribute is the partition key, and the second attribute is the sort key.

我过去经常使用多列值(在 Cassandra 的意义上是 composite)作为键,所以当我意识到 DynamoDB 不支持它时,我有点震惊。我知道像 这样的连接总是一个选项。我的问题是:

  1. 将多列值作为分区键是一种反模式吗?集群键也是如此吗?
  2. 多列键会导致性能下降吗?
  3. 如果没有性能下降,那么这两种实现背后的其他权衡是什么?

如果你看一下 Cassandra 如何实现复合分区键,你会发现它只是将多个分区键列序列化为存储在 sstable 中的单个键(我曾就此写过详细解释,在 https://docs.scylladb.com/architecture/sstable/sstable2/sstable-data-file/ - 用于重新实现 Cassandra 和 DynamoDB 的开源 Scylla 项目。

DynamoDB选择不为你做这个序列化,让你自己做(这就是你所说的串联)。我认为他们选择这样做没有任何特别的原因 - 我认为它只是简化了 API.

我能想到的没有复合键的唯一缺点是您无法 索引 复合键的某些部分。在 Cassandra 中,如果 (a,b) 是复合分区键,您可以添加一个物化视图,其分区键只是 a(b 部分是集群键)。在 DynamoDB 中,您不能使用 GSI(DynamoDB 与 Cassandra 的物化视图平行)。