Reputation: 7254
I know how a B-Tree works in-memory, it's easy enough to implement. However, I don't know how to find a data layout that works effectively on disk, such that:
How can I do lay out B-Tree structures on the disk level in a way that matches these criteria? The last bullet point especially gives me a lot of headache. Most database literature I've seen explains only the high-level structure (i.e. "this is how you do it in memory"), but skips the nitty gritty details on the disk layout.
Upvotes: 37
Views: 14094
Reputation: 3608
Notes:
Databases do not directly implement indexes based on B-tree but on a variant called B+ tree. Which according to wikipedia:
A B+ tree can be viewed as a B-tree in which each node contains only keys (not key-value pairs), and to which an additional level is added at the bottom with linked leaves.
Databases work, in general, with block-oriented storage and b+ tree is more suited then a b-tree for this.
The blocks are fixed size and are left with some free space to accommodate future changes in value or key size.
A block can be either a leaf(holds actual data) or branch(holds the pointers to the leaf nodes)
A toy model how writing to disk can be implemented (for a block size 10k for arithmetic simplification):
When the information is read from a big index: can go following:
a really large index can be split on multiple files, then the address of block will be something as (filename_id, address_relative_to_this_file)
Upvotes: 37