QUERY PLAN
Limit (cost=60.88..60.88 rows=1 width=217)
-> Sort (cost=60.88..60.88 rows=1 width=217)
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=60.83..60.87 rows=1 width=217)
Group Key: r.id
-> Sort (cost=60.83..60.83 rows=1 width=221)
Sort Key: r.id
-> Nested Loop Left Join (cost=53.88..60.82 rows=1 width=221)
Join Filter: (rsvr.erp_payment_ticket_id = r.id)
-> Hash Right Join (cost=53.88..59.62 rows=1 width=217)
Hash Cond: (rvr.erp_payment_ticket_id = r.id)
-> Seq Scan on tbl_erp_payment_ticket_verify_rels rvr (cost=0.00..4.71 rows=271 width=8)
-> Hash (cost=53.87..53.87 rows=1 width=213)
-> Nested Loop (cost=0.28..53.87 rows=1 width=213)
-> Seq Scan on tbl_erp_payment_ticket_settles eptss (cost=0.00..45.56 rows=1 width=4)
Filter: (purchase_contract_id = 4502)
-> Index Scan using tbl_erp_payment_tickets_pkey on tbl_erp_payment_tickets r (cost=0.28..8.30 rows=1 width=213)
Index Cond: (id = eptss.erp_payment_ticket_id)
-> Seq Scan on tbl_erp_payment_ticket_stop_verify_rels rsvr (cost=0.00..1.09 rows=9 width=8)