Skip to content

Enforce order in result.changes for batch insert? #3853

Closed

Description

@neumino

So if I do

r.table('test').insert([
  {id: 1},
  {id: 2},
  {id: 3},
  {id: 4}
]).run()

In result.changes, I may not get the same order (I may get 4, 1, 3, 2 and not 1, 2, 3, 4). Would it be possible to enforce the order of changes on the server?

Activity

  1. danielmewes commented on Feb 28, 2015

    @danielmewes
    Member

    That sounds difficult since those inserts can be routed to different shards and part of the performance benefit of batched inserts comes from the fact that they do not have to be serialized but can be processed in any order.

    Do you have a specific use case in mind for which this matters?

  2. neumino commented on Feb 28, 2015

    @neumino
    MemberAuthor

    So with thinky I let people do batch inserts:

    Model.save([doc1, doc2, doc3]).run()
    // ~= r.table('data').insert(doc1, doc2, doc3, {returnChanges: true})

    Once the query comes back, I create instances of the model using what is in changes. Since it doesn't come back in the same order, I may return [doc2, doc3, doc1] which is not super friendly.

    The current field generated_keys enforce an order if I'm not mistaken so maybe the server could use that? While it would be nice for thinky, no one complained so far (or no complains reached me ^_^) so I guess it's not that important.

    Also Slightly related to #3074.

  3. danielmewes commented on Mar 2, 2015

    @danielmewes
    Member

    Oh sorry I thought you were talking about changefeeds.

    Returning changes in the same order as the input sounds reasonable.

  4. added this to the subsequent milestone on Mar 2, 2015
  5. mlucy commented on Mar 3, 2015

    @mlucy
    Member

    It's a little harder because we generate the keys on the parsing node but the changes are calculated on the shards, so we'll have to re-order them once we get them back. But it should be perfectly doable since the primary key is preserved.

  6. danielmewes commented on Dec 3, 2015

    @danielmewes
    Member

    Marking as a duplicate of #5041

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions