QUERY PLAN
Sort (cost=1040.30..1040.48 rows=71 width=84)
Sort Key: (COALESCE(sum(r.amount), '0'::numeric)) DESC
-> GroupAggregate (cost=1036.69..1038.11 rows=71 width=84)
Group Key: tt.id
-> Sort (cost=1036.69..1036.87 rows=71 width=21)
Sort Key: tt.id
-> Nested Loop Left Join (cost=0.44..1034.51 rows=71 width=21)
-> Nested Loop Left Join (cost=0.29..1022.02 rows=71 width=9)
-> Seq Scan on tbl_reimbursements r (cost=0.00..302.26 rows=71 width=9)
Filter: ((occurrence_at >= '2022-06-01 00:00:00+08'::timestamp with time zone) AND (occurrence_at <= '2022-06-30 23:59:59+08'::timestamp with time zone) AND (status = ANY ('{1,2,3}'::integer[])))
-> Index Scan using tbl_term_taxonomy_relationships_object_id_term_id_idx on tbl_term_taxonomy_relationships ttr (cost=0.29..10.13 rows=1 width=8)
Index Cond: ((object_id = r.id) AND (term_id = 18))
Filter: (object_type = 7)
-> Index Scan using tbl_term_taxonomies_pkey on tbl_term_taxonomies tt (cost=0.15..0.18 rows=1 width=16)
Index Cond: (id = ttr.taxonomy_id)