QUERY PLAN
Aggregate (cost=49.75..49.76 rows=1 width=8)
-> Sort (cost=49.73..49.74 rows=1 width=401)
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=48.45..49.72 rows=1 width=401)
Group Key: r.id
-> Nested Loop Left Join (cost=48.45..49.69 rows=1 width=30)
Join Filter: (rvr.erp_collect_ticket_id = r.id)
-> Merge Left Join (cost=48.45..48.60 rows=1 width=30)
Merge Cond: (r.id = rvr.erp_collect_ticket_id)
-> Sort (cost=46.54..46.54 rows=1 width=22)
Sort Key: r.id
-> Nested Loop (cost=0.28..46.53 rows=1 width=22)
-> Seq Scan on tbl_erp_collect_ticket_settles ectss (cost=0.00..38.23 rows=1 width=4)
Filter: (purchase_contract_id = 2364)
-> Index Scan using tbl_erp_collect_tickets_pkey on tbl_erp_collect_tickets r (cost=0.28..8.29 rows=1 width=22)
Index Cond: (id = ectss.erp_collect_ticket_id)
-> Sort (cost=1.91..1.98 rows=27 width=8)
Sort Key: rvr.erp_collect_ticket_id
-> Seq Scan on tbl_erp_collect_ticket_verify_rels rvr (cost=0.00..1.27 rows=27 width=8)
-> Seq Scan on tbl_erp_collect_ticket_stop_verify_rels rsvr (cost=0.00..1.04 rows=4 width=4)