QUERY PLAN
Limit (cost=110.81..110.86 rows=20 width=132)
-> Sort (cost=110.81..110.89 rows=31 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 Left Join (cost=41.45..110.04 rows=31 width=132)
Hash Cond: (r.id = rc.rating_id)
-> Hash Right Join (cost=7.09..74.89 rows=31 width=131)
Hash Cond: (rvr.rating_id = r.id)
-> Seq Scan on tbl_rating_voters rvr (cost=0.00..67.25 rows=208 width=9)
Filter: (user_id = 1001)
-> Hash (cost=6.70..6.70 rows=31 width=126)
-> Seq Scan on tbl_ratings r (cost=0.00..6.70 rows=31 width=126)
Filter: (rating_type = '2'::smallint)
-> Hash (cost=34.29..34.29 rows=6 width=4)
-> Seq Scan on tbl_rating_candidates rc (cost=0.00..34.29 rows=6 width=4)
Filter: (user_id = 1001)