QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sort (cost=8621.73..8628.51 rows=2711 width=40) (actual time=1919.952..1922.192 rows=7540 loops=1) Sort Key: sum(((o3.opinion)::numeric * o12.correlation)) -> HashAggregate (cost=8446.81..8467.14 rows=2711 width=40) (actual time=1795.636..1817.034 rows=7540 loops=1) -> Hash Left Join (cost=3330.84..8129.69 rows=63425 width=40) (actual time=530.277..1419.850 rows=48789 loops=1) Hash Cond: ("outer".prodid = "inner".prodid) Filter: ("inner".num_my_comments IS NULL) -> Merge Join (cost=3008.88..7489.95 rows=63425 width=40) (actual time=527.703..1230.049 rows=58792 loops=1) Merge Cond: ("outer".uid = "inner".uid) -> Index Scan using uid_index on opinions o3 (cost=0.00..3371.13 rows=63425 width=12) (actual time=0.023..361.852 rows=63416 loops=1) Filter: (opinion <> 0) -> Sort (cost=3008.88..3011.04 rows=864 width=36) (actual time=527.653..549.180 rows=58788 loops=1) Sort Key: o12.uid -> Subquery Scan o12 (cost=2921.38..2966.74 rows=864 width=36) (actual time=428.641..522.524 rows=1186 loops=1) -> HashAggregate (cost=2921.38..2958.10 rows=864 width=12) (actual time=428.633..519.345 rows=1186 loops=1) Filter: (((sum((opinion * opinion)))::numeric / sqrt(((count(*))::numeric + 0.0))) <> 0::numeric) -> Merge Right Join (cost=324.44..2886.89 rows=2759 width=12) (actual time=1.518..386.898 rows=13126 loops=1) Merge Cond: ("outer".prodid = "inner".prodid) -> Index Scan using prodid_index on opinions o2 (cost=0.00..2290.37 rows=92276 width=12) (actual time=0.012..223.663 rows=92183 loops=1) -> Sort (cost=324.44..324.67 rows=92 width=8) (actual time=1.486..6.016 rows=13105 loops=1) Sort Key: o1.prodid -> Index Scan using uid_index on opinions o1 (cost=0.00..321.44 rows=92 width=8) (actual time=0.017..0.984 rows=216 loops=1) Index Cond: (uid = 1355) -> Hash (cost=321.95..321.95 rows=4 width=12) (actual time=2.333..2.333 rows=0 loops=1) -> Subquery Scan nmc (cost=321.90..321.95 rows=4 width=12) (actual time=1.346..2.093 rows=216 loops=1) -> HashAggregate (cost=321.90..321.91 rows=4 width=4) (actual time=1.341..1.733 rows=216 loops=1) -> Index Scan using uid_index on opinions o4 (cost=0.00..321.44 rows=92 width=4) (actual time=0.044..0.812 rows=216 loops=1) Index Cond: (uid = 1355) Total runtime: 1927.140 ms (28 rows)