QUERY PLAN
Aggregate (cost=71.54..71.55 rows=1 width=8)
-> Sort (cost=71.52..71.53 rows=1 width=398)
Sort Key: (CASE WHEN (r.status = 1) THEN 0 WHEN (r.status = 5) THEN 1 ELSE 2 END), r.created_at DESC
-> Group (cost=71.50..71.51 rows=1 width=398)
Group Key: r.id
-> Sort (cost=71.50..71.51 rows=1 width=14)
Sort Key: r.id
-> Hash Right Join (cost=48.14..71.49 rows=1 width=14)
Hash Cond: (rvr.erp_payment_ticket_id = r.id)
-> Seq Scan on tbl_erp_payment_ticket_verify_rels rvr (cost=0.00..19.70 rows=970 width=4)
-> Hash (cost=48.13..48.13 rows=1 width=14)
-> Nested Loop (cost=0.28..48.13 rows=1 width=14)
-> Seq Scan on tbl_erp_payment_ticket_settles eptss (cost=0.00..39.83 rows=1 width=4)
Filter: (purchase_contract_id = 4056)
-> Index Scan using tbl_erp_payment_tickets_pkey on tbl_erp_payment_tickets r (cost=0.28..8.30 rows=1 width=14)
Index Cond: (id = eptss.erp_payment_ticket_id)