
Why PostgreSQL Ignores Your Index (Sometimes), Entry #2
I Thought My Index Would Fix Everything I added the index. Ran the query. And… nothing changed. Same slow response. Same frustration. That was the moment I realized something uncomfortable: PostgreSQL doesn’t care about your index. It cares about something else entirely. The Question PostgreSQL Is Actually Answering When you run a query, PostgreSQL is not asking: “Do I have an index?” It’s asking: “What is the cheapest way to get this data?” That’s it. Meet EXPLAIN ANALYZE If you’ve ever run: EXPLAIN ANALYZE SELECT * FROM orders WHERE user_id = 42 ; You’ve seen something like: Index Scan using idx_orders_user_id on orders Index Cond: ( user_id = 42 ) Actual Time: 0.03 ms Here’s how to read it: Index Scan using idx_orders_user_id → PostgreSQL used your index Index Cond: (user_id = 42) → Condition applied inside the index Actual Time → What really happened (not theory) But here’s where things get interesting… The Counter-Intuitive Truth Indexes are not always faster. Let that sink in. In
Continue reading on Dev.to
Opens in a new tab



