如果总是需要键,我如何制作稀疏索引? [英] How can I make a sparse index if the key is always required?

查看:25
本文介绍了如果总是需要键,我如何制作稀疏索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 DynamoDB 中的某些东西感到非常困惑:

事实证明,我需要做的只是删除这些字段.

删除任何 GSI 或 LSI 相关属性后,我可以保存该项目,果然,这些索引仅显示那些键存在的项目.

I'm terribly confused by something in DynamoDB:

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/GuidelinesForLSI.html#GuidelinesForLSI.SparseIndexes

For any item in a table, DynamoDB will only write a corresponding index entry if the index sort key value is present in the item. If the sort key does not appear in every table item, the index is said to be sparse.

[...]

To track open orders, you can create an index on CustomerId (partition key) and IsOpen (sort key). Only those orders in the table with IsOpen defined will appear in the index.

But if you have an LSI defined with an alternate sort key, when you create new items, that alternate sort key can never be null. So therefore the index isn't sparse at all because every item I create will wind up in the index.

What am I missing?

解决方案

So I finally figured it out. I should've clarified I was using the AWS console.

I created a GSI as a test, with partition key Gpart and sort key Gsort. I noticed when I create a new item, these fields are added automatically, and I cannot leave them blank, which is where I was getting stuck. (I'd get the error "One or more parameter values were invalid: An AttributeValue may not contain an empty string")

Turns out, all I needed to do was actually just remove those fields.

After removing any GSI or LSI related attributes, I can save the item, and sure enough, those indexes only show items where those keys exist.

这篇关于如果总是需要键,我如何制作稀疏索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆