B-Trees Vs Btrees
B-Trees Vs Btrees
husseinnasser.com
Internal tuple
id/page#/rowid Node
TID ID , Name
701 1 , John
702 2 , Ali
703 3 , Rick
704 4 , Sara
705 5 , Edmond
800 6 , Ion
801 7 , Edmond
802 8 , Pete
803 9 , Oliver
804 10 , Yong
805 11 , Xui
https://www.cs.usfca.edu/~galles/visualization/BTree.html
TID ID , Name
ROOT node 701 1 , John
702 2 , Ali
703 3 , Rick
4:704 8:802 704 4 , Sara
Internal 705 5 , Edmond
node 800 6 , Ion
801 7 , Edmond
802 8 , Pete
2:702 10:804 803 9 , Oliver
6:800
804 10 , Yong
805 11 , Xui
Leaf node
Limitation B-Tree
● Elements in all nodes store both the key and the
value
● Internal nodes take more space thus require more
IO and can slow down traversal
● Range queries are slow because of random
access (give me all values 1-5)
● B+Tree solves both these problems
● Hard to fit internal nodes in memory
Find rows (ID between (4 and 9) in this b-Tree TID ID , Name
701 1 , John
702 2 , Ali
703 3 , Rick
4:704 8:802 704 4 , Sara
705 5 , Edmond
800 6 , Ion
801 7 , Edmond
802 8 , Pete
2:702 10:804 803 9 , Oliver
6:800
804 10 , Yong
805 11 , Xui
3
7 9
2 4 6 8 10
1:701 2:702 3:703 4:704 5:705 6:800 7:801 8:802 9:803 10:804 11:805
Find rows (ID between (4 and 9)
3
7 9
2 4 6 8 10
1:701 2:702 3:703 4:704 5:705 6:800 7:801 8:802 9:803 10:804 11:805
B+Tree & DBMS Considerations
● Cost of leaf pointer (cheap)
● 1 Node fits a DBMS page (most DBMS)
● Can fit internal nodes easily in memory for fast
traversal
● Leaf nodes can live in data files in the heap
● Most DBMS systems use B+Tree
B+Tree Storage cost
5
“Should” fit in memory
3
7 9
2 4 6 8 10
1:701 2:702 3:703 4:704 5:705 6:800 7:801 8:802 9:803 10:804 11:805