QUERY PLAN
Limit (cost=118.80..118.80 rows=1 width=539)
-> Sort (cost=118.80..118.80 rows=1 width=539)
Sort Key: (CASE WHEN s.is_complete THEN 3 WHEN ((NOT s.is_complete) AND (s.end_at <= now())) THEN 2 ELSE 1 END), (CASE WHEN s.is_complete THEN s.complete_at ELSE NULL::timestamp with time zone END) DESC, (CASE WHEN (NOT s.is_complete) THEN s.end_at ELSE NULL::timestamp with time zone END), s.end_at DESC
-> Group (cost=118.77..118.79 rows=1 width=539)
Group Key: s.id
-> Sort (cost=118.77..118.78 rows=1 width=519)
Sort Key: s.id
-> Hash Right Join (cost=106.04..118.76 rows=1 width=519)
Hash Cond: (ccr.schedule_id = s.id)
-> Seq Scan on tbl_schedule_carbon_copy_rels ccr (cost=0.00..10.91 rows=691 width=4)
-> Hash (cost=106.03..106.03 rows=1 width=519)
-> Bitmap Heap Scan on tbl_schedules s (cost=4.53..106.03 rows=1 width=519)
Recheck Cond: (created_by = 5250)
Filter: (NOT is_complete)
-> Bitmap Index Scan on tbl_schedules_created_by_idx (cost=0.00..4.53 rows=33 width=0)
Index Cond: (created_by = 5250)