How do indexes help, and what do they cost?
Understand the concept
An index is an extra data structure that helps the database find matching records without inspecting every document. Reads can become much faster, but inserts, updates and deletes must maintain the relevant indexes. Indexes are most useful when their fields and order match important query patterns.
Important ideas
-
Indexes reduce the documents examined for matching queries.
-
Each index takes storage and adds work to writes.
-
Check real query patterns before adding indexes.
-
Measure keys examined, documents examined and returned documents together; merely seeing an index in a plan does not prove efficiency.
Can you explain it without the notes?
How do indexes help, and what do they cost?
Use your own words. Explain an example and one limitation before checking the explanation.
Check your explanation
An index is an extra data structure that helps the database find matching records without inspecting every document. Reads can become much faster, but inserts, updates and deletes must maintain the relevant indexes. Indexes are most useful when their fields and order match important query patterns.
Turn this concept into a clear answer.
- Include write cost and storage in the trade-off, and show which actual query the index is meant to improve.
Adapted from 04_MONGODB_MONGOOSE.md · “How do indexes help, and what do they cost?”. Examples are study fragments; framework behavior can depend on your version.