I have table which has a few billion rows. There are two columns in the table:
match_id uuid,
group_id integer
And there are indexes created on both of the above columns:
create index if not exists my_tbl_match_id_idx on my_tbl (match_id);
create index if not exists my_tbl_group_id_idx on my_tbl (group_id);
When I perform following query, both indexes are scanned in parallel.
match_id index look up is much faster and returns result back in 13 milliseconds while group_id index look up is slower and takes 1.3 seconds. Because both indexes are looked up in parallel, overall query time = 1.3 seconds i.e. look up time of group_id index.
Is there any way Postgres can just use group_id index after the match_id result set is computed?
SELECT *
FROM my_table
WHERE match_id = 'e089e0af-543b-45d5-abbf-22c6c5ed9a01'
AND (group_id IN (167,1704,1864,2065,2145,3812,3814,3855,7462,11393,11394,11396))
Or do I need to create a composite index for match_id and group_id?
match_idi.e. SELECT * FROM my_table WHERE match_id = 'e089e0af-543b-45d5-abbf-22c6c5ed9a01' hopefully composite index won't affect adversely on this query pattern