我有3个dynamodb表,比如:
companies:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:provider.region}.${opt:stage}.companies
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
BillingMode: PAY_PER_REQUEST
Tags:
- Key: Name
Value: ${self:provider.region}.${opt:stage}.${self:custom.customDomain.domainName}
addresses:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:provider.region}.${opt:stage}.addresses
AttributeDefinitions:
- AttributeName: id
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
BillingMode: PAY_PER_REQUEST
Tags:
- Key: Name
Value: ${self:provider.region}.${opt:stage}.${self:custom.customDomain.domainName}
users:
Type: AWS::DynamoDB::Table
DependsOn: companies
Properties:
TableName: ${self:provider.region}.${opt:stage}.users
BillingMode: PAY_PER_REQUEST
AttributeDefinitions:
- AttributeName: id
AttributeType: S
- AttributeName: email
AttributeType: S
- AttributeName: upload_id
AttributeType: S
- AttributeName: company
AttributeType: S
KeySchema:
- AttributeName: id
KeyType: HASH
- AttributeName: email
KeyType: RANGE
LocalSecondaryIndexes:
- IndexName: LSI-${self:provider.region}-${opt:stage}-companyId-by-userId-index
KeySchema:
- AttributeName: company
KeyType: HASH
- AttributeName: id
KeyType: RANGE
Projection:
ProjectionType: ALL
GlobalSecondaryIndexes:
- IndexName: GSI-${self:provider.region}-${opt:stage}-uploadId-by-userId-index
KeySchema:
- AttributeName: upload_id
KeyType: HASH
- AttributeName: id
KeyType: RANGE
Projection:
ProjectionType: ALL
Tags:
- Key: Name
Value: ${self:provider.region}.${opt:stage}.${self:custom.customDomain.domainName}基本上,一个公司的记录会有很多地址,一个用户只属于一个公司,这个用户是用一个唯一的upload_id上传的,这个upload_id可以上传很多用户,所以:
如果我想得到所有的用户谁有一个特定的upload_id,是一个全球指数更好吗?
如果我想从一家公司获得所有用户,本地二级索引会更好吗?
发布于 2019-04-03 00:27:03
只有在要求索引强烈一致时,才应使用本地辅助索引(LSI)。如果您对最终一致的索引没有意见,那么您应该使用全局二级索引(GSI),因为LSI有很多限制。
有关更多详细信息,请参阅利用二次索引改进数据访问。
https://stackoverflow.com/questions/55484683
复制相似问题