QUERY PLAN
Limit (cost=678.79..678.84 rows=1 width=119)
-> Unique (cost=678.79..678.84 rows=1 width=119)
-> Sort (cost=678.79..678.79 rows=1 width=119)
Sort Key: (CASE WHEN ((rvr.status = 0) AND (r.next_verify_user = 1000)) THEN 1 ELSE 0 END) DESC, r.created_at DESC, r.id, r.status, r.amount, r.occurrence_at, r.settle_accounts_at, r.settle_accounts_by, r.description, r.updated_at, r.refuse_description, r.client_id, r.project_id, r.next_verify_user, r.is_resubmited, r.work_log_id, r.pre_sales_id, r.implement_record_id
-> Group (cost=678.76..678.78 rows=1 width=119)
Group Key: r.id, (CASE WHEN ((rvr.status = 0) AND (r.next_verify_user = 1000)) THEN 1 ELSE 0 END)
-> Sort (cost=678.76..678.77 rows=1 width=119)
Sort Key: r.id, (CASE WHEN ((rvr.status = 0) AND (r.next_verify_user = 1000)) THEN 1 ELSE 0 END) DESC
-> Nested Loop Left Join (cost=520.83..678.75 rows=1 width=119)
-> Nested Loop (cost=520.54..670.42 rows=1 width=119)
-> Nested Loop (cost=520.25..662.37 rows=1 width=123)
-> Hash Right Join (cost=520.25..654.27 rows=1 width=123)
Hash Cond: (rsr.reimbursement_id = r.id)
-> Seq Scan on tbl_reimbursement_settle_rels rsr (cost=0.00..107.83 rows=6983 width=4)
-> Hash (cost=520.23..520.23 rows=1 width=123)
-> Nested Loop (cost=0.28..520.23 rows=1 width=123)
-> Seq Scan on tbl_reimbursement_verify_rels rvr (cost=0.00..330.45 rows=30 width=8)
Filter: (user_id = 1000)
-> Index Scan using tbl_reimbursements_pkey on tbl_reimbursements r (cost=0.28..6.30 rows=1 width=115)
Index Cond: (id = rvr.reimbursement_id)
Filter: ((status <> 0) AND (created_by = 1000))
-> Seq Scan on tbl_users u (cost=0.00..8.09 rows=1 width=4)
Filter: ((id = 1000) AND (department_id = 10))
-> Index Scan using tbl_term_taxonomy_relationships_object_id_term_id_idx on tbl_term_taxonomy_relationships dt1 (cost=0.29..8.05 rows=1 width=4)
Index Cond: ((object_id = rvr.reimbursement_id) AND (term_id = 15))
Filter: (taxonomy_id = 185)
-> Index Scan using tbl_term_taxonomy_relationships_object_id_term_id_idx on tbl_term_taxonomy_relationships dt2 (cost=0.29..8.31 rows=1 width=4)
Index Cond: ((object_id = r.id) AND (term_id = 18))
Filter: (object_type = 7)