How to create tree B in Mongo DB

I am trying to get an idea of ​​how tree B is created here.

Suppose I use a number as an index variable. How will a tree with depth = 1 be created or would it be like this: http://bit.ly/ygwlEp If yes, then what will be the depth of the tree and what is the maximum number of children. For composite keys (say, 2 index variables) there will be two trees. Or would it be one tree with the first level as the first key and the second level as the second key? Let's say I use a timestamp as an index key. Can I make it like a tree with the first layer as years, the second as a month and the third as a day. Can mongoDB automatically analyze this information?

+4
source share
1 answer

How would a tree with depth = 1 be created or would it be like this: http://bit.ly/ygwlEp

Your picture shows a "binary tree", not a "b-tree", these are different.

The "B-tree" works by creating buckets of a given size (assume that MongoDB uses 4k) and arranges the elements in these buckets.

If so, what will be the depth of the tree and the maximum number of children

Please take a look at the Wikipedia entry on B-trees, it should give you the final answer.

For composite keys (say, 2 index variables) there will be two trees.

Only one tree. However, the key stored in the tree is basically a BSON representation of both elements β€œmerged” together.

Let's say I use timestamp as an index key. Can I make it like a tree with the first layer as years, the second as a month and the third as a day. Can mongoDB automatically analyze this information?

No, you have no control over the indexing structure.

No MongoDB does not support any special parsing by dates in indexes.

If you are performing a comparison operation for timestamps, you need to send another timestamp.

+8
source

Source: https://habr.com/ru/post/1394233/


All Articles