DEV Community

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

emptyother profile image

Every person in my country is registered in a database. This database is just a long list, sorted by a National ID. It's sequential, and starts with the persons birth date. But the NID isn't something other people usually know, and so everyone who wanted to call someone would need to look trough the entire list to find a phone number.

The "Telephone directory" is an index of all these people, but sorted by surname instead of national ID. Whenever someone gets added to the first list, they also gets added to the phone directory and sorted.

If you want to select a long list of people where their surname starts with "V", you can find them a lot faster by just selecting everything between page "V" and page "W". But if you want to find every person that was born in 2015, you would have to check the first list instead. And if you wanted to create a combined list of people which surname starts with "V" and was born in 2015, you would either have to make a new index or manually search trough the shortest of these two lists.