-> Index Scan Backward using btdt_responses_n5 on btdt_responses (cost=0.57..6425932.41 rows=2214 width=8) (actual time=86910.723..86910.723 rows=1 loops=1)
Index Cond: (last_update_date IS NOT NULL)
Filter: ((response <> 4) AND (registration_id = 8718704208::bigint))
Rows Removed by Filter: 52145434
Total runtime: 86910.766 ms
The issue here is the "Row Removed by Filter", you are filtering out more than 52M rows, so the index is not being much effective.
What you want for this query is a composite index on (registration_id, last_update_date). And if the filter always include `response <> 4`, then you can also create a partial index with that (unless it is not very selective, then it might not be worthy it).
Regards,
--
Matheus de Oliveira Analista de Banco de Dados Dextra Sistemas - MPS.Br nível F! www.dextra.com.br/postgres