QUERY PLAN
Sort (cost=1669.64..1669.89 rows=99 width=424)
Sort Key: sub2.score DESC
-> Subquery Scan on sub2 (cost=1661.16..1666.36 rows=99 width=424)
-> GroupAggregate (cost=1661.16..1665.37 rows=99 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=1661.16..1661.41 rows=99 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=1652.88..1657.88 rows=99 width=424)
Hash Cond: (u.department_position_id = dp.id)
-> Hash Left Join (cost=1651.41..1656.13 rows=99 width=278)
Hash Cond: (u.department_id = d.id)
-> GroupAggregate (cost=1650.21..1653.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=1650.21..1650.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=1645.15..1646.92 rows=99 width=132)
Hash Cond: (u.id = um.user_id)
-> Hash Left Join (cost=1640.62..1642.13 rows=99 width=65)
Hash Cond: (sub2_1.voted_for = u.id)
-> Sort (cost=1622.38..1622.63 rows=99 width=192)
Sort Key: sub2_1.voted_for, sub2_1."order"
-> Subquery Scan on sub2_1 (cost=1614.89..1619.10 rows=99 width=192)
-> GroupAggregate (cost=1614.89..1618.11 rows=99 width=66)
Group Key: rv.rating_id, rv.voted_for, rv.dimension_id, rd.dimension, rd."order"
-> Sort (cost=1614.89..1615.14 rows=99 width=39)
Sort Key: rv.voted_for, rv.dimension_id, rd.dimension, rd."order"
-> Hash Left Join (cost=76.86..1611.61 rows=99 width=39)
Hash Cond: (rv.dimension_id = rd.id)
-> Hash Join (cost=74.64..1609.11 rows=99 width=17)
Hash Cond: (rv.voter = tbl_rating_voters.user_id)
-> Seq Scan on tbl_rating_votes rv (cost=0.00..1532.93 rows=170 width=21)
Filter: (rating_id = 351)
-> 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 = 351))
-> 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=16.44..16.44 rows=144 width=25)
-> Seq Scan on tbl_users u (cost=0.00..16.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=150)
-> Seq Scan on tbl_departments d (cost=0.00..1.09 rows=9 width=150)
-> Hash (cost=1.21..1.21 rows=21 width=150)
-> Seq Scan on tbl_department_positions dp (cost=0.00..1.21 rows=21 width=150)