I'm using PostgreSQL 14. I'm confused why multi-column index not working for first column.
Here is the output:
# \d+ para_data
...
"para_data_pkey" PRIMARY KEY, btree (id)
"para_data_eq_id_timestamp_high_idx" btree (eq_id, timestamp_high)
You can see when query eq_id and timestamp_high at one time is using index:
# explain analyze verbose SELECT "ch00_status", "ch00_wf_peak_peak" FROM para_data WHERE eq_id = '020090120479F281' and timestamp_high > 1 and timestamp_high < 100;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------
Index Scan using para_data_eq_id_timestamp_high_idx on public.para_data (cost=0.42..8.44 rows=1 width=16) (actual time=0.009..0.009 rows=0 loops=1)
Output: ch00_status, ch00_wf_peak_peak
Index Cond: (((para_data.eq_id)::text = '020090120479F281'::text) AND (para_data.timestamp_high > 1) AND (para_data.timestamp_high < 100))
Planning Time: 0.064 ms
Execution Time: 0.018 ms
But when I just query for eq_id, it's not working:
# explain analyze verbose SELECT "ch00_status", "ch00_wf_peak_peak" FROM para_data WHERE eq_id = '020090120479F281';
QUERY PLAN
-------------------------------------------------------------------------------------------------------------------------
Seq Scan on public.para_data (cost=0.00..24496.89 rows=53693 width=16) (actual time=12.849..47.731 rows=52348 loops=1)
Output: ch00_status, ch00_wf_peak_peak
Filter: ((para_data.eq_id)::text = '020090120479F281'::text)
Rows Removed by Filter: 122283
Planning Time: 0.049 ms
Execution Time: 49.490 ms
Am I misunderstanding the multi-column index ?
eq_idhas so many records and postgresql does not use index. I try to use anothereq_idto query, and multi-column index is working. Thanks.enable_seqscansee the manual