QUERY PLAN
Sort (cost=21.98..21.98 rows=1 width=110)
Sort Key: d.updated_at DESC
-> Group (cost=21.96..21.97 rows=1 width=110)
Group Key: d.id
-> Sort (cost=21.96..21.96 rows=1 width=110)
Sort Key: d.id
-> Nested Loop (cost=0.29..21.95 rows=1 width=110)
-> Seq Scan on tbl_documents d (cost=0.00..13.62 rows=1 width=110)
Filter: ((document_type_id IS NULL) AND (department_id = 1))
-> 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)