sde

Joined December 2019
B-Trees are one of the most important data structures in database internals, yet most of us barely explore them almost every time you create an index in postgres or mysql, there's a good chance a B-Tree or one of its variations is used but why do databases prefer B-Trees over traditional binary search trees, AVL trees, or red black trees? it's how computers store and access data , lets see this from first principles A balanced BST can search among a 1e6 elements in ~20 comparisons which is very efficient, but there's a problem Databases deal with data that often doesn't fit entirely in RAM. They store data on disk in fixed size blocks called pages, and accessing a page from disk is much more expensive than comparing two integers in memory In a traditional BST, each node contains one key and at most two child pointers, traversing the tree may require jumping between multiple memory locations or disk pages what if instead of storing just one key per node, we stored hundreds of sorted keys in a single node? unlike BST, B-Trees are multiway search trees where each node can hold multiple keys and have multiple children. for example, a node might look like, [10 | 20 | 30 | 40] these keys divide the search space into five different ranges, and if each node can branch into 100 children, a tree with only a few levels can organize millions of records. this is possible because B-Trees are designed to fit many keys into a single database page, significantly reducing the number of page accesses needed during traversal. all leaf nodes remain at the same depth, when a node becomes full during insertion, it can split and propagate a separator key upward, deletions may involve redistribution or merging this keeps the tree balanced without rebuilding the entire structure, this is called self balancing some examples of usages of B-Trees in systems - Database indexing - postgres and mysql use B-Tree style indexes to locate records without scanning the entire table Range queries - queries like "WHERE age BETWEEN 20 AND 30" benefit from the sorted arrangement of keys. Sorting - an index can help databases efficiently process ORDER BY queries without requiring a separate sorting operation Storage engines - B-Tree variations help organize large amounts of data while minimizing expensive storage accesses Filesystems - B-Tree based structures are also used to manage file metadata and other on disk structures. there's also an important variation called the B+ Tree, in a B+ Tree, internal nodes primarily guide the search, while actual indexed entries are stored at the leaf level. leaf nodes are typically linked, making sequential and range based traversal efficient. this is especially useful for databases because queries don't always search for a single key. They frequently retrieve an entire range of sorted records. every additional index consumes storage and introduces overhead during inserts, updates, and deletes. page splits and index maintenance can make writes more expensive that's why creating indexes on every column isn't necessarily a good idea. the interesting part is that B-Trees don't fundamentally improve the asymptotic search complexity over balanced binary search trees both provide O(log n) operations.
1
1
34
💀
who wants to be a millionaire? i actually want to know if your account on X is worth $1M go check this out myaccworth.com
2
84
bro is mocking a 28 batch student , he/she still has time to learn and grow but i think you haven't after all this time alas 🥀
Bro did everything to get a 3LPA job at TCS😭
2
10
302
we have no compute
2
103
so it's a proven fact that larping is the way
The Effort Paradox 🤔 (explained)
2
71
recently I was upgrading a legacy java codebase and the amount of slop there was actually insane it's over bros, AI is much better at coding than humans, stop believing anyone who says otherwise, it's 2026
No human will ever write code better than LLMs. Accept this fact, stop pretending, and move on.
1
2
70
bro someone said “congress k time pe ab tak diwali aa jati thi” 😭
1
88
coding is dead.
1
97
morning contest after a decade
1
7
260
me creating multiple accounts with different email to get free trial
1
9
281
why are japanese people getting cooked on tl ? 😭
2
147
not bad for day 1 without any promo btw
stacked with tokens today, if i don't ship something we're all gay
5
219
tibo did reset again today wtf 💀
1
5
262
Replying to @behalnihal
Based on your tweets: leetcode/codeforces grinds, Java overkill memes, shipping pressure with tokens, viral self-aware self-destructive loops, account locks, and scrolling old ex chats… you’re Neo from The Matrix. You see the code in everything, know the patterns are a trap, yet keep plugging back in while still building.
1
5
277
Hey @grok based on my tweets, which movie character am I?
Hey @grok based on my tweets, which movie character am I?
1
1
3
196
the first programming language i ever learned was php in 2017
4
242
bro my account got locked just cuz I posted a game's name 💀
9
217