“Add an index” is not bad advice. It is incomplete advice.
The real question is: what kind of lookup are you optimizing?
PostgreSQL supports multiple index types because not all query shapes look alike. A good index choice follows the access pattern rather than defaulting blindly to whatever is easiest to generate from the GUI.
Start With the Query
Ask what the query is actually doing:
- equality lookup
- range scan
- full-text search
- geometric proximity
- document membership
That question should come before the index type.
B-Tree Is the Default, Not the Universal Answer
B-tree is versatile and usually right for:
That is why it is the default.
But other cases call for other tools. For example, GiST becomes relevant for geometric and nearest-neighbor style searches, while GIN often fits document and full-text patterns much better.
That difference becomes concrete very quickly:
CREATE INDEX articles_search_idx
ON articles
USING GIN (to_tsvector('english', title || ' ' || body));
That is solving a different problem than a simple B-tree on created_at.
The Engineering Habit That Scales
Do not memorize exotic index types first. Memorize the workflow:
- inspect the query pattern
- inspect the execution plan
- choose the index type that matches the actual work
That keeps indexing attached to evidence instead of folklore.
Further Reading