Database Indexes need to be optimized to support MVCC


Last Updated on Feb 16, 2021

When databases maintain multiple versions of objects to support database snapshots, their corresponding indexes need to be updated to reflect available versions. When an object version is no longer used by any transaction, the database's garbage collection mechanism should remove the version and clean up the index.

This is automatically done if you are using a relational database, for example. Many database implementations have performance optimizations in place to avoid index updates when possible.

Another approach adopted by databases that use B-Trees is to use an append-only/copy-on-write system that does not overwrite pages of the tree when updated but instead creates a new copy of each modified page. Parent pages, up to the root of the tree, are copied and updated to point to their child pages' latest versions. Pages that are not updated are not copied and remain immutable.

With this append-only approach, there is no need to filter out objects based on transaction IDs because subsequent writes cannot modify the existing B-tree - they can only create new roots. The database will remain performant as long as there is a background process that performs compaction and garbage collection.


© 2022 Ambitious Systems. All Rights Reserved.