QUERY PLAN
Aggregate (cost=383.22..383.23 rows=1 width=8)
-> Sort (cost=383.18..383.18 rows=3 width=391)
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=383.02..383.15 rows=3 width=391)
Group Key: r.id
-> Merge Left Join (cost=383.02..383.06 rows=3 width=30)
Merge Cond: (r.id = rsvr.erp_cash_cost_ticket_id)
-> Sort (cost=381.99..382.00 rows=3 width=26)
Sort Key: r.id
-> Hash Right Join (cost=9.38..381.96 rows=3 width=26)
Hash Cond: (rvr.erp_cash_cost_ticket_id = r.id)
-> Seq Scan on tbl_erp_cash_cost_ticket_verify_rels rvr (cost=0.00..299.86 rows=19386 width=8)
-> Hash (cost=9.36..9.36 rows=1 width=22)
-> Nested Loop (cost=0.28..9.36 rows=1 width=22)
-> Seq Scan on tbl_erp_cash_cost_ticket_purchase_contract_settles eptss (cost=0.00..1.06 rows=1 width=4)
Filter: (purchase_contract_id = 4142)
-> Index Scan using tbl_erp_cash_cost_tickets_pkey on tbl_erp_cash_cost_tickets r (cost=0.28..8.30 rows=1 width=22)
Index Cond: (id = eptss.erp_cash_cost_ticket_id)
-> Sort (cost=1.03..1.04 rows=1 width=8)
Sort Key: rsvr.erp_cash_cost_ticket_id
-> Seq Scan on tbl_erp_cash_cost_ticket_stop_verify_rels rsvr (cost=0.00..1.02 rows=1 width=8)
Filter: (user_id = 1001)