QUERY PLAN
Aggregate (cost=136.67..136.68 rows=1 width=8)
-> Sort (cost=133.63..134.13 rows=203 width=362)
Sort Key: (CASE WHEN ((r.open_from <= now()) AND (r.close_at >= now())) THEN 1 WHEN (r.open_from > now()) THEN 2 ELSE 3 END), r.created_at DESC
-> Hash Right Join (cost=48.79..125.85 rows=203 width=362)
Hash Cond: (rvr.rating_id = r.id)
Filter: ((rvr.id IS NOT NULL) OR (rc.id IS NOT NULL))
-> Seq Scan on tbl_rating_voters rvr (cost=0.00..72.03 rows=160 width=8)
Filter: (user_id = 1011)
-> Hash (cost=46.25..46.25 rows=203 width=32)
-> Hash Right Join (cost=9.46..46.25 rows=203 width=32)
Hash Cond: (rc.rating_id = r.id)
-> Seq Scan on tbl_rating_candidates rc (cost=0.00..36.56 rows=85 width=8)
Filter: (user_id = 1011)
-> Hash (cost=6.93..6.93 rows=203 width=28)
-> Seq Scan on tbl_ratings r (cost=0.00..6.93 rows=203 width=28)
Filter: (rating_type = '1'::smallint)