[DOCS-8471] Fix explanation of when indexes get updated Created: 01/Aug/16  Updated: 08/Sep/16  Resolved: 08/Sep/16

Status: Closed
Project: Documentation
Component/s: dochub
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Adinoyi Omuya Assignee: Steve Renaker (Inactive)
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
Participants:
Days since reply: 7 years, 22 weeks, 6 days ago
Story Points: 1

 Description   

The first paragraph at https://docs.mongodb.com/manual/core/write-performance/#indexes read:

After every insert, update, or delete operation, MongoDB must update every index associated with the collection in addition to the data itself.

Assuming the document doesn't move, only the indexes associated with fields that change (as part of the operation) get updated. Perhaps we can phrase it more along the lines of:

After every insert, update, or delete operation, MongoDB must update every index associated with the fields changed in addition to the data itself (for insert and remove operations, sparse and partial indexes may not be updated if the document does not have an index entry).

On MMAPv1, if the document moves, every index containing the document must be updated.



 Comments   
Comment by Githook User [ 08/Sep/16 ]

Author:

{u'username': u'steveren', u'name': u'Steve Renaker', u'email': u'steve.renaker@mongodb.com'}

Message: DOCS-8471: impact of indexes on write performance

Signed-off-by: kay <kay.kim@10gen.com>
Branch: master
https://github.com/mongodb/docs/commit/b525dc40d3ba637b134b61111dbc52d9ed51d598

Comment by Githook User [ 08/Sep/16 ]

Author:

{u'username': u'steveren', u'name': u'Steve Renaker', u'email': u'steve.renaker@mongodb.com'}

Message: DOCS-8471: impact of indexes on write performance

Signed-off-by: kay <kay.kim@10gen.com>
Branch: master
https://github.com/mongodb/docs/commit/6f6419adfdd54df2174dc26000f6297669facfda

Comment by David Storch [ 19/Aug/16 ]

steve.renaker, I don't think that is strictly correct. Setting aside sparse and partial indices, it is the case that any insert or delete of a document will have to either insert the corresponding key into every index or remove the corresponding key from any index. An update operation on any storage engine, however, may result in index keys being removed/added from some subset of the indices on the collection. Imagine that you have a collection with indices {a: 1} and {b: 1}. If you $inc field a, then we have to update the corresponding key in index {a: 1}, but there is no need to modify {b: 1}. This is true on both MMAPv1 and on WiredTiger.

MMAPv1 also has a special concept of a "document move". This typically happens when an update grows a document beyond its allotted space in its data file; the MMAP storage engine deals with this by moving the document to another mmap'ed disk location (sometimes abbreviated diskloc). On MMAP, the storage engine-assigned id is the diskloc. Since every index key pointing to the document contains the record id, all index keys pointing to the document have to be updated to contain the new id. Finally, note that an MMAP document move is an expensive but usually rare operation; the storage engine leaves padding so that documents have room to grow without being moved.

Hopefully this helps to clear things up!

Comment by Steve Renaker (Inactive) [ 18/Aug/16 ]

adinoyi.omuya david.storch So is it correct to say (setting aside sparse/partial indexes for the moment) that on both WT and MMAPv1, insert and delete operations will require indexes to rebuild, whereas update operations will require a rebuild only on MMAPv1? Thanks!

Comment by David Storch [ 08/Aug/16 ]

Assuming the document doesn't move, only the indexes associated with fields that change (as part of the operation) get updated.

The term "move" here is specific to MMAPv1. It would be more correct to say something like this: "If the document's storage engine-assigned id changes, then all indexes on the collection must be updated accordingly. Most storage engine implementations, including WiredTiger, will not change a document's id when it is updated. An MMAPv1 document move, however, results in the id being changed."

Comment by Charlie Swanson [ 01/Aug/16 ]

I think it might also be worth mentioning partial and sparse indexes, since those would potentially be unchanged during an insert or remove, or if a document is updated such that it still does not have an entry in the index.

Generated at Thu Feb 08 07:56:22 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.