1 minute read · database
Database performance is the most impactful optimisation you can make.
EXPLAIN ANALYZE
EXPLAIN ANALYZE
SELECT * FROM posts WHERE status='PUBLISHED' ORDER BY created_at DESC LIMIT 10;Partial Index
CREATE INDEX idx_posts_published ON posts(created_at DESC)
WHERE status = 'PUBLISHED';GIN Index for Arrays
CREATE INDEX idx_posts_tags ON posts USING GIN(tags);
SELECT * FROM posts WHERE tags @> ARRAY['web-dev'];Conclusion
Always EXPLAIN before adding an index. Wrong indexes hurt more than they help.