Index isn't used when value is a result of a subquery or from a wrapper query
Change the order of the columns in the index to support the B-tree search for the bank_account_id and filtering by type. Once filtered, all records are read ordered by id. By including the created_at column last, you have all the data the query needs in the index and it won't access the table at all.
CREATE INDEX &quot;nc_bank_account_events_bank_account_id&quot;
ON bank_account_events (bank_account_id, type, id, created_at);