QUERY PLAN
Aggregate (cost=1236.67..1236.68 rows=1 width=8)
-> Sort (cost=1234.15..1234.57 rows=168 width=273)
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
-> Group (cost=1226.26..1227.94 rows=168 width=273)
Group Key: r.id
-> Sort (cost=1226.26..1226.68 rows=168 width=22)
Sort Key: r.id
-> Nested Loop Left Join (cost=148.60..1220.05 rows=168 width=22)
-> Nested Loop (cost=148.31..274.91 rows=168 width=22)
-> Seq Scan on tbl_users u (cost=0.00..8.09 rows=1 width=4)
Filter: ((id = 5300) AND (department_id = 1))
-> Hash Right Join (cost=148.31..265.14 rows=168 width=26)
Hash Cond: (rccr.approve_id = r.id)
Filter: ((r.created_by = ANY ('{5311,5300}'::integer[])) OR (rccr.user_id = 5300) OR (rvr.user_id = 5300))
-> Seq Scan on tbl_approve_carbon_copy_rels rccr (cost=0.00..80.97 rows=5197 width=8)
-> Hash (cost=144.49..144.49 rows=305 width=30)
-> Hash Right Join (cost=108.05..144.49 rows=305 width=30)
Hash Cond: (rvr.approve_id = r.id)
-> Seq Scan on tbl_approve_verify_rels rvr (cost=0.00..31.77 rows=1777 width=8)
-> Hash (cost=104.41..104.41 rows=291 width=30)
-> Seq Scan on tbl_approves r (cost=0.00..104.41 rows=291 width=30)
Filter: ((status <> 0) AND (created_by = 5300))
-> Index Only Scan using tbl_term_taxonomy_relationships_object_id_term_id_idx on tbl_term_taxonomy_relationships dt1 (cost=0.29..5.62 rows=1 width=4)
Index Cond: ((object_id = r.id) AND (term_id = 17))