QUERY PLAN
Limit (cost=161.30..161.30 rows=1 width=402)
-> Sort (cost=161.30..161.30 rows=1 width=402)
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=161.27..161.29 rows=1 width=402)
Group Key: r.id
-> Sort (cost=161.27..161.28 rows=1 width=390)
Sort Key: r.id
-> Nested Loop Left Join (cost=94.67..161.26 rows=1 width=390)
-> Nested Loop (cost=94.38..155.57 rows=1 width=390)
-> Nested Loop (cost=94.38..147.48 rows=1 width=390)
-> Hash Join (cost=94.10..143.34 rows=7 width=8)
Hash Cond: (rvr.approve_id = rccr.approve_id)
-> Seq Scan on tbl_approve_verify_rels rvr (cost=0.00..37.46 rows=1171 width=4)
Filter: (user_id = 1001)
-> Hash (cost=93.96..93.96 rows=11 width=4)
-> Seq Scan on tbl_approve_carbon_copy_rels rccr (cost=0.00..93.96 rows=11 width=4)
Filter: (user_id = 1000)
-> Index Scan using tbl_approves_pkey on tbl_approves r (cost=0.28..0.59 rows=1 width=390)
Index Cond: (id = rvr.approve_id)
Filter: ((status <> 0) AND (created_by = 1011))
-> Seq Scan on tbl_users u (cost=0.00..8.09 rows=1 width=4)
Filter: ((id = 1011) AND (department_id = 3))
-> Index Only Scan using tbl_term_taxonomy_relationships_object_id_term_id_idx on tbl_term_taxonomy_relationships dt1 (cost=0.29..5.68 rows=1 width=4)
Index Cond: ((object_id = r.id) AND (term_id = 17))