Restream / reindexer

Embeddable, in-memory, document-oriented database with a high-level Query builder interface.
https://reindexer.io
Apache License 2.0
763 stars 64 forks source link

Difference between ModifyItem and Update,Delete methods #73

Closed oruchreis closed 2 years ago

oruchreis commented 2 years ago

Hi, I saw these methods in grpc proto:

    rpc ModifyItem(stream ModifyItemRequest) returns(stream ErrorResponse) {}
    rpc Update(UpdateRequest) returns(stream QueryResultsResponse) {}
    rpc Delete(DeleteRequest) returns(stream QueryResultsResponse) {}

I know that ModifyItem is a bidirectional stream method, and supports bulk operations. But this method also does other methods' job, which means I can do any operations with ModifyItem method that Update, Delete methods do. Is there any particular reason to use Update, Delete methods over ModifyItem method, maybe performance reasons or something else?

graveart commented 2 years ago

Hi, @oruchreis!

Those methods are pretty similar, but a bit different. ModifyItem requires 1 or more documents, which will be handled sequentially one by one. It's useful, when you are inserting documents or want to update few specific documents. Update and Delete methods, on the other hand, accept query in JSON DSL format: https://github.com/Restream/reindexer/blob/1cbb63ce2ba80af1512deb41458f04b77d406bb9/cpp_src/server/contrib/server.yml#L2248 With DSL you are able to construct some equvalents of SQL-sentences (like UPDATE SET field1 = 'value' WHERE id > 100, for example). So it will be useful , when you don't have specific documents, but have some conditions to find them.

Also there is a difference in internal implementation. Update and Delete are atomic (i.e. both documents search and all the modifications will be executed under single mutex), and ModifyItem will take separate mutex lock for each item in bulk

oruchreis commented 2 years ago

Thanks, it is all clear now, especially this quote:

Update and Delete are atomic (i.e. both documents search and all the modifications will be executed under single mutex), and ModifyItem will take separate mutex lock for each item in bulk