DEV Community

Discussion on: Explain indexing in databases Like I'm Five

Collapse
 
wstocker profile image
Wendy Stocker

I’m looking for a number in the phone book where the last name starts with G. Instead of turning every page starting with A to G, I open the phonebook in the middle, then I cut that in half, and half that again till I get to the record I am searching for. That’s essentially what indexes do in a DB.

Collapse
 
poojacsc profile image
Pooja

That is a binary search!

Collapse
 
wstocker profile image
Wendy Stocker

Haha ‘half’ might have been a bad word to use, rather the emphasis should be on removing a subset of the data to eliminate potential possibilities. It’s easier to find a needle in a haystack if you know which section of the hay it isn’t in.