QUERY PLAN
Limit (cost=128.69..128.70 rows=1 width=192)
-> Sort (cost=128.69..128.70 rows=1 width=192)
Sort Key: (CASE WHEN (r.status = 1) THEN 0 WHEN (r.status = 5) THEN 1 ELSE 2 END), r.created_at DESC
-> Group (cost=128.67..128.68 rows=1 width=192)
Group Key: r.id
-> Sort (cost=128.67..128.67 rows=1 width=188)
Sort Key: r.id
-> Hash Right Join (cost=105.31..128.66 rows=1 width=188)
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=105.30..105.30 rows=1 width=188)
-> Nested Loop (cost=65.12..105.30 rows=1 width=188)
-> Hash Join (cost=64.84..104.92 rows=1 width=4)
Hash Cond: (eptss.sales_contract_id = s.id)
-> Seq Scan on tbl_erp_payment_ticket_settles eptss (cost=0.00..34.66 rows=2066 width=8)
-> Hash (cost=64.83..64.83 rows=1 width=4)
-> Seq Scan on tbl_sales_contracts s (cost=0.00..64.83 rows=1 width=4)
Filter: (project_id = 3751)
-> Index Scan using tbl_erp_payment_tickets_pkey on tbl_erp_payment_tickets r (cost=0.28..0.38 rows=1 width=188)
Index Cond: (id = eptss.erp_payment_ticket_id)