QUERY PLAN
Aggregate (cost=2143.07..2143.08 rows=1 width=8)
-> Sort (cost=2111.30..2116.59 rows=2118 width=445)
Sort Key: (CASE WHEN (r.status = 1) THEN 0 ELSE 1 END), (CASE WHEN (r.status = 1) THEN r.created_at ELSE r.verify_at END) DESC, r.created_at DESC
-> HashAggregate (cost=1962.52..1994.29 rows=2118 width=445)
Group Key: r.id
-> Hash Right Join (cost=1780.31..1946.11 rows=6567 width=22)
Hash Cond: (rcvr.approve_id = r.id)
Filter: ((r.created_by = ANY ('{1000,1001,1004,1005,1011,1013,1015,1022,1023,5016,5064,5085,5087,5248,5250,5252,5295,5300,5311,5332,5360,5388,5446,5449}'::integer[])) OR (rccr.user_id = 1001) OR (rvr.user_id = 1001) OR (rcvr.user_id = 1001))
-> Seq Scan on tbl_approve_cancel_verify_rels rcvr (cost=0.00..19.70 rows=970 width=8)
-> Hash (cost=1697.54..1697.54 rows=6622 width=34)
-> Hash Right Join (cost=1508.69..1697.54 rows=6622 width=34)
Hash Cond: (rccr.approve_id = r.id)
-> Seq Scan on tbl_approve_carbon_copy_rels rccr (cost=0.00..98.73 rows=6373 width=8)
-> Hash (cost=1480.39..1480.39 rows=2264 width=30)
-> Hash Right Join (cost=236.87..1480.39 rows=2264 width=30)
Hash Cond: (dt1.object_id = r.id)
-> Seq Scan on tbl_term_taxonomy_relationships dt1 (cost=0.00..1229.41 rows=2118 width=4)
Filter: (term_id = 17)
-> Hash (cost=208.57..208.57 rows=2264 width=30)
-> Hash Right Join (cost=161.16..208.57 rows=2264 width=30)
Hash Cond: (rvr.approve_id = r.id)
-> Seq Scan on tbl_approve_verify_rels rvr (cost=0.00..41.29 rows=2329 width=8)
-> Hash (cost=134.69..134.69 rows=2118 width=30)
-> Seq Scan on tbl_approves r (cost=0.00..134.69 rows=2118 width=30)
Filter: ((status <> 0) AND (status = '2'::smallint))