If I have read-only tables in Postgres, should I index them heavily?
Even when writes are off the table, heavily indexing read-only Postgres tables only pays off under certain conditions: table size, query complexity, data cardinality and resource constraints. Benchmarks show no gain from an index on a 10k-row table, and a simple low-selectivity equality query on 10M rows was actually slower with an index (0.0078s vs 0.0026s). A multi-condition search with a range filter, ORDER BY and LIMIT dropped from 20.8s to 3.4s with indexing. The recommendation is to index columns used in WHERE, JOIN, ORDER BY and GROUP BY for critical queries, favor high-cardinality orderable types over booleans, and account for the disk, memory and CPU cost of extra indexes.
Related posts
- Choosing the right Postgres indexes
incident.io mediumAdeptPostgres indexes pay off for frequently run queries that discard most rows they read, need results in a specific order, or must enforce uniqueness. In a 500k-row example, adding a B-tree index cuts a lookup from 215ms to 0.05ms. Put the most frequently filtered columns first in composite indexes, prefer reusable indexes over narrowly tailored ones, and use partial indexes (e.g. WHERE archived_at IS NULL) to keep them small. Missing indexes can be spotted with a Grafana panel on pg_stat_user_tables_seq_tup_read and confirmed with EXPLAIN ANALYZE.
- Tips for maximizing your Turso billing allowances
Turso mediumAdeptTurso bills by rows read, rows written and storage, so queries that scan whole tables or compute aggregates can cost far more row reads than the rows they return. Use EXPLAIN QUERY PLAN to spot full table scans ("SCAN" vs "SEARCH ... USING INDEX") and add indexes only on columns you filter or sort by, since indexes add storage and slow inserts and deletes. For count/sum/avg, maintain precomputed aggregate tables, either in client transactions or automatically with SQLite triggers. This trades cheaper reads for extra writes, so it suits read-heavy tables.
- Top 10 best practices tips for ClickHouse
ClickHouse mediumAdept
Ten practices for getting performance and storage efficiency out of ClickHouse, each measured on a 150M-row Amazon reviews dataset. Aligning ORDER BY with query filters (low-cardinality columns first) made one query 3x faster and cut scanned data 347x. Right-sized types, no Nullable and LowCardinality(String) doubled query speed and shrank storage. Partitioning is best avoided except for TTL expiry or FINAL on merge engines; monthly partitions slowed one aggregation 46x. The post also covers lightweight versus heavyweight skipping indexes, JSON type hints (38% less storage, 26% faster), and preferring Parquet/ORC for bulk ingestion.
- The side quest that freed 10% of our database
incident.io mediumAdeptA single lateral-join query answering "who's on call for this rotation layer right now" consumed 34% of incident.io's Postgres replica CPU. It was using a GiST exclusion-constraint index that lacked organisation_id and start_at, so every lookup read a layer's full history. Adding a five-column btree index did nothing on its own, because the planner assumed the four ID columns were independent and kept choosing the GiST index. Rewriting the predicate as a row-value comparison with a matching ORDER BY, which only btree indexes can serve, forced the new index and cut per-call time from 44ms to 0.26ms, buffers by 115x and CPU share to 0.3%.
- 6 tips to optimize storage costs for your Postgres databases
Neon mediumAdept
Six ways to shrink Postgres storage spend: drop unused indexes (found via pg_stat_user_indexes and pg_index), avoid full database copies for dev and staging by using Neon's copy-on-write branching, choose smaller data types like SMALLINT, order columns largest to smallest to cut alignment padding, shorten Neon's history retention window, and tune autovacuum to limit bloat. Shorter retention saves storage but narrows the point-in-time recovery window. For bloat, look in pg_stat_activity for long-running transactions that block autovacuum.