Loading Depth Study
Preparing your workspace
An index is an additional data structure that helps a database find records more efficiently for supported query patterns.
Without a suitable index, a database may need to inspect many rows to find matching records. An index can make lookups, sorting, and certain joins much faster. However, indexes consume storage and must be maintained when data changes, so adding indexes to every column is not a good strategy. Indexes should be based on actual query patterns and workload.
If users frequently log in by email, indexing the email column can make lookups more efficient.
CREATE INDEX idx_users_email ON users(email); SELECT * FROM users WHERE email = 'aman@example.com';
The index provides a structure that can help the database locate the matching email more efficiently.