When a database index is the right tool
standardintermediateA database index is the right tool whenever the question is structured: exact values, ranges, ordering, and combinations of those, over data you also need to write transactionally. "Orders for this customer, placed in the last 30 days, status pending, newest first" is a structured question, and a composite index answers it with a single range scan that stays fast as the table grows. The database is also the only place that can answer such a question in the same transaction as a write, which matters whenever the answer drives a decision that has to be consistent with what is stored — checking remaining stock, computing a balance, validating a constraint. Beyond the ordinary B-tree, most relational databases carry index types that cover more than people expect: an inverted index type for array containment and JSON keys, a trigram index for substring and fuzzy matching, a partial index that indexes only the rows a hot query actually touches, and built-in full-text search with stemming and ranking. That built-in full-text search is the important middle ground — for many products it is genuinely sufficient, and adopting a separate search engine before exhausting it buys an extra system to run, sync, monitor and reindex in exchange for capabilities the database already had. The rule is that structured filtering and transactional reads stay in the database, and the next concept covers what genuinely justifies leaving it.
Think of it as
A well-organised filing cabinet with several kinds of tabs: alphabetical, by date, by status. Any question you can phrase as "find the range between these two tabs" is answered by walking straight to it. Questions of that shape are the overwhelming majority of what an application asks, and they are answered in the same place the records are actually kept — which is what lets you read and write in one consistent operation.
- Exact match — B-tree
- Range and order — B-tree, composite
- Array / JSON containment — inverted index
- Substring, fuzzy — trigram
- Stemmed text with ranking — built-in full-text search
Index types and the question shape each one answers
Remember: A database index is the right tool for structured questions — exact values, ranges, ordering and their combinations — and it is the only tool that can answer inside the same transaction as a write. Composite indexes put equality columns before the range or sort column. Beyond B-trees, inverted, trigram, partial and built-in full-text indexes cover far more than people assume, and exhausting the built-in full-text search first avoids adopting a whole second system for capabilities the database already had.
See also: when a search engine is the right tool · keeping the system of record in the primary store · when database search is insufficient · access patterns first · oltp workload characteristics

