DynamoDB M-M Adjacency List Design Pattern

前端 未结 2 1565
旧巷少年郎
旧巷少年郎 2020-12-01 00:05

Referring to https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/bp-adjacency-graphs.html. I was wondering if anyone could help me.

The first image is o

2条回答
  •  囚心锁ツ
    2020-12-01 01:02

    Stu's answer is not quite correct, the table actually looks as it is illustrated:

    First_id(Partition key)        Second_id(Sort Key)          Dated
    -------------                   ----------                  ------
    Invoice-92551                   Invoice-92551               2018-02-07
    Invoice-92551                   Bill-4224663                2017-12-03
    Invoice-92551                   Bill-4224687                2018-01-09
    Invoice-92552                   Invoice-92552               2018-03-04
    Invoice-92552                   Bill-4224687                2018-01-09
    Bill-4224663                    Bill-4224663                2018-12-03
    Bill-4224687                    Bill-4224687                2018-01-09
    

    In the table above, the Bill items (i.e. partition key = Bill-xxxxx) hold common information for the bill, where as the Invoice items with Bill items as sort key hold information for the bill that is specific to the given invoice.

    In order to fully reconstruct a bill, a GSI is required that allows you to lookup the complete information for a bill (i.e. the common record + invoice specific records):

    Second_id(Partition Key)       First_id                   Data
    ----------                     ---------------            -----------
    Bill-4224663                   Bill-4224663               Common bill data
    Bill-4224663                   Invoice-92551              Bill data for Invoice-92551
    Bill-4224687                   Bill-4224687               Common bill data
    Bill-4224687                   Invoice-92551              Bill data for Invoice-92551
    Bill-4224687                   Invoice-92552              Bill data for Invoice-92552
    Invoice-92551                  Invoice-92551              Redundant data!
    Invoice-92552                  Invoice-92552              Redundant data!
    

提交回复
热议问题