QUERY PLAN
GroupAggregate (cost=0.29..23.57 rows=1 width=158)
Group Key: dd.id
-> Nested Loop (cost=0.29..23.55 rows=1 width=158)
-> Nested Loop (cost=0.29..22.43 rows=1 width=12)
-> Seq Scan on tbl_documents d (cost=0.00..14.11 rows=1 width=20)
Filter: ((department_id = 1) AND (created_by = 1000))
-> 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)
-> Seq Scan on tbl_departments dd (cost=0.00..1.11 rows=1 width=150)
Filter: ((id IS NOT NULL) AND (id = 1))