Skip to content

DOCS-8471: impact of indexes on write performance #2721

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 23 additions & 9 deletions source/core/write-performance.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,29 @@ Write Operation Performance
Indexes
-------

After every insert, update, or delete operation, MongoDB must update
*every* index associated with the collection in addition to the data
itself. Therefore, every index on a collection adds some amount of
overhead for the performance of write operations. [#exceptions]_
Each index on a collection adds some amount of overhead to the
performance of write operations.

For each :dbcommand:`insert` or :dbcommand:`delete` write operation
on a collection, MongoDB either inserts or removes the corresponding
document keys from each index in the target collection. An
:dbcommand:`update` operation may result in updates to a subset of
indexes on the collection, depending on the keys affected by the update.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the sparse/partial index blurb below need to be moved up here? Because if a collection only has partial index and the document being inserted/removed doesn't hit that index, that wouldn't be affected, yes?


.. note::

MongoDB only updates a :ref:`sparse <index-type-sparse>` or
:ref:`partial <index-type-partial>` index if the documents involved
in a write operation are included in the index.

On :program:`mongod` instances that use the
:ref:`MMAPv1 <storage-mmapv1>` storage engine, update operations may
cause a document to grow beyond its allocated space.
When a document outgrows its allocated space, MMAPv1 moves
the document to a new location on disk, and must
update each index on the collection to point to the new document
location. These move operations can be expensive but occur
infrequently.

In general, the performance gains that indexes provide for *read
operations* are worth the insertion penalty. However, in order to
Expand All @@ -28,11 +47,6 @@ For indexes and queries, see :doc:`/core/query-optimization`. For more
information on indexes, see :doc:`/indexes` and
:doc:`/applications/indexes`.

.. [#exceptions] For inserts and updates to un-indexed fields, the
overhead for :ref:`sparse indexes <index-type-sparse>` is less than
for non-sparse indexes. Also for non-sparse indexes, updates that
do not change the record size have less indexing overhead.

.. _write-performance-and-document-growth:

Document Growth and the MMAPv1 Storage Engine
Expand Down