N.Rajal
N.Rajal

Reputation: 175

Use a specific index from a table while running a query with multiple joins

I have multiple indexes on a postgres table -

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?

Upvotes: 0

Views: 72

Answers (1)

Laurenz Albe
Laurenz Albe

Reputation: 247250

Change the condition so that the index cannot be used:

... WHERE/ON notification_permission.user_id + 0 = u.id

Upvotes: 1

Related Questions