Hacker News new | ask | show | jobs
by kebsup 51 days ago
I was using postgres for embarrassingly long time before I've learned the difference between "index scans" and "index only scans".

Including relevant columns in the index can massively improve the performance, because postgres does not need to read the randomly sorted tuple in the original table.

2 comments

Just be wary that if your app is a high-write-throughput or high-update-frequency system, this is not a free lunch!

The indices will bloat in size (postgres does not vacuum them in the way a table is vacuumed), and begin to bottleneck primary writer latency.

You should repack the indices every once in a while (you can set up monitors on index bloat) with something like pg_repack, and make sure that your indices are minimally-sized (i.e. omit rows that are never scanned, use pg_stat to verify which indices are actually used by the primary or read-replicas).

Yep, this can be huge. I learned this in the MySQL days with "covering indexes."