Compound Index Size shrinks when adding more fields

Hi,

I have a question regarding two indices which were created for one of our collection on MongoDB Atlas.
Both are regular compound indices which are structured as follows:

(1) structureNode_date_1
(2) kind_1_structureNode_1_posGroup_1_source_1_date_1

Type of fields is as follows:

  • structureNode: ObjectID
  • date: ISODate
  • kind: string
  • posGroup: string
  • source: string

What confuses me is the following observation:
The size of index (1) is greater than the size of index (2). (see screenshot attached)
Both indices are fully built and (2) contains all fields that are available in (1).
Thus, I expect index (2) to be at least the size of index (1).

Q: Why is it that index (1) is larger than index (2)?

Is this some kind of compression issue?
Has the unique flag on index (2) any influence on index size?

Best,
Martin

1 Like

@Sinan_Birbalta and I discovered today that there is indeed a different index format version (8 vs. 12) [1] in use when comparing both of our indices. I think the different format might explain our observation, but anyway… maybe someone here in the community forums knows better?!

[1] https://github.com/mongodb/mongo/blob/5bbadc66ed462aed3cc4f5635c5003da6171c25d/src/mongo/db/storage/wiredtiger/wiredtiger_index.cpp#L99