DynamoDB 二级索引扫描 (GSI)

DynamoDB scan on seconday index (GSI)

我正在阅读有关 Scan 的文档,它的序言是:

The Scan operation returns one or more items and item attributes by accessing every item in a table or a secondary index.1

这让我想知道,在什么情况下会扫描二级索引 return 普通 table 会 return 的不同记录集?

扫描不支持 KeyConditionExpression,仅支持 FilterExpression - 这基本上发生在检索到数据之后。

那么扫描 GSI 与 table 有何含义?

扫描可能 return GSI 与基础 table 不同的结果,因为 GSI 可以是 sparse.

GSI 具有与基 table 不同的密钥集。如果项目上存在 GSI 密钥,项目只会写入 GSI。否则它会被省略,这意味着 GSI 中的数据可能少于基数 table.

假设基 table 具有分区属性 A 和排序键 B。 table 上的 GSI 具有分区属性 C,但没有排序键。如果某个项目只有属性值 AB,但没有 C,则该项目将不会出现在 GSI 中。

编辑:AWS 在我提供的 link 中使用的示例是一个 LSI。我在问题中使用了 GSI 的示例。原理是一样的。