Why databases use ordered indexes but programming uses hash tables (evanjones.ca)
I think it is safe to state that hash tables (e.g. maps in Go, dicts in Python, HashMap in Java, etc.) are far more common than ordered data structures such as trees for in-memory data structures. One data point is that in a talk about C++ hash table optimization at Google (available in Abseil), the speaker noted that 1% of CPU and 4% of RAM globally at Google is used by hash tables. However, in databases, the default is almost always an ordered index, typically a B-Tree. Why is the "default" choice different between programs and databases, when at the end of the day they both do the same thing: accessing data for our code? More than a year ago I asked about this out loud on Twitter, and got many interesting answers. This is my very delayed attempt to distill what I've learned. [Note 2019-12-15: Added a paragraph about locality of reference.] The traditional answer is that hash tables are designed to be efficient when storing data in memory, while B-Trees are designed for slower storag
Why databases use ordered indexes but programming uses hash tables (evanjones.ca) Why databases use ordered indexes but programming uses hash tables about | archive [ 2019-December-08 16:34 ] I think it is safe to state that hash tables (e.g. maps in Go, dicts in Python, HashMap in Java, etc.) are far more common than ordered data structures such as trees for in-memory data structures. One data point is that in a talk about C++ hash table optimization at Google ( available in Abseil ), the speaker noted that 1% of CPU and 4% of RAM globally at Google is used by hash tables. However, in databas
related reading
- Build Your Own Databasenan.fyi
- Static search trees: 40x faster than binary search · CuriousCodingcuriouscoding.nl
- CppCon 2017: Matt Kulukundis “Designing a Fast, Efficient, Cache-friendly Hash Table, Step by Step”youtube.com
- A very concrete explanation of how a cache worksparksb.github.io
- The Beginner's Guide to Databasestechnically.substack.com
- Log Structured Merge Trees | Ben Stopfordbenstopford.com
- B+Trees - Database Systemscs186berkeley.net
- Memory access is O(N^[1/3])vitalik.eth.limo
- Static B-Trees - Algorithmicaen.algorithmica.org
- How Cursor Indexes Codebases Fastread.engineerscodex.com
- Hash Tablesalgs4.cs.princeton.edu
- database - What are the differences between B trees and B+ trees? - Stack Overflowstackoverflow.com