QUERY PLAN
Limit (cost=647.34..647.39 rows=1 width=119)
-> Unique (cost=647.34..647.39 rows=1 width=119)
-> Sort (cost=647.34..647.35 rows=1 width=119)
Sort Key: (CASE WHEN (r.status = 2) THEN 1 ELSE 0 END) DESC, r.created_at DESC, r.id, r.amount, r.occurrence_at, r.settle_accounts_at, r.settle_accounts_by, r.description, r.created_by, r.updated_at, r.refuse_description, r.client_id, r.project_id, r.is_resubmited, r.work_log_id, r.pre_sales_id, r.implement_record_id, r.have_invoice
-> Group (cost=619.71..647.33 rows=1 width=119)
Group Key: r.id
-> Nested Loop Left Join (cost=619.71..647.33 rows=1 width=115)
-> Nested Loop Left Join (cost=619.42..635.75 rows=1 width=115)
-> Nested Loop (cost=619.13..627.43 rows=1 width=115)
Join Filter: (rvr.reimbursement_id = r.id)
-> Merge Join (cost=618.85..619.11 rows=1 width=8)
Merge Cond: (rvr.reimbursement_id = rsr.reimbursement_id)
-> Sort (cost=467.38..467.49 rows=45 width=4)
Sort Key: rvr.reimbursement_id
-> Seq Scan on tbl_reimbursement_verify_rels rvr (cost=0.00..466.14 rows=45 width=4)
Filter: ((user_id = 1001) AND (status = 0))
-> Sort (cost=151.47..151.48 rows=6 width=4)
Sort Key: rsr.reimbursement_id
-> Seq Scan on tbl_reimbursement_settle_rels rsr (cost=0.00..151.39 rows=6 width=4)
Filter: (user_id = 1001)
-> Index Scan using tbl_reimbursements_pkey on tbl_reimbursements r (cost=0.29..8.31 rows=1 width=115)
Index Cond: (id = rsr.reimbursement_id)
Filter: ((status <> 0) AND (next_verify_user = 1001) AND (status = 1))
-> Index Only Scan using tbl_term_taxonomy_relationships_object_id_term_id_idx on tbl_term_taxonomy_relationships dt1 (cost=0.29..8.31 rows=1 width=4)
Index Cond: ((object_id = r.id) AND (term_id = 15))
-> Index Scan using tbl_term_taxonomy_relationships_object_id_term_id_idx on tbl_term_taxonomy_relationships dt2 (cost=0.29..11.56 rows=1 width=4)
Index Cond: ((object_id = r.id) AND (term_id = 18))
Filter: (object_type = 7)