Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to decide order of a B-tree

B trees are said to be particularly useful in case of huge amount of data that cannot fit in main memory.

My question is then how do we decide order of B tree or how many keys to store in a node ? Or how many children a node should have ?

I came across that everywhere people are using 4/5 keys per node. How does it solve the huge data and disk read problem ?

like image 889
Andy897 Avatar asked Feb 23 '15 15:02

Andy897


People also ask

What does order of B-tree mean?

Definition. The order of the tree represents the maximum number of children a tree's node could have. So when we say we have a B-Tree of order , It means every node of that B-Tree can have a maximum of. children.

What is the order p of a B-tree?

Describe the structure of B-tree nodes. Refer to page 170 in the text. A search tree of order p is a tree such that each node contains at most p – 1 search values and p pointers inthe order <P1, K1, P2, K2, … Pq-1, Pq> where q <= p; each Pi valueAll search values are assumed unique.

What is the order of B+ tree in DBMS?

B+ Tree Structure The B+ Tree has an order of n, with n being the same for all B plus trees. It has a leaf node and an internal node.


1 Answers

Typically, you'd choose the order so that the resulting node is as large as possible while still fitting into the block device page size. If you're trying to build a B-tree for an on-disk database, you'd probably pick the order such that each node fits into a single disk page, thereby minimizing the number of disk reads and writes necessary to perform each operation. If you wanted to build an in-memory B-tree, you'd likely pick either the L2 or L3 cache line sizes as your target and try to fit as many keys as possible into a node without exceeding that size. In either case, you'd have to look up the specs to determine what size to use.

Of course, you could always just experiment and try to determine this empirically as well. :-)

Hope this helps!

like image 120
templatetypedef Avatar answered Oct 01 '22 14:10

templatetypedef