Larger indexes in MongoDB 5 compared to MongoDB 4

Viewed 35

I noticed that MongoDB database indexes take more space in MongoDB 5 than in MongoDB 4. I verified the phenomenon by testing as follows:

  1. export (mongoexport) sample data of 100.000 documents out of some test environment (documents have MongoDB ObjectIds included)
  2. import (mongoimport) these data to a fresh MongoDB 4.2.22 and a fresh Mongo 5.0.11 database
  3. compare the collection statistics

Test-Result:

  • same avgObjSize of 495 bytes in MongDB 4 and 5
  • different avgIndex Size of _id-Index
    • MongoDB 4 → 10 bytes
    • MongoDB 5 → 19 bytes

Does anyone know what causes this difference?

1 Answers

I believe what you’re seeing was caused by the new-ish (from MongoDB 5.0) WiredTiger feature of Snapshot History Retention. The introduction of this feature changes a lot of WiredTiger internals, and this is one of the side effect of the change.

This issue was known, and was discussed in SERVER-47652, WT-6082, and WT-6251.

Related