I have multiple indexes on a postgres table -
- On primary id (notification_permission_on_user_id)
- On three different columns (notification_channel_route_type)
I'm running a query with two joins and the second one caters to my requirement better. But when I analyze the query, it uses primary_id_index automatically, which I assume is decided by postgres itself based on the query.
Index Scan using notification_permission_on_user_id on notification_permission (cost=0.28..0.30 rows=1 width=21) (never executed)
Index Cond: (user_id = u.id)
Filter: ((channel = 1) AND (type = 2))
How do I make sure that my query uses the second index which suits my need and would really speed up the process?
(channel, route, type)is not all that well suited to a query that specifies "type" but not "route".