QUERY PLAN
Sort (cost=1535.27..1535.51 rows=95 width=424)
Sort Key: sub2.score DESC
-> Subquery Scan on sub2 (cost=1527.17..1532.15 rows=95 width=424)
-> GroupAggregate (cost=1527.17..1531.20 rows=95 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=1527.17..1527.40 rows=95 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=1519.25..1524.05 rows=95 width=424)
Hash Cond: (u.department_position_id = dp.id)
-> Hash Left Join (cost=1517.80..1522.33 rows=95 width=278)
Hash Cond: (u.department_id = d.id)
-> GroupAggregate (cost=1516.60..1519.92 rows=95 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=1516.60..1516.83 rows=95 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=1511.77..1513.48 rows=95 width=132)
Hash Cond: (u.id = um.user_id)
-> Hash Left Join (cost=1507.32..1508.77 rows=95 width=65)
Hash Cond: (sub2_1.voted_for = u.id)
-> Sort (cost=1498.19..1498.43 rows=95 width=192)
Sort Key: sub2_1.voted_for, sub2_1."order"
-> Subquery Scan on sub2_1 (cost=1491.03..1495.07 rows=95 width=192)
-> GroupAggregate (cost=1491.03..1494.12 rows=95 width=66)
Group Key: rv.rating_id, rv.voted_for, rv.dimension_id, rd.dimension, rd."order"
-> Sort (cost=1491.03..1491.27 rows=95 width=38)
Sort Key: rv.voted_for, rv.dimension_id, rd.dimension, rd."order"
-> Hash Left Join (cost=69.77..1487.91 rows=95 width=38)
Hash Cond: (rv.dimension_id = rd.id)
-> Hash Join (cost=67.55..1485.42 rows=95 width=16)
Hash Cond: (rv.voter = tbl_rating_voters.user_id)
-> Seq Scan on tbl_rating_votes rv (cost=0.00..1416.39 rows=163 width=20)
Filter: (rating_id = 325)
-> Hash (cost=67.40..67.40 rows=12 width=4)
-> HashAggregate (cost=67.28..67.40 rows=12 width=4)
Group Key: tbl_rating_voters.user_id
-> Seq Scan on tbl_rating_voters (cost=0.00..67.25 rows=13 width=4)
Filter: (completed AND (rating_id = 325))
-> 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.39..7.39 rows=139 width=25)
-> Seq Scan on tbl_users u (cost=0.00..7.39 rows=139 width=25)
-> Hash (cost=3.23..3.23 rows=98 width=75)
-> Seq Scan on tbl_user_meta um (cost=0.00..3.23 rows=98 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)