What if your database could find anything instantly, no matter how big it grows?
Why Index creation in Ruby on Rails? - Purpose & Use Cases
Imagine you have a huge phone book with thousands of names and numbers. If you want to find one person's number, you have to flip through every page until you find it.
Searching manually through all entries takes a lot of time and effort. It's easy to lose your place or make mistakes, especially as the list grows bigger.
Creating an index is like adding an organized list at the front of the phone book. It lets you jump straight to the right page quickly without flipping through everything.
SELECT * FROM users WHERE email = 'example@example.com'; -- scans whole tableCREATE INDEX index_users_on_email ON users(email); SELECT * FROM users WHERE email = 'example@example.com'; -- uses index for fast search
Indexes let databases find data lightning fast, even in huge tables, making apps feel quick and smooth.
When you log into a website, the system quickly finds your user info by using an index on your email, so you don't have to wait.
Manual searching is slow and error-prone.
Indexes organize data for quick access.
They make large databases fast and efficient.