QUERY PLAN
Limit (cost=71.52..71.57 rows=20 width=441)
-> Sort (cost=71.52..71.91 rows=154 width=441)
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 = 5495)) THEN 1 WHEN ((rsvr.status = 0) AND (r.next_stop_verify_user = 5495)) THEN 2 ELSE 4 END END)), r.created_at DESC
-> HashAggregate (cost=65.88..67.42 rows=154 width=441)
Group Key: r.id
-> Hash Right Join (cost=37.77..62.42 rows=154 width=445)
Hash Cond: (rsvr.erp_purchase_gift_id = r.id)
-> Seq Scan on tbl_erp_purchase_gift_stop_verify_rels rsvr (cost=0.00..19.70 rows=970 width=8)
-> Hash (cost=37.43..37.43 rows=27 width=441)
-> Hash Right Join (cost=15.09..37.43 rows=27 width=441)
Hash Cond: (rvr.erp_purchase_gift_id = r.id)
Filter: ((r.created_by = 5495) OR (rvr.user_id = 5495) OR (r.created_by = ANY ('{5493,5495,5495}'::integer[])))
-> Seq Scan on tbl_erp_purchase_gift_verify_rels rvr (cost=0.00..19.70 rows=970 width=12)
-> Hash (cost=12.97..12.97 rows=169 width=437)
-> Seq Scan on tbl_erp_purchase_gifts r (cost=0.00..12.97 rows=169 width=437)
Filter: ((status <> 0) OR ((status = 0) AND (created_by = 5495)))