DEV Community

Discussion on: Explain what is DB indexing like I'm five

Collapse
girish3 profile image
Girish Budhwani • Edited on

Imagine it’s 1930s and you are among the first few to buy a home telephone. Some of your rich friends have it and you keep a book to track their numbers as Telephone directory did not exist. You write the entries in the order they were introduced.

  1. John 7354
  2. Anna 3211
  3. Natalie 2345
  4. Bob 8739
  5. .. ..
  6. .. ..

Yeah I know… numbers were that short! In few years your list has grown to more than 100 and it has become painful to find the number. Then you think of rewriting the entries in alphabetical order.

  1. Anna 3211
  2. Bob 8739
  3. John 7354
  4. Natalie 2345
  5. … ..
  6. … ..

Suddenly, finding a number has become easier. Guess what you did there? You indexed the entries by name!!

Certainly, rewriting is not an efficient way to do indexing in the computer world. But the crux is we do indexing (on a column, in this case “name”) in some form so to make the search faster.