QUERY PLAN
Sort (cost=1660.63..1660.88 rows=99 width=155)
Sort Key: sub2.score DESC
-> Subquery Scan on sub2 (cost=1652.15..1657.35 rows=99 width=155)
-> GroupAggregate (cost=1652.15..1656.36 rows=99 width=159)
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=1652.15..1652.40 rows=99 width=155)
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=1643.88..1648.87 rows=99 width=155)
Hash Cond: (u.department_position_id = dp.id)
-> Hash Left Join (cost=1642.40..1647.13 rows=99 width=142)
Hash Cond: (u.department_id = d.id)
-> GroupAggregate (cost=1641.20..1644.67 rows=99 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=1641.20..1641.45 rows=99 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=1636.14..1637.92 rows=99 width=132)
Hash Cond: (u.id = um.user_id)
-> Hash Left Join (cost=1631.62..1633.12 rows=99 width=65)
Hash Cond: (sub2_1.voted_for = u.id)
-> Sort (cost=1622.38..1622.62 rows=99 width=192)
Sort Key: sub2_1.voted_for, sub2_1."order"
-> Subquery Scan on sub2_1 (cost=1614.89..1619.09 rows=99 width=192)
-> GroupAggregate (cost=1614.89..1618.10 rows=99 width=66)
Group Key: rv.rating_id, rv.voted_for, rv.dimension_id, rd.dimension, rd."order"
-> Sort (cost=1614.89..1615.13 rows=99 width=38)
Sort Key: rv.voted_for, rv.dimension_id, rd.dimension, rd."order"
-> Hash Left Join (cost=76.86..1611.60 rows=99 width=38)
Hash Cond: (rv.dimension_id = rd.id)
-> Hash Join (cost=74.64..1609.11 rows=99 width=16)
Hash Cond: (rv.voter = tbl_rating_voters.user_id)
-> Seq Scan on tbl_rating_votes rv (cost=0.00..1532.93 rows=168 width=20)
Filter: (rating_id = 352)
-> Hash (cost=74.49..74.49 rows=12 width=4)
-> HashAggregate (cost=74.37..74.49 rows=12 width=4)
Group Key: tbl_rating_voters.user_id
-> Seq Scan on tbl_rating_voters (cost=0.00..74.34 rows=13 width=4)
Filter: (completed AND (rating_id = 352))
-> 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.44..7.44 rows=144 width=25)
-> Seq Scan on tbl_users u (cost=0.00..7.44 rows=144 width=25)
-> Hash (cost=3.26..3.26 rows=101 width=75)
-> Seq Scan on tbl_user_meta um (cost=0.00..3.26 rows=101 width=75)
Filter: ((meta_key)::text = 'avatar'::text)
-> Hash (cost=1.09..1.09 rows=9 width=14)
-> Seq Scan on tbl_departments d (cost=0.00..1.09 rows=9 width=14)
-> Hash (cost=1.21..1.21 rows=21 width=17)
-> Seq Scan on tbl_department_positions dp (cost=0.00..1.21 rows=21 width=17)