QUERY PLAN
Aggregate (cost=22.47..22.48 rows=1 width=8)
-> Sort (cost=22.46..22.46 rows=1 width=611)
Sort Key: d.updated_at DESC
-> Group (cost=22.44..22.45 rows=1 width=611)
Group Key: d.id
-> Sort (cost=22.44..22.44 rows=1 width=12)
Sort Key: d.id
-> 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=16)
Filter: ((document_type_id IS NULL) AND (created_by = 1000) 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)