QUERY PLAN
GroupAggregate (cost=50.19..50.35 rows=9 width=158)
Group Key: dd.id
-> Sort (cost=50.19..50.21 rows=9 width=158)
Sort Key: dd.id
-> Nested Loop (cost=33.38..50.05 rows=9 width=158)
-> Hash Join (cost=33.24..44.94 rows=9 width=12)
Hash Cond: (d.id = vd.document_id)
-> Seq Scan on tbl_documents d (cost=0.00..11.20 rows=120 width=20)
-> Hash (cost=33.12..33.12 rows=9 width=4)
-> Seq Scan on tbl_visible_documents vd (cost=0.00..33.12 rows=9 width=4)
Filter: (accessible_user = 5495)
-> Index Scan using tbl_departments_pkey on tbl_departments dd (cost=0.15..0.57 rows=1 width=150)
Index Cond: ((id = d.department_id) AND (id IS NOT NULL))