QUERY PLAN
Aggregate (cost=51.91..51.92 rows=1 width=8)
-> Sort (cost=51.89..51.89 rows=1 width=402)
Sort Key: (min(CASE WHEN (1 = r.verify_type) THEN CASE WHEN (rvr.status = 0) THEN 1 WHEN (rsvr.status = 0) THEN 2 ELSE 4 END ELSE CASE WHEN ((rvr.status = 0) AND (r.next_verify_user = 1001)) THEN 1 WHEN ((rsvr.status = 0) AND (r.next_stop_verify_user = 1001)) THEN 2 ELSE 4 END END)), r.created_at DESC
-> GroupAggregate (cost=51.84..51.88 rows=1 width=402)
Group Key: r.id
-> Sort (cost=51.84..51.85 rows=1 width=30)
Sort Key: r.id
-> Nested Loop Left Join (cost=0.28..51.83 rows=1 width=30)
Join Filter: (rvr.erp_payment_ticket_id = r.id)
-> Nested Loop Left Join (cost=0.28..50.76 rows=1 width=30)
Join Filter: (rvr.erp_payment_ticket_id = r.id)
-> Nested Loop (cost=0.28..48.73 rows=1 width=22)
-> Seq Scan on tbl_erp_payment_ticket_settles eptss (cost=0.00..40.42 rows=1 width=4)
Filter: (purchase_contract_id = 4141)
-> Index Scan using tbl_erp_payment_tickets_pkey on tbl_erp_payment_tickets r (cost=0.28..8.30 rows=1 width=22)
Index Cond: (id = eptss.erp_payment_ticket_id)
-> Seq Scan on tbl_erp_payment_ticket_verify_rels rvr (cost=0.00..1.46 rows=46 width=8)
-> Seq Scan on tbl_erp_payment_ticket_stop_verify_rels rsvr (cost=0.00..1.03 rows=3 width=4)