QUERY PLAN
GroupAggregate (cost=14.83..114.65 rows=1 width=158)
Group Key: dd.id
-> Nested Loop (cost=14.83..114.63 rows=1 width=158)
-> Merge Join (cost=14.54..14.76 rows=12 width=162)
Merge Cond: (d.department_id = dd.id)
-> Sort (cost=13.30..13.33 rows=12 width=20)
Sort Key: d.department_id
-> Seq Scan on tbl_documents d (cost=0.00..13.09 rows=12 width=20)
Filter: (created_by = 1000)
-> Sort (cost=1.23..1.26 rows=9 width=150)
Sort Key: dd.id
-> Seq Scan on tbl_departments dd (cost=0.00..1.09 rows=9 width=150)
Filter: (id IS NOT NULL)
-> Index Scan using tbl_term_taxonomy_relationships_object_id_term_id_idx on tbl_term_taxonomy_relationships dt (cost=0.29..8.31 rows=1 width=4)
Index Cond: ((object_id = d.id) AND (term_id = 7))
Filter: (taxonomy_id = 116)