Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

database design - 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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...