DynamoDB两个具有相同哈希键并按特定排序键排序的全局辅助索引。

huangapple go评论51阅读模式
英文:

DynamoDB two Global Secondary Indexes with the same hash key order by a specific sort key

问题

当我使用筛选条件 studentGroup = 1 扫描表时,DynamoDB 返回的结果按照 mathScore 还是 scienceScore 的顺序排列?

是否有办法指定使用哪个属性(或哪个GSI)进行排序?

如果不可行,那么在设计GSI以便应用程序可以选择属性进行排序方面的最佳实践是什么?

我尝试过从DynamoDB管理控制台进行操作,但似乎无法指定用于扫描的索引。

英文:

I have a DynamoDB table with two GSI:

GSI 1

  • hash key: studentGroup
  • sort key: mathScore

GSI 2

  • hash key: studentGroup
  • sort key: scienceScore

When I scan the table with filter studentGroup = 1, does DynamoDB return the results in the order of mathScore or scienceScore?

Is there any way to specify which attribute (or which GSI) to be used for sorting?

If not possible, what's the best practice to design GSI to sort by an attribute that the application side can choose?

I tried from the DynamoDB management console, but it seems no way to specify which index to be used for scanning.

答案1

得分: 1

在DynamoDB中,当执行Scan操作时,不会跨键维护顺序,而只会在每个项目集合中维护顺序(共享相同键的项目)。

如果您想要按照mathScore对studentGroup=1进行排序,那么请从GSI1中读取。

如果您想要按照scienceScore进行排序,那么请从GSI2中读取。

在发出请求时,您必须指定要使用的索引。

aws dynamodb query \
--table-name <TableName> \
--index-name <GSI1或GSI2> \
--key-condition-expression <条件>
英文:

In DynamoDB when you do a Scan there is no order maintained across keys, but only per item collection (items which share the same key).

If you want a result where studentGroup=1 ordered by mathScore then you read from GSI1.

If you want it ordered by scienceScore then read from GSI2.

You must specify which index when you make the request.

aws dynamodb query \
--table-name &lt;TableName&gt; \
--index-name &lt;GSI1 or GSI2&gt; \
--key-condition-expression &lt;&gt;

huangapple
  • 本文由 发表于 2023年4月6日 22:27:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/75950690.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定