Hassan Syed
Hassan Syed

Reputation: 20485

mongodb index data structures

Does mongodb discriminate between indices constructed of small, statically sized elements (lets say numeric types) and those with large variant types (such as strings) ?

From the BSON spec I can see that BSON does show the capacity of special treatment of integral types. I would expect the indexing code to create more performant indices if the index contains only int64's.

Perhaps it has some form of discriminated union ?

Upvotes: 3

Views: 4357

Answers (1)

Gates VP
Gates VP

Reputation: 45287

The B-Tree contents are basically just the BSON serialized representation of the indexed fields and a pointer to the disk location of that object.

Here is a link to the code where it mentions this. In fact, here is the woCompare function they use while looping through the index.

Looks to me like a simple binary comparison, so smaller data will compare faster than larger data.

Upvotes: 4

Related Questions