QUERY PLAN
Limit (cost=131.25..131.30 rows=20 width=132)
-> Sort (cost=131.25..131.75 rows=203 width=132)
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=132)
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=9)
Filter: (user_id = 1011)
-> Hash (cost=46.25..46.25 rows=203 width=130)
-> Hash Right Join (cost=9.46..46.25 rows=203 width=130)
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=126)
-> Seq Scan on tbl_ratings r (cost=0.00..6.93 rows=203 width=126)
Filter: (rating_type = '1'::smallint)