Combining indexes
Though, this doesn't mean the v
index is useless. If you are running something that is selective based on the k
index, the one on v can be combined with that. With the index in place, this earlier example now uses a complicated query plan:
EXPLAIN ANALYZE SELECT count(*) FROM t WHERE k>9000 AND v=5; QUERY PLAN ------------------------- Aggregate (cost=787.97..787.98 rows=1 width=0) (actual time=40.545..40.546 rows=1 loops=1) -> Bitmap Heap Scan on t (cost=170.38..765.03 rows=9176 width=0) (actual time=4.107..24.606 rows=9097 loops=1) Recheck Cond: (v = 5) Filter: (k > 9000) -> Bitmap Index Scan on i (cost=0.00..168.08 rows=10110 width=0) (actual time=3.255..3.255 rows=9993 loops=1) Index Cond: (v = 5) Total runtime: 40.638 ms seq_scan | 0 seq_tup_read | 0 idx_scan | 1 idx_tup_fetch | 9993 heap_blks_read | 0 heap_blks_hit | 443...