QUERY PLAN
Sort (cost=1620.90..1621.15 rows=98 width=424)
Sort Key: sub2.score DESC
-> Subquery Scan on sub2 (cost=1612.52..1617.66 rows=98 width=424)
-> GroupAggregate (cost=1612.52..1616.68 rows=98 width=428)
Group Key: sub2_1.rating_id, sub2_1.voted_for, u.name, u.sex, u.department_id, d.name, um.meta_value, u.department_position_id, dp.name
-> Sort (cost=1612.52..1612.76 rows=98 width=424)
Sort Key: sub2_1.rating_id, sub2_1.voted_for, u.name, u.sex, u.department_id, d.name, um.meta_value, u.department_position_id, dp.name
-> Hash Left Join (cost=1604.33..1609.28 rows=98 width=424)
Hash Cond: (u.department_position_id = dp.id)
-> Hash Left Join (cost=1602.88..1607.56 rows=98 width=278)
Hash Cond: (u.department_id = d.id)
-> GroupAggregate (cost=1601.68..1605.11 rows=98 width=161)
Group Key: sub2_1.rating_id, sub2_1.voted_for, u.name, u.sex, u.department_id, u.department_position_id, um.meta_value
-> Sort (cost=1601.68..1601.92 rows=98 width=132)
Sort Key: sub2_1.voted_for, u.name, u.sex, u.department_id, u.department_position_id, um.meta_value
-> Hash Left Join (cost=1596.67..1598.43 rows=98 width=132)
Hash Cond: (u.id = um.user_id)
-> Hash Left Join (cost=1592.17..1593.67 rows=98 width=65)
Hash Cond: (sub2_1.voted_for = u.id)
-> Sort (cost=1583.00..1583.25 rows=98 width=192)
Sort Key: sub2_1.voted_for, sub2_1."order"
-> Subquery Scan on sub2_1 (cost=1575.59..1579.76 rows=98 width=192)
-> GroupAggregate (cost=1575.59..1578.78 rows=98 width=66)
Group Key: rv.rating_id, rv.voted_for, rv.dimension_id, rd.dimension, rd."order"
-> Sort (cost=1575.59..1575.84 rows=98 width=39)
Sort Key: rv.voted_for, rv.dimension_id, rd.dimension, rd."order"
-> Hash Left Join (cost=74.54..1572.35 rows=98 width=39)
Hash Cond: (rv.dimension_id = rd.id)
-> Hash Join (cost=72.33..1569.86 rows=98 width=17)
Hash Cond: (rv.voter = tbl_rating_voters.user_id)
-> Seq Scan on tbl_rating_votes rv (cost=0.00..1496.00 rows=168 width=21)
Filter: (rating_id = 343)
-> Hash (cost=72.18..72.18 rows=12 width=4)
-> HashAggregate (cost=72.06..72.18 rows=12 width=4)
Group Key: tbl_rating_voters.user_id
-> Seq Scan on tbl_rating_voters (cost=0.00..72.03 rows=13 width=4)
Filter: (completed AND (rating_id = 343))
-> Hash (cost=1.54..1.54 rows=54 width=26)
-> Seq Scan on tbl_rating_dimensions rd (cost=0.00..1.54 rows=54 width=26)
-> Hash (cost=7.41..7.41 rows=141 width=25)
-> Seq Scan on tbl_users u (cost=0.00..7.41 rows=141 width=25)
-> Hash (cost=3.25..3.25 rows=100 width=75)
-> Seq Scan on tbl_user_meta um (cost=0.00..3.25 rows=100 width=75)
Filter: ((meta_key)::text = 'avatar'::text)
-> Hash (cost=1.09..1.09 rows=9 width=150)
-> Seq Scan on tbl_departments d (cost=0.00..1.09 rows=9 width=150)
-> Hash (cost=1.20..1.20 rows=20 width=150)
-> Seq Scan on tbl_department_positions dp (cost=0.00..1.20 rows=20 width=150)