Store ordered list in database (Gap approach)

后端 未结 3 1870
孤独总比滥情好
孤独总比滥情好 2021-02-08 16:14

I want to keep a large ordered list (millions of elements) in Google App Engine datastore. Fast insertion is required.

The simplest way would be adding an indexed proper

3条回答
  •  猫巷女王i
    2021-02-08 16:51

    You could make a giant linked-list.... with each entity pointing to the next one in the list.

    It would be extremely slow to traverse the list later, but that might be acceptable depending on how you are using the data, and inserting into the list would only ever be two datastore writes (one to update the insertion point and one for your new entity).

    In the database, your linked list can be done like this:

    value (PK)   predecessor
    ------------------------
      A              null
      B               A
      C               B
    

    then when you insert new data, change the predecessor:

    value (PK)   predecessor
    ------------------------
      A              null
      B               A
      C               D
      D               B
    

    Inserting is quick, but traversing will be slow indeed!

提交回复
热议问题